假设我有以下变量:
Public Shared x As String = "100"
Public Shared y As String = "text"
Public Shared z As String = "something"
我得到了一个功能:
Function giveVar(ByVal varName As String) As String
Return varName
End Function
但这自然不是我想要的。我想要的是我的函数giveVar
返回持有的变量的值giveVar
。例如,我打电话给giveVar("x")
我希望我的函数返回"100"
。
当然,这可以通过 a 来完成,Select Case
但这不是我喜欢做的。有人有什么建议吗?甚至可以根据字符串调用值吗?
[编辑:]
Namespace i18n
public NotInheritable Class Settings
Public Shared LanguageCode As String
Public Shared HideAllLocalizedText As Boolean
End Class
Public NotInheritable Class i18n
Private Sub New()
End Sub
Public Shared Function t(ByVal varName As String) As String
Select Case Settings.LanguageCode
Case "en"
Return en(varName)
Case Else
Return nl(varName)
End Select
End Function
Private Shared Function en(ByVal varName As String) As String
Dim ASP_0344 As String = "Cancel"
Dim ASP_0807 As String = "Click"
Dim ASP_0808 As String = "here"
Dim ASP_0812 As String = "Welcome at the login screen..."
' These are examples there is a whole bigger list
Return CallByName(Me, varName, vbGet)
End Function
Private Shared Function nl(ByVal varName As String) As String
Dim ASP_0344 As String = "Annuleren"
Dim ASP_0807 As String = "Klik"
Dim ASP_0808 As String = "hier"
Dim ASP_0812 As String = "Welkom op het inlogscherm..."
Return CallByName(Me, varName, vbGet)
End Function
End Class
End Namespace
我认为这到目前为止有效,但我在CallByName(Me, varName, vbGet)
at上收到以下错误Me
:"me is only valid within an instance method"