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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use a string variable to input command 1

Status
Not open for further replies.

lived

Programmer
Jun 6, 2000
39
CA
I'm trying to get the user input a line of code and then execute it. I want it to look like this:

Code:
Private Sub inputbox_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then commandline$ = inputbox.Text
End Sub

Private Sub Command1_Click()
commandline$ 'execute the command
End Sub
or there is a way to write the string to a file and then execute it?
thanx in advance

SkyFighter
 
I believe you will want to look at using the shell command:

Shell "cmd /c " & commandline
 
a way to write the string to a file and then execute it?

Open "C:\Test.bat" For Output as #1
Print #1, "Dir"
Close #1

Shell "C:\Test.bat"

This example will execute very quickly, but its just for illustration purposes.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
I think i did not be explicit enough. i want to run a VB statements from a variable and not a Ms-dos command line

commandinput$ = "For i = 1 to 3 : next"
execute commandline

Or to load a sub or fonction previously saved on disk?
any idea?


SkyFighter
 
Here's one potential solution:

Private Function ExecString(strExpression As String)
With CreateObject("MSScriptControl.ScriptControl")
.Language = "vbscript"
ExecString = .ExecuteStatement(strExpression)
End With
End Function

which might be called like:

execstring "for x = 1 to 3: msgbox x: next
 
This solution is workable for me, thank you strongm!

SkyFighter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top