?
Solved

run code that is in a textbox

Posted on 2003-03-04
9
Medium Priority
?
142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

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 53

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 53

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

743 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