从类内部调用属性

net*_*iul 2 vb6

有没有办法在同一个类中调用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
Run Code Online (Sandbox Code Playgroud)

Dea*_*nna 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
Run Code Online (Sandbox Code Playgroud)

或者,更明确地说:

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
Run Code Online (Sandbox Code Playgroud)

请注意,我已经删除了值/参数周围的(),因为它们不应该(通常)存在,并且可能会在以后发现.