• 0

how do i exit a vbscript conditionally...


Question

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

11 answers to this question

Recommended Posts

  • 0

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

  • 0

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

  • 0

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

  • 0

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.

  • 0

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.

  • 0

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.

  • 0

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

  • 0

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 by bigflavor
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Windows 7 its the peak of windows desktop experience, it felt polished, it was CONSISTENT, the UI was not something made to ###### people off it was more functional and productive because everything felt like a improvement. Windows 8 was horrible they did fix a little with 8.1 but the thing its that in usability it was the same as 7 you can avoid all the metro stuff, you don't need to use the cripple setting or metro stuff, for me it was bearable because it can be customized and you can make it like 7 (sure you waste time setting stuff) even if you needed a third party app. And there are serious performance improvement over 7 faster startup, Windows 10 was ok too nothing felt out of place and the start menu was usable it was filled with bloat but as usual you can remove it, what i really hated about 10 at that time it have worse windows update, you cant customize what update to install and the privacy and telemetry is horrible again it was bearable even but w11, not only they double down on things that i seriously hate on 10 like the bloat, they force changes that make no sense, make an worse start menu, worse context menu, worse task bar. force microsoft account. When i tried w10 iot enterprise LTSC on a ancient laptop, i felt that it was a throwback of what OLD windows should be a normal desktop OS with only the basics and you put the rest it was fast fluid functional, no nagging, its a productive, spend less time setting up the OS the way i want it. every windows after 7 its making it worse for me because i have to spend more time setting up
    • https://filepilot.tech/ File Pilot is a whole lot faster and offers a lot of the same features. Has a free beta available, but it looks like it's going to be a paid app in the future.
    • 24H2 was absolutely plagued with stability and compatibility problems, many of which are still not solved. You don't have to take my word for that either, given that Microsoft have an official know issues page available. Games using older versions of Easy Anti-Cheat still cause 24H2 to lock up and/or BSOD, and there's still a compatbility hold on upgrades if you have them installed as a result. Maybe 25H2 will be less of a dumpster fire, but I wouldn't count on it given Microsoft's recent track record.
    • No I don't also get my news for one source. Have you considered that maybe I just don't care about tech enough to spend time reading multiple sources? Anyway my website preferences are way off topic.
    • The bloat on windows after 7 was acceptable, but 11 its even worse than chinese android phone makers, because at least they can remove the ads or apps, but w11 shove you bloat with no option to remove it, it seems that 25h2 will fix that
  • Recent Achievements

    • Week One Done
      MIghty Haul earned a badge
      Week One Done
    • One Month Later
      MIghty Haul earned a badge
      One Month Later
    • Collaborator
      KD2004 earned a badge
      Collaborator
    • One Month Later
      ataho31016 earned a badge
      One Month Later
    • One Month Later
      Delahenty Machinery earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      594
    2. 2
      Michael Scrip
      200
    3. 3
      ATLien_0
      192
    4. 4
      +FloatingFatMan
      140
    5. 5
      Xenon
      127
  • Tell a friend

    Love Neowin? Tell a friend!