Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn a variable based on the input of a function (.NET C# or VB)
    primarykey
    data
    text
    <p>Say I've got the following variables:</p> <pre><code>Public Shared x As String = "100" Public Shared y As String = "text" Public Shared z As String = "something" </code></pre> <p>And I got a function:</p> <pre><code>Function giveVar(ByVal varName As String) As String Return varName End Function </code></pre> <p>But this doesn't do what I want, naturally. What I want is that my function <code>giveVar</code> returns the value of the variable that holds <code>giveVar</code>. For example I call <code>giveVar("x")</code> I want my function to return <code>"100"</code>. </p> <p>Of course this can be done by a <code>Select Case</code> but thats not what I like to do. Does anyone has any suggestion? Is it even possible to call a value based on a string?</p> <p>[edit:]</p> <pre><code>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 </code></pre> <p>I think this works so far, BUT I get the following error on the <code>CallByName(Me, varName, vbGet)</code> at the <code>Me</code> : <code>"me is only valid within an instance method"</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload