bj-kaiser Posted June 29, 2009 Posted June 29, 2009 Option ExplicitConst strConnection = "RAS"Const strUsername = "UserXYZ"Dim oShellSet oShell = CreateObject ("WScript.Shell")'run command and wait for it to exitoShell.Run("rasdial.exe " & strConnection & " " & strUsername, 1, true)OK, I'm new to vbscript, can somebody point out what in heck is wrong with that script? it looks good to me...seems to be ok until WSH hits the "oShell.Run" line, there I get a compile error "no brackets allowed in subroutine call" or something like that. (german windows xp)
Yzöwl Posted June 29, 2009 Posted June 29, 2009 Option ExplicitConst strConnection = "RAS"Const strUsername = "UserXYZ"Dim oShellSet oShell = CreateObject ("WScript.Shell")'run command and wait for it to exitoShell.Run("rasdial.exe " & strConnection & " " & strUsername, 1, true)OK, I'm new to vbscript, can somebody point out what in heck is wrong with that script? it looks good to me...seems to be ok until WSH hits the "oShell.Run" line, there I get a compile error "no brackets allowed in subroutine call" or something like that. (german windows xp)Try either one of the following:oShell.Run "rasdial.exe" & " " & strConnection & " " & strUsername, 1, trueoShell.Run("rasdial.exe" & " " & strConnection & " " & strUsername), 1, true
Mijzelf Posted June 29, 2009 Posted June 29, 2009 Well then remove the brackets:oShell.Run "rasdial.exe " & strConnection & " " & strUsername, 1, trueWorks. Personally I hate VBScript for this kind of (apparent?) inconsistencies. CreateObject has to have brackets, and Run should not have. My advice is to use JScript instead. You can do the same things with a much more clear syntax.
MHz Posted June 29, 2009 Posted June 29, 2009 (edited) ... I get a compile error "no brackets allowed in subroutine call" or something like that. (german windows xp)You will find that subroutines do not return a value so do not use brackets. On the use of functions with storing the returned value into a variable, then you may need to use brackets. I keep to that concept and has proven consistent with good results.So this should be finesubroutine "parameter"and thisvariable = function("parameter")The below (reversed usage of brackets) will occur error that I would expect.subroutine ("parameter")and thisvariable = function "parameter"So if it returns a value, then use brackets, else do not. I'm not sure by my memory atm about the following, but if you do not store the value of a function return, then do not use brackets (like a subroutines behavior) to avoid error. A function may require brackets if used with an IF statement like below to also avoid error.If function("parameter") ThenEdit:Added last sentence about using IF statement Edited June 29, 2009 by MHz
bj-kaiser Posted June 29, 2009 Author Posted June 29, 2009 I figured it out by now... brackets without storing the value = BAD.one reason why I like AutoIt over vbscript... but for what I am working on I am trying to work with what comes in the box with Windows, since I dont want to add too much additional stuff. (Thin client system= XP embedde)
Mijzelf Posted June 30, 2009 Posted June 30, 2009 but for what I am working on I am trying to work with what comes in the box with Windows, since I dont want to add too much additional stuff.JScript is as available as VBScript. It's the same engine (WScript.exe or CScript.exe), only a different syntax. Your code in JScript would be:var strConnection = "RAS";var strUsername = "UserXYZ";var oShell;oShell = WScript.CreateObject ("WScript.Shell");// run command and wait for it to exitoShell.Run("rasdial.exe " + strConnection + " " + strUsername, 1, true);save as .js file, and it just works.
gunsmokingman Posted June 30, 2009 Posted June 30, 2009 You could just make this a oneline script.CreateObject ("WScript.Shell").Run("rasdial.exe RAS UserXYZ"),1,true
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now