次の変数があるとします。
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")
I want my function to returnを呼び出します"100"
。
もちろん、これは誰でもできますが、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)
ますMe
。"me is only valid within an instance method"