Community
Showing results for 
Search instead for 
Do you mean 
Reply

create a new Variable using a value from a Field?

Highlighted
New Member
Posts: 1
Country: USA

create a new Variable using a value from a Field?

Is it possible to create a new Variable using a value from a Field?

 

For instance, if a Field value is "Address1" I like to create a new Variable called Address1

 

"Dim [Variable Name] as string = [Field value]"

 

In Visual FoxPro, I could use a macro expression to create a new variable:

 

 "&[Variable Name] = [Field value]"

 

 

Does this work in vb.NET? If so, would you show a code snippet to do this?

 

Thanks!

Bronze Super Contributor
Posts: 1,245
Country: USA

Re: create a new Variable using a value from a Field?

[ Edited ]

Helen,

Being an old VFP guy myself I would love .NET to do some of the stuff we had years ago in Fox.

 

There are two ways I have found workarounds.

 

1) declare a dictionary of variable ( or a two dimensional array ) where you can store them.

 

Dim variables As New Dictionary(Of String, Integer)()
variables("MyDynamicVariable") = 10 ' Set the value of the "variable" Dim value As Integer = variables("MyDynamicVariable") ' Retrieve the value of the variable

 

2) The second is to dynamically compile on the fly. 

There are many pros and cons to this methodology. I use it heavily for scripting in Impact Suite and took weeks to write.

There is too much code to show an example so here is a link to the MS topic.

https://support.microsoft.com/en-us/help/304654/how-to-programmatically-compile-code-by-using-the-vi...

 

Here's a good article by Rick Strahl, (he's an old VFP guy too)

https://www.codemag.com/Article/0211081/Dynamically-Executing-Code-in-.NET

 

 

Hope this helps

-- Jim Durkin