Thanbor
asked on
Macro Substitution in VB.Net
In FoxPro you can use the ampersand character to indicate macro substitution. For example:
TableName = "Companies"
FieldName = "Location"
Use &TableName index &FieldName
FoxPro would see the '&' and substitute "Companies" in place of &TableName and "Location" in place of &FieldName.
Is there a way to do something similar in VB.NET?
TableName = "Companies"
FieldName = "Location"
Use &TableName index &FieldName
FoxPro would see the '&' and substitute "Companies" in place of &TableName and "Location" in place of &FieldName.
Is there a way to do something similar in VB.NET?
Oops, sorry - I answered a bit soon there. I just found this: http://www.thecodeproject.com/dotnet/evaluator.asp
If you are interested in executing a runtime-built string, you might want to take a look.
A warning, however: code built up from strings at runtime can be a nightmare to debug, so if you can possibly do without this feature it's probably worth avoiding it.
If you are interested in executing a runtime-built string, you might want to take a look.
A warning, however: code built up from strings at runtime can be a nightmare to debug, so if you can possibly do without this feature it's probably worth avoiding it.
ASKER
What I really want to do is issue a call with the name of the function called in a variable. I was hoping for the macro substitution so that I could do this:
MyFunc = "TheRealFucntionName"
Call &MyFunc()
which should be translated as
Call TheRealFuntionName()
I REALLY need to use control arrays like we were able to in VB6, so I worked out a way to do it thus far:
It works except that all the controls (buttons in my example) in the array need to have a select case to handle EACH button in the one event handler that is executed when any button in the array is clicked. The handler works fine catching all the button clicks, but you are stuck in it unless you can define a case to do something for each button dynamically. You can dynamically add buttons at run time by redimming the button array and the button info array but you can't dynamically add more buttons at run time than you have cases in the handler. I have an array of buttons and an parallel array of button information that includes button index and the function to be called. I just cant get that function called without the macro substitution.
Is there a better way to do this?
MyFunc = "TheRealFucntionName"
Call &MyFunc()
which should be translated as
Call TheRealFuntionName()
I REALLY need to use control arrays like we were able to in VB6, so I worked out a way to do it thus far:
It works except that all the controls (buttons in my example) in the array need to have a select case to handle EACH button in the one event handler that is executed when any button in the array is clicked. The handler works fine catching all the button clicks, but you are stuck in it unless you can define a case to do something for each button dynamically. You can dynamically add buttons at run time by redimming the button array and the button info array but you can't dynamically add more buttons at run time than you have cases in the handler. I have an array of buttons and an parallel array of button information that includes button index and the function to be called. I just cant get that function called without the macro substitution.
Is there a better way to do this?
ASKER
Let me rephrase part of that. You CAN add more buttons than you have cases in the handler, its just that you cant dynamically add cases, so again you are stuck in the handler.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry to be the bearer of bad news :-P
VB.NET does support the #Const and #If / #EndIf conditional compilation directives, but only in a very limited form.
The #Const directive could be just what you need, except for one thing: you cannot use a constant declared with it in anything except an #If expression.
(If you're after more detail, check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vadirif.asp).
Another similar thing is normal Consts (Const blah As Integer = 12), but they can only replace variables - not code.
To create different code text based on a const, you may need to build a string and tell the runtime to compile and execute it. I don't think .NET really
supports this, but if you are desperate it could be worth looking into.
PS: If anyone out there can contradict me, I would be overjoyed - macro substituion can be a _very_ useful tool.