-
May 9th, 2016, 02:22 PM
#1
string value used to access another variable value ?
Hi,
I have a variable in one module
public test_var as decimal = "12.345"
In another module I have a variable
public Var_name as string = "test_var"
in this second module i'd like to reference the value in test_var ( which is "12.345") .. but I can only reference it using the value of the string 'var_name' .. which is the actually the name of the variable i need to get the value of.
note : test_var is not a control.
I found an example below that I thought might work ..
- I'm not sure what to substitute 'Me' with ? (note : test_var is not a control.)
- I did substitute it with 'test_var' but 'fi returns nothing
any ideas what i'm doing wrong - thanks
[I]
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public var1, var2 As String 'MUST BE PUBLIC
________________________________________
var1 = "test string"
var2 = "var1"
Dim t As Type = Me.GetType()
Dim fi As FieldInfo = t.GetField(var2) 'get the value of var2's string reference
var3 = fi.GetValue(Me)
-
May 9th, 2016, 08:56 PM
#2
Re: string value used to access another variable value ?
The short answer is no you can't do that.
Your string var will have a string in it, that string value does not link it to the other variable it is simply text.
As for the usage of Me. This refers to the current Class where the code is located.
As for the code itself ????
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|