User-158480776 posted
Environment: Windows 8; WebMatrix; Visual Basic
- Can I name a variable using the contents of another variable and if so how do I do it?
To use an example;
i. A database field contains the value "UK1"
ii. I have recovered that value to a variable called "Publisher_Code"
iii. Another field in the database contains the value 6
iv. I have recovered that value to a variable called "Series_Count"
v. I now want to create a VB array variable called and sized somewhat like this -
Dim Series_Codes_[the contents of Publisher_Code](Series_Count) As Array
Bottom line - I don't know the syntax for invoking the contents of Publisher_Code while I'm declaring the variable.
I have seen a similar query to this elsewhere and the reply included some references to using objects and the following C# code snippet, but I couldn't work out how to adapt that to VB and to my specific example above,
var obj = { someprop:"someval", otherprop:… },
name = "someprop";
obj[name]; // "someval"
The same post also included this line -
"You can't really,
variable names (identifiers) are static (as long as you don't use
eval
) in a scope."
Eval doesn't seem to be a VB statement, so though I would be willing to use something that 'evaluates' the dim statement I again do not know how to effect such 'evaluation'.
With hopes for a positive answer and thanks in anticipation
Best regards
Philip, Perth, Western Australia