VBS case

Microsoft Windows xp professional w/serv...
February 21, 2010 at 11:47:32
Specs: Windows XP
I am trying to write a vbscript but found out that you can't do a "goto" in vb. What's the alternative to goto in vb?

I have a case statement with some of the cases doing 1 set of actions afterwards and the others doing another set, then after the case specific action both sets of cases follow onto the same actions. How can I do this?


See More: VBS case

Report •

#1
February 21, 2010 at 16:57:15
it would help a lot if you could post what you've got (just the portion of the script that you are describing - don't really need all the "housekeeping", inits, etc.)

Report •

#2
February 22, 2010 at 04:47:21
It's a good thing you cant do GOTO in a given language, it means another - smarter - command covers that. Like Nbrane says, post the code (or the part of code), and it'll be easy from there on.

Report •

#3
February 22, 2010 at 05:52:35
'Get Country
log.WriteLine("1. Dubai")
log.WriteLine("18. Other")

cou_id= InputBox("Please enter the number that corespond to your Office:", "Computer Setup")

Select Case cou_id
Case "1"
computerNameprefix="AEDB"
servername=computerNameprefix&"-NW1"
Case "18"
log.WriteLine("19. Athens")
log.WriteLine("20. Sofia")
End Select

log.WriteLine("Computer will have "&computerNameprefix&" prefix, servername="&servername)
'Get CN and check it
empCN = InputBox("Enter the CN of the employee who will be assigned this computer:", "Computer Setup")
If empCN = "" Then
log.WriteLine("No CN entered, cancelling. To re-run Setup, execute c:\setup.vbs.")
WScript.Quit
End If

log.WriteLine("CN: " & empCN)

dn = CheckForCN(empCN)

If dn = "" Then
log.WriteLine("User '" & empCN & "' not found in ldap on LDAP. Please create Novell account first.")
log.WriteLine("To re-run setup, execute c:\setup.vbs")
WScript.Quit
End If

'Get password
passwd = InputBox("Enter the password for " & empCN & ":", "Computer Setup")
If passwd = "" Then
log.WriteLine("No password entered, cancelling. To re-run Setup, execute c:\setup.vbs.")
WScript.Quit
End If


Report •

Related Solutions

#4
February 22, 2010 at 06:01:18
Sorry, I suck at scripting so its difficult to explain without a process diagram.

I want case = "1-17" then proceed. If case = "18-other" then write list of new sites, then set computernameprefix and servername ect. Then proceed but needs to skip the "If dn" section and rejoin at get password section.

How should I do this? Later in the script I will need have a few if/then statements to split if "1-17" or "other". I was thinking about defining a variable for "1-17"="connected" and "other"="non-connected".

Let me know if it doesn't make sense. Cheers!


Report •

#5
February 22, 2010 at 13:48:09
its difficult to explain without a process diagram.
Then give us a diagram. From what you described, you probably shouldn't be using Select Case at all.

Report •

#6
February 22, 2010 at 14:31:48
ok.. Where is upload attachment?

Report •

#7
February 22, 2010 at 14:34:51
There isn't one. If you can't relay the important parts of the diagram in text, pick one of the free upload services. I prefer mediafire.

Report •

#8
February 22, 2010 at 15:29:37
It looks like you need something like this structure:

if cou_id > "0" and cou_id<"17" then
seventeen
else
eighteen
end if
'Get password - RESUME PROCEDURES - ALL ID'S
passwd = InputBox("Enter the password for " & empCN & ":", "Computer Setup")
If passwd = "" Then
log.WriteLine("No password entered, cancelling. To re-run Setup, execute c:\setup.vbs.")
WScript.Quit
End If
end
sub seventeen
computerNameprefix="AEDB"
servername=computerNameprefix&"-NW1"
end sub

sub eighteen
'******** BEGINNING OF 18+ PROCEDURE
log.WriteLine("19. Athens")
log.WriteLine("20. Sofia")
log.WriteLine("Computer will have "&computerNameprefix&" prefix, servername="&servername)
'Get CN and check it
empCN = InputBox("Enter the CN of the employee who will be assigned this computer:", "Computer Setup")
If empCN = "" Then
log.WriteLine("No CN entered, cancelling. To re-run Setup, execute c:\setup.vbs.")
WScript.Quit
End If
log.WriteLine("CN: " & empCN)
dn = CheckForCN(empCN)
If dn = "" Then
log.WriteLine("User '" & empCN & "' not found in ldap on LDAP. Please create Novell account first.")
log.WriteLine("To re-run setup, execute c:\setup.vbs")
WScript.Quit
End If
' ***** END OF 18+ PROCEDURES
end sub

if you need to handle individual logging for id's 1-17, I would set up an array 1-17 with values.
subroutines are the best way to handle this kind of stuff, imo, easier to follow logic.


Report •

#9
February 22, 2010 at 16:45:56
if cou_id > "0" and cou_id<"17" then
Be very, very, VERY careful with this syntax. You're doing string comparisons, here, so "2" > "17", and that's probably not what we want.

Report •

#10
February 22, 2010 at 18:02:34
yeah, i wondered about that! i'm not good with vbscript, and my test arrangement kicked an error if i did numeric comparison and the data entered was a string, (which is not supposed to happen but users could enter anything to an inputbox). I tried "val" and "num" to try and filter it out but to no avail, so i just went with string compare. how do you separate strings from numbers in vbs without kicking errors?

Report •

#11
February 23, 2010 at 07:42:23
Here is a process diagram of how it should flow:

http://www.mediafire.com/file/woyum... Process Diagram2.vsd

My scripting knowledge isn't very good so if you know of a cleaner or restructured way please tell me. As you can see there is alot of duplication, so much so I thinking of just having - if non connected site run a separate vbscript. But that has its pro's and con's also.


Report •

#12
February 24, 2010 at 04:19:34
bump post. please help!

Report •

#13
February 24, 2010 at 08:06:12
i tried to look at your process diag, but i don't have anything to view ".vds" file.

if cou_id > 0 and cou_id<17 then
seventeen
else
eighteen
end if
'--- password stuff


Report •

#14
February 24, 2010 at 09:53:32
Here is a .jpg version - http://www.mediafire.com/file/jg2jw... Process Diagram2.JPG

Report •

#15
February 24, 2010 at 12:10:01
the jpeg helped.
i would just set values to defaults (either workstation or server) and go from there.
probably just set defaults to workstation-mode and change them if user enters "1".
i'm unclear why you would want to use 1, 18 instead of just 1,2,3.
kinda like this:
computername=""
srvprefix=""
srvsuffix=""
workstn="1"
shell1="\mcafee\setup.exe"
'dummy command does nothing
shell2="cmd /c exit"
'to enable windows update
enablupd=1
dn="ok"
log..writeline ("1. Dubai ** server config")
log..writeline ("2. Athens **workstation")
log..writeline ("3. Sofia **workstation")
id=inputbox("please select your office location: ")
if id< "0" or id>"3" then
msgbox ("id blah blah aborting")
wscript.quit
end if
empCN=inputbox("enter computer/employee name: ")
if empCN="" then
msgbox ("name blah blah aborting")
wscript.quit
end if
if id="1" then
srvrprefix="AEDB"
srvrsuffix="-NW1"
workstn="0"
'i don't know what these really consist of, plug in what's needed
'either batch scripts or executables
shell1="\epo\setup.exe"
shell2="\patchlnk\setup.exe"
enablupd=0
dn = CheckForCN(empCN)
if dn="" then
msgbox ("blah blah")
wscript.quit
end if
end if
'note: prefix and suffix are both null in case of workstation
computername=srvprefix&empCN&srvrsuffix
'Get password
passwd = InputBox("Enter the password for " & empCN & ":", "Computer Setup")
If passwd = "" Then
log.WriteLine("No password entered, cancelling. To re-run Setup, execute c:\setup.vbs.")
WScript.Quit
End If

you shouldn't have to do much more testing i don't think.
when it gets to branchpoint #2 (right after "email computer details"),
configure Novell with the value that is already in "workstn", (zero or one),
then run the two shells using var.s shell1 and shell2 which have whichever commands
needed for either type of setup.
shell (shell1)
shell (shell2)

hope this helps.


Report •

Ask Question