从类内部调用 Property Let

发布于 2024-12-09 22:38:55 字数 690 浏览 0 评论 0原文

有没有办法从同一个类内部调用 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

Is there a way calling a Property Let method from inside the same class?

Like this function SetConnectionDetails. But this one gets a Compile error: Invalid use of property...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⊕婉儿 2024-12-16 22:38:55

您将其称为普通属性/变量:

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

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

You call it as a normal property/variable:

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

Or, more explicitly:

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

Note that I've removed the () around the values/parameters is they shouldn't (normally) be there, and may catch you out later.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文