有没有办法在同一个类中调用Property Let方法?
喜欢这个函数SetConnectionDetails
。但是这个得到了编译错误:属性的使用无效......
Public Sub SetConnectionDetails(ByVal strServer As String, ByVal strDatabase As String, ByVal strUser As String, ByVal strPassword As String)
Server (strServer)
User (strUser)
Password (strPassword)
Database (strDatabase)
End Sub
Property Let Server(ByVal value As String)
lServer = value
End Property
Property Let User(ByVal value As String)
lUser = value
End Property
Property Let Password(ByVal value As String)
lPassword = value
End Property
Property Let Database(ByVal value As String)
lDatabase = value
End Property
答案 0 :(得分:5)
您将其称为普通属性/变量:
Public Sub SetConnectionDetails(ByVal strServer As String, ByVal strDatabase As String, ByVal strUser As String, ByVal strPassword As String)
Server = strServer
User = strUser
Password = strPassword
Database = strDatabase
End Sub
或者,更明确地说:
Public Sub SetConnectionDetails(ByVal strServer As String, ByVal strDatabase As String, ByVal strUser As String, ByVal strPassword As String)
Me.Server = strServer
Me.User = strUser
Me.Password = strPassword
Me.Database = strDatabase
End Sub
请注意,我已经删除了值/参数周围的(),因为它们不应该(通常)存在,may catch you out later。