Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

macro expansion

Status
Not open for further replies.

mivc31

Programmer
Apr 19, 2005
3
0
0
NL
Is there a way to do macro expansion in visual basic like in visual foxpro? For example;

dim a as string

a="TEXT1"

if Text1 is a textbox control then the following code in foxpro will give me the contents of text1

b = &a

The & operator in foxpro is called macro expansion. Is there a way to do this in visual basic?

Thanks
 
Try this:


Private Sub Command1_Click()
Dim a As String
Dim b As String
a = "text1"

b = Me.Controls(a).Text
MsgBox b
End Sub
 
Here's an alternative solution:
Code:
[blue]Option Explicit

Private Sub Command1_Click()
    Dim a As String
    a = "Text1"
    Debug.Print Macro(a)
    a = "2 + 7 * 16"
    Debug.Print Macro(a)
End Sub

Private Function Macro(strMacro As String)
    With New ScriptControl
        .Language = "vbscript"
        .AddObject "whocaresfornow", Me, True
        Macro = .Eval(strMacro)
    End With
End Function[/blue]
 
Does if you add a reference to Microsoft Script Control library, which I forgot to mention.

(or changing

[tt]With New ScriptControl[/tt]

to

[tt]With CreateObject("MSScriptControl.ScriptControl")[/tt]

which achieves the same effect)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top