Let me best describe this issue.
I am trying to get Visual Basic (2010 Express) execute the value of a string variable, rather than the varialble itself.
As an example (then I'll quote the context).
Dim tmpString1 as string = LocalFolder
Dim tmpString2 as String = "GlobalVariables.str" & tmpString1
Dim tmpVal1 as String = "Hello"
GlobalVariables.strLocalFolder = "World"
tmpString2 = tmpVal
' Result = "Hello"
' Result = "World" ...
' This should result in "Hello"
In other words I want VB to process the line
tmpString2 = tmpVal
GlobalVariables.strLocalFolder = tmpVal
but this is the struggle.
That's the end goal, let me explain in context so perhaps a better approach can be suggested.
I have a long list of registry keys I want to import into a variable with the same name. These variables are stored within a GlobalVariables class that already exist and have default values set (the registry setting value should overwrite that of the default setting).
The string looks like this:
Dim strSettingList As String = "LocalFolder, SlideDuration, PictureX, PictureY"
Then I am converting the string into an array:
Dim strSettingArray() As String = Split(strSettingList, ",")
I'm then declaring several more strings I will use to construct the registry lookup:
Dim intCount As Integer = Nothing
Dim tmpString As String = Nothing
Dim tmpVariable As String = Nothing
I am using a For, Next loop to read each item in the strSettingArray array, go and get that registry key and apply it to the variable name of the same name inside my GlobalVariables class.
read registry key LocalFolder and apply it to the GlobalVariables.strLocalFo
read registry key SlideDuration and apply it to the GlobalVariables.strSlideDu
I am trying to make the For Next loop work because I am going to have about 50 different registry keys, and would like to dynamically add new keys just be expanding the original strSettingList comma delimited string.
This is how I'm doing that:
For intCount = LBound(strSettingArray) To UBound(strSettingArray)
tmpVariable = "GlobalVariables.str" & strSettingArray(intCount)
If Not My.Computer.Registry.GetValue("HKEY_CURRENT_USER\SOFTWARE\MyApplication", CStr(strSettingArray(intCount)), Nothing) Is Nothing Then tmpVariable = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\SOFTWARE\MyApplication", CStr(strSettingArray(intCount)), Nothing)
MsgBox(tmpVariable) ' This returns the correct value as defined in the registry
MsgBox(GlobalVariables.strLocalFolder) ' Returns the old value of the variable defined in its declaration, but it should be the same as tmpVariable.
The last step is to apply the value to a text box with the same name, ie:
"txt" & tmpVariable & ".text" = tmpString
and I am hitting the same hurdle.
Any advice or suggestions would be appreciated. I've spent the last 24 hours trying to figure out a solution, well and truly stumped on this.