Solved

Trying to figure out the logic and syntax for a VB Script

Posted on 2011-09-20
5
288 Views
Last Modified: 2012-05-12
I have created a script that so far is working, but I need more logic.  The script gives the user an inputbox with a list of choices above it.  It's a cheap workaround for a combobox in my opnion, but it works.  When the user selects a number the Case is chosen and another box pops up asking the user to validate their choice.  Here is where I need the logic.  If the user selects Yes everything works fine.  But if the user were to select No then I need them returned to the intial dialog box with the menu so they can make a different selection.  How do I do this?  The second thing I need is if the user enters a number other than one on the list, I need them returned to the intial menu so they can choose again.  And lastly if a user chooses a value other than a number or hits Cancel, I need the returned to the menu.  I know the Cancel request is strange, but the user MUST pick a value.  Canceling is not an option.
Dim printerOU
  
strMenu="Select Printer OU" & VbCrLf & VbCrLf &_
"1 SE8thPrinters"  & VbCrLf &_ 
"2 SW8thPrinters" & VbCrLf &_ 
"3 SS9thPrinters" & VbCrLf &_
"4 SN9thPrinters"
  
rc=InputBox(strMenu,"Select OU", 1) 
If IsNumeric(rc) Then 
    Select Case rc 
        Case 1  
            Do While answer <> vbYes
  		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SE8thPrinters", vbYesNo, "Verify Printer OU")
		printerOU = "SE8thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop 
        Case 2 
              Do While answer <> vbYes
   		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SW8thPrinters", vbYesNo, "Verify Printer OU")
		printerOU = "SW8thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop 
        Case 3 
             Do While answer <> vbYes
   		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SS9thPrinters", vbYesNo, "Verify Printer OU")
		printerOU = "SS9thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop
        Case 4 
             Do While answer <> vbYes
   		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SN9thPrinters", vbYesNo, "Verify Printer OU")
		printerOU = "SN9thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop  
        Case Else 
             wscript.echo rc & " is not a choice." 
    End Select 
    Else 
    WScript.Echo "Invalid option. Numbers only." 
End If

Open in new window

0
Comment
Question by:TPBPIT
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
ctgilbert earned 500 total points
ID: 36567202
This should cover everything...
Dim printerOU
  
strMenu="Select Printer OU" & VbCrLf & VbCrLf &_
"1 SE8thPrinters"  & VbCrLf &_ 
"2 SW8thPrinters" & VbCrLf &_ 
"3 SS9thPrinters" & VbCrLf &_
"4 SN9thPrinters"

return = true
while return = true
	rc=InputBox(strMenu,"Select OU", 1)
	If IsNumeric(rc) Then 
		Select Case rc 
			Case 1  
				printerOU = "SE8thPrinters,OU=Printers,DC=domain,DC=com"
			Case 2 
				printerOU = "SW8thPrinters,OU=Printers,DC=domain,DC=com"
			Case 3 
				printerOU = "SS9thPrinters,OU=Printers,DC=domain,DC=com"
			Case 4 
				printerOU = "SN9thPrinters,OU=Printers,DC=domain,DC=com"
			Case Else 
				wscript.echo rc & " is not a choice." 
				printerOU = false
		End Select 
		if printerOU <> false then
			answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SN9thPrinters", vbYesNo, "Verify Printer OU")
			if answer = vbYes then 
				return = false
			end if
		else
		
		end if

	Else 
		WScript.Echo "Invalid option. Numbers only." 
	End If
wend

Open in new window

0
 

Author Comment

by:TPBPIT
ID: 36567255
I have to logic for the case select working now, but I can't figure out what I need to do to get the logic for a wrong number or and non numerical entry working.  I will send it back to the menu, but then you answer witha correct number and it does run through the logic again.  It just displays a blank diallog box and closes.  How should I be handling the case logic so that a wrong answre will bring up the dialog box and then run the logic after a selection?
Dim printerOU, rc
  
strMenu="Select Printer OU" & VbCrLf & VbCrLf &_
"1 SE8thPrinters"  & VbCrLf &_ 
"2 SW8thPrinters" & VbCrLf &_ 
"3 SS9thPrinters" & VbCrLf &_
"4 SN9thPrinters"

MessageBox

Sub MessageBox
	rc=InputBox(strMenu,"Select OU", 1)

If IsNumeric(rc) Then 
    Select Case rc 
        Case 1  
            Do While answer <> vbYes
  		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SE8thPrinters", vbYesNo, "Verify Printer OU")
			If answer = vbNo Then
				MessageBox
			End If
		printerOU = "SE8thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop 
        Case 2 
              Do While answer <> vbYes
   		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SW8thPrinters", vbYesNo, "Verify Printer OU")
			If answer = vbNo Then
				MessageBox
			End If
		printerOU = "SW8thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop 
        Case 3 
             Do While answer <> vbYes
   		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SS9thPrinters", vbYesNo, "Verify Printer OU")
			If answer = vbNo Then
				MessageBox
			End If
		printerOU = "SS9thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop
        Case 4 
             Do While answer <> vbYes
   		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SN9thPrinters", vbYesNo, "Verify Printer OU")
			If answer = vbNo Then
				MessageBox
			End If
		printerOU = "SN9thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop  
        Case Else 
             WScript.echo rc & " is not a choice.  Please select again from the list."
	     MessageBox 
    End Select 
    Else 
    WScript.Echo rc & " is an invalid option. Please select again from the list."
    MessageBox
End If 
End Sub

WScript.Echo printerOU

Open in new window

0
 

Author Comment

by:TPBPIT
ID: 36567269
Opps, I put the wrong code.  Please ignore the code in the last post.  The correct code for the last post is here.
Dim printerOU, rc
  
strMenu="Select Printer OU" & VbCrLf & VbCrLf &_
"1 SE8thPrinters"  & VbCrLf &_ 
"2 SW8thPrinters" & VbCrLf &_ 
"3 SS9thPrinters" & VbCrLf &_
"4 SN9thPrinters"

MessageBox

Sub MessageBox
	rc=InputBox(strMenu,"Select OU", 1)

If IsNumeric(rc) Then 
    Select Case rc 
        Case 1  
            Do While answer <> vbYes
  		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SE8thPrinters", vbYesNo, "Verify Printer OU")
			If answer = vbNo Then
				MessageBox
			End If
		printerOU = "SE8thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop 
        Case 2 
              Do While answer <> vbYes
   		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SW8thPrinters", vbYesNo, "Verify Printer OU")
			If answer = vbNo Then
				MessageBox
			End If
		printerOU = "SW8thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop 
        Case 3 
             Do While answer <> vbYes
   		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SS9thPrinters", vbYesNo, "Verify Printer OU")
			If answer = vbNo Then
				MessageBox
			End If
		printerOU = "SS9thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop
        Case 4 
             Do While answer <> vbYes
   		answer = MsgBox("Is this correct?" & vbCrLf & "Printer OU = SN9thPrinters", vbYesNo, "Verify Printer OU")
			If answer = vbNo Then
				MessageBox
			End If
		printerOU = "SN9thPrinters,OU=Printers,DC=domain,DC=com"
	     Loop  
        Case Else 
             WScript.echo rc & " is not a choice.  Please select again from the list."
	     MessageBox 
    End Select 
    Else 
    WScript.Echo rc & " is an invalid option. Please select again from the list."
    MessageBox
End If 
End Sub

WScript.Echo printerOU

Open in new window

0
 
LVL 2

Expert Comment

by:ctgilbert
ID: 36567290
Did the code I submitted earlier work?
0
 

Author Closing Comment

by:TPBPIT
ID: 36567368
Sorry, for some reason the system didn't email me regarding your first post.  With a small modification it worked like a champ.  Thanks for your quick response to this post.

Cheers
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question