RobZeilinga
April 17th, 2001, 05:09 AM
Hi All,
Is there a way of interpreting a string ?
str = "bb = 10"
interpret(str) <- this is what I want to be able to do!
debug.print bb (will print out 10)
many thanks
RobZ
Iouri
April 17th, 2001, 07:37 AM
dim bb as string
bb= "10"
debug.print bb
that will print 10 in the debug window
Iouri Boutchkine
iouri@hotsheet.com
John G Duffy
April 17th, 2001, 07:47 AM
Here is something I ran across. I did not write it. Start a new Project, Add a Module. Add a ComboBox, A command Button, two labels and a textBox using the default names to the form.
http://www.vb-helper.com/HowTo/execline.zip
Purpose
Execute a line of code stored in a string
Method
Use the EbExecuteLine API function.
Thanks to Sergio Perciballi (oigres@postmaster.co.uk).
Disclaimer
This example program is provided "as is" with no warranty of any kind. It is
intended for demonstration purposes only. In particular, it does no error
handling. You can use the example in any form, but please mention
www.vb-helper.com.
' Copy the following to a form
'------------------------------------------
' (c) 1999 Trigeminal Software, Inc. All Rights Reserved
'------------------------------------------
'Thanks to ----------michka - Michael Kaplan
'Rest of code by Sergio Perciballi -oigres P (Aug-6-2000)
'Email: oigres@postmaster.co.uk
'Uses the function used by the immediate window
'to execute a line of code.
option Compare Text
option Explicit
private Declare Function EbExecuteLine Lib "vba6.dll" _
(byval pStringToExec as Long, byval Foo1 as Long, _
byval Foo2 as Long, byval fCheckOnly as Long) as Long
' for VB5 IDE
'Declare Function EbExecuteLine Lib "vba5.dll" _
(byval pStringToExec as Long, byval Foo1 as Long, _
byval Foo2 as Long, byval fCheckOnly as Long) as Long
' for Access 97/VBE.dll clients like Word 97 and Excel 97
'Declare Function EbExecuteLine Lib "vba332.dll" _
(byval pStringToExec as Long, byval Foo1 as Long, _
byval Foo2 as Long, byval fCheckOnly as Long) as Long
Function FExecuteCode(stCode as string, _
optional fCheckOnly as Boolean) as Boolean
FExecuteCode = EbExecuteLine(StrPtr(stCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function
private Sub Combo1_Click()
Text1.Text = Combo1.List(Combo1.ListIndex)
End Sub
private Sub Command1_Click()
Dim res as Boolean
res = FExecuteCode(Text1.Text)
Label1.Caption = "Status = " & res
End Sub
private Sub Form_Load()
Combo1.AddItem "?secret"
Combo1.AddItem "msgbox secret"
Combo1.AddItem "secret2"
Combo1.AddItem "for x=0 to 5:?" & Chr$(34) & "hello " & Chr$(34) & "&x:next:beep"
Combo1.AddItem "sendkeys " & Chr$(34) & "{TAB}" & Chr$(34) & ":sendkeys " & Chr$(34) & "{up}" & Chr$(34)
Combo1.AddItem "shell " & Chr$(34) & "calc.exe" & Chr$(34) & ",vbNormalFocus"
Combo1.AddItem "shell " & Chr$(34) & "c:\windows\explorer.exe ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" & Chr$(34) & ",vbNormalFocus"
Combo1.AddItem "form1.text1.visible=false"
Combo1.AddItem "form1.text1.visible=true"
Combo1.AddItem "form1.combo1.listindex=1"
Combo1.AddItem "msgbox app.Title"
Combo1.AddItem "form1.combo1.listindex=1:form1.command1.value=true"
Combo1.ListIndex = 0
Show
End Sub
' Copy the following to a module
option Explicit
'need to be public functions/subs to be available
'/******************************************************************************
public Function secret() as string
'/******************************************************************************
secret = "this is a secret subroutine"
End Function
'/******************************************************************************
public Sub secret2()
'/******************************************************************************
MsgBox "this is a secret subroutine 2"
End Sub
John G
RobZeilinga
April 17th, 2001, 07:52 AM
Sorry Perhaps i didn't make myself clear! apologies
What I require is the generation of variables at runtime,
i.e. say that the variable bb has never been defined.
in a textbox I type bb=10.( or any other variable I require)
I would like to be able to later in the program use the variable
Another way of putting it is as follows:
in a running EXE enter into a textbox the following: aa = mid("Hello",2,1)
then followed by a function to extract the value of aa ( remember this is all run-time)
what it boils down to is an exe which can be used to demonstrate all the VB functions without actually writing code !
Many Thanks
RobZ
RobZeilinga
April 17th, 2001, 08:19 AM
John, You are the MAN !!!!
That was exactly what i was looking for ( AWESOME !!!)
(ok excuse spelling i'm really excited)
Once again Thanks
RobZ