brand Posted August 11, 2005 Share Posted August 11, 2005 so, i was working on a vbscript today... and i simply want to exit the vbscript if the contents of an input box are empty or if it cancels. that's it; no error checking, just hop out the bitch if the input is null so... it goes like what? because i can tell you end exit leave explode combust sublime all don't work i think i saw exit sub but then i'd need to declare a sub, which i don't want to do; but i tried it any way, and it didn't work. if strPath = "" then ______ or is there actually something like if strPath = NULL then _____ that's be even better... please help. thanks, matt Link to comment Share on other sites More sharing options...
0 James Rose Posted August 12, 2005 Share Posted August 12, 2005 Matt, Yes it's EXIT SUB, and yes you have to be in a procedure (or a function) to run ANY vbscript code. So, it would be like: Public Sub Test() sInput = InputBox("Info") If LEN(TRIM$(sInput)) = 0 Then Exit Sub End Sub Link to comment Share on other sites More sharing options...
0 brand Posted August 12, 2005 Author Share Posted August 12, 2005 option explicit 'declaring variables Dim strCompName Dim objShell Public Sub Test() strCompName = inputbox("Enter the computer name that you need to view the agent on.", "ePO Agent Web") If LEN(strCompName)=0 then exit sub 'creates a shell object to run the shell executable with set objShell = WScript.createobject("wscript.shell") 'runs the executable objShell.run ("%windir%\explorer.exe http://" & strCompName & ":8072") exit sub won't run Link to comment Share on other sites More sharing options...
0 James Rose Posted August 12, 2005 Share Posted August 12, 2005 Well, declare your variable inside your procedure. And two, have you tried hard coding the values of this: objShell.run ("%windir%\explorer.exe http://" & strCompName & ":8072") Just to make sure it does run. And, use the TRIM fucntion, just in case someone places in somes spaces in the InputBox, that was it will clean those out Also error handling will help you find the issue. So, you code should look like this: Option Explicit Public Sub Test() Dim strCompName Dim objShell strCompName = inputbox("Enter the computer name that you need to view the agent on.", "ePO Agent Web") If LEN(TRIM(strCompName)) = 0 Then Exit Sub 'creates a shell object to run the shell executable with set objShell = WScript.createobject("wscript.shell") 'runs the executable 'objShell.run ("%windir%\explorer.exe http://" & strCompName & ":8072") objShell.run ("c:\windows\explorer.exe http://www.google.com:8072") 'OR objShell.run ("http://www.google.com:8072") ProcExit: On Error Resume Next Exit sub ProcError: Msgbox Err.Number & " " & Err.Description End Sub Link to comment Share on other sites More sharing options...
0 brand Posted August 12, 2005 Author Share Posted August 12, 2005 call me crazy, but it won't execute anything within the sub; i moved the inputbox out of the public sub, and it executed. but when i moved it back in (even right below the sub), it won't execute. that looks like good VB code, but is scripting a VBS different? Sorry, i'm new to scripting and I do appreciate the help. Thanks, Matt Link to comment Share on other sites More sharing options...
0 James Rose Posted August 12, 2005 Share Posted August 12, 2005 VBS is a subset of VB, and yes I am typing VB code, but the values and functions are items available to VBS. (no need to appologize!!!!) Ok, let me try this. Is this script to be run in a web page? If not, how EXACTLY are you running it. I'll take the time to recreate it, when i know how/where it's running. We'll get it, eventually. Link to comment Share on other sites More sharing options...
0 brand Posted August 12, 2005 Author Share Posted August 12, 2005 I'm simply trying to run a VBS on my system. No webpages.. nothing. this is really my first script, so i'm just getting used to the idea of objects, and stuff like that. I do have experience with VB... not much, but some. so i know END is a keyword (or whatever) in VB6 that will end the program. no worky in VBScripts. Link to comment Share on other sites More sharing options...
0 James Rose Posted August 12, 2005 Share Posted August 12, 2005 Ok, this is on your system. I see. I have run out of time today Finish a bit of work, head home, guests over tonight for a mental-bash! ;) and a music gathering tomorrow. But I will have time to run a test on Sunday or Monday. (sorry) If in the meantime you can state exactly what you are trying to achive. Not the code, but the business reason/logic. Just in case there is a better way to get what you want. Link to comment Share on other sites More sharing options...
0 brand Posted August 12, 2005 Author Share Posted August 12, 2005 all i'm trying to do is launch a web site on port 8072 and the computer name is the web server. it's for ePolicy Orchestra; McAfee install agent type ****. I figured it'd be a good place to start. Thanks for all the time and attn. Peace, Matt Link to comment Share on other sites More sharing options...
0 AndreasV Posted August 13, 2005 Share Posted August 13, 2005 Why not simply revert the exit condition: if something then exit end if Dim i 'some other code to if Not something then Dim i 'some other code end if Link to comment Share on other sites More sharing options...
0 brand Posted August 25, 2005 Author Share Posted August 25, 2005 (edited) Hello, Thanks for all your input guys.... got this bitch. Option Explicit dim strCompName dim objShell dim LoopCount dim i LoopCount = 0 do while LoopCount = 0 strCompName = inputbox("Enter the computer name that you need to view the agent on.", "ePO Agent Web") if StrCompName = "" then LoopCount = 1 elseif not LEN(trim(strCompName)) = 0 Then 'creates a shell object to run the shell executable with set objShell = WScript.createobject("wscript.shell") 'runs the executable objShell.run ("%windir%\explorer.exe http://" & strCompName & ":8072") LoopCount = 1 elseif LEN(trim(strCompName)) = 0 Then i = msgbox ("Chief, you gotta enter a computer name.", 1, "Invalid") end if Loop Thanks, Matt Edited August 25, 2005 by bigflavor Link to comment Share on other sites More sharing options...
0 jaylweb Posted May 16, 2006 Share Posted May 16, 2006 For anyone that may be interested, you can use the following to exit a vbs file. wscript.quit Link to comment Share on other sites More sharing options...
Question
brand
so, i was working on a vbscript today... and i simply want to exit the vbscript if the contents of an input box are empty or if it cancels.
that's it; no error checking, just hop out the bitch if the input is null
so... it goes like what?
because i can tell you
end
exit
leave
explode
combust
sublime
all don't work
i think i saw exit sub
but then i'd need to declare a sub, which i don't want to do; but i tried it any way, and it didn't work.
if strPath = "" then ______
or is there actually something like
if strPath = NULL then _____
that's be even better...
please help.
thanks,
matt
Link to comment
Share on other sites
11 answers to this question
Recommended Posts