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!

microsoft script control 1

Status
Not open for further replies.

n2jesus

Programmer
May 20, 2003
66
0
0
US
Hi all,

I am trying to use the script control inside of a visual basic application. However, when I try to do something like set wshell = createobject("wscript.shell")
it gives me a syntax error.

Is it possible to create a shell (thus gaining control of other applications) using the script control? If so, how?

My app is going to be a gui where users can make selections, and then click a button which will place their selections into a script and run it. The script will be copying and pasting info between 3 different applications, thus the need for the shell.

Thanks for any help,

jim
 
n2jesus,
Sorry, but I don't get that error. One thing to try, if you haven't already done so, is to place
Code:
Option Explicit
at the top of your code. This forces you to decalre your variables, and may flag a diferent issue that may effect your object creation. Also, don't forget to
Code:
Set wshell = Nothing
at the end of your code.

Zy
 
Ok, I just tried this:

Option Explicit

Private Sub Command1_Click()

sc.ExecuteStatement("set wshell = createobject("wscript.shell")")

End Sub


(the script control is all on one line in vb)

when I hit enter to go to the next line I get this error:

Compile error:
Expected: list separator or )

and the debugger highlights "wscript" every time.

thanks for any help,

Jim
 
Try something like this:
Code:
sc.ExecuteStatement("set wshell = createobject("&Chr(34)&"wscript.shell"&Chr(34)&")")

Hope This Help
PH.
 
Those chr(34) calls create double-quotes. A perhaps more-legible way of putting double quotes in a string without er, prematurely ending it is to escape them. In vbscript escape a " in a string by doubling it up.
So:
[tt]
sc.ExecuteStatement("set wshell = createobject(""wscript.shell"")")
[/tt]

uh oh that's gotten confusing..
I've colored in green the string you want to execute, which will be: set wshell = createobject("wscript.shell") as you have cleverly escaped the quotes.

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top