?
Solved

run code that is in a textbox

Posted on 2003-03-04
9
Medium Priority
?
143 Views
Last Modified: 2010-04-07
Hi guys

what i am trying to do is....i have a text box and a command button and when
i press the command button i would like it to run whatever code i put in the
text box ..for eg ....if i typed MsgBox "Hello" in the text box and press
the command button it runs MsgBox "Hello".

Regards

Tim
0
Comment
Question by:nutter01
9 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 8069006
afaik, not possible.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8069017
although, i know you can run vbscript/javascript:

reference ms script control under project/references, then do:

Dim scr As New MSScriptControl.ScriptControl

scr.Language = "vbscript"
scr.Eval "msgbox (" & Chr(34) & "Hello World" & Chr(34) & ")"

Set scr = Nothing

(btw, chr(34) is ")
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8069023
sorry tim, but i've been trying to work it out, and i've found out that it is not possible to do.  It would involve inputing the textbox value as string, then converting the string to a subprocedure, or function or something, and that can't be done.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 56

Expert Comment

by:Ryan Chong
ID: 8069074
Actually, i can be done..
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8069077
> Actually, i can be done..
gonna show us how?
0
 
LVL 56

Accepted Solution

by:
Ryan Chong earned 105 total points
ID: 8069081
Try add the M$ Scripting Runtime from your Reference, then implement the example below:


Dim iScript As New ScriptControl
Dim a As Variant
Dim aa As New clsScript

Private Sub Command1_Click()
    On Error GoTo EH
    iScript.Language = "VBScript"
    a = iScript.Eval(Text1.Text)
    MsgBox a
    Exit Sub
EH:
    ShowErrMsg
End Sub

Private Sub Command2_Click()
    On Error GoTo EH
    iScript.Language = "VBScript"
    iScript.Reset
    iScript.AddObject "aa", aa
    iScript.ExecuteStatement Text2.Text
    MsgBox aa.a
    Exit Sub
EH:
    ShowErrMsg
End Sub

Private Sub Command3_Click()
    Randomize
    iScript.Language = "VBScript"
    iScript.Reset
    iScript.AddObject "Command3", Command3, True
    iScript.ExecuteStatement "Command3.Caption = " & Chr$(34) & "Hello World" & Rnd * 1 & Chr$(34)
End Sub

Private Sub Form_Load()
    Command1.Caption = "Eval"
    Command2.Caption = "ExecuteStatement"
    Text1.Text = "(5500 * 0.986)* 12/100"
    Text2.Text = "x = 5500" & vbCrLf
    Text2.Text = Text2.Text & "aa.a = (x * 0.986)* 12/100"
End Sub

cheers
0
 
LVL 56

Expert Comment

by:Ryan Chong
ID: 8069086
Ops, havent realize while bobbit31 already posted the example.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8069089
that's still vbscript, which is pretty much the same as my post above ;)
0
 
LVL 8

Expert Comment

by:List244
ID: 8069117
you want source for a vb compiler? if thats what your looking for good luck
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question