2011-10-13 47 views
2

有沒有一種方法從同一個類內調用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 

回答

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