Solved

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

Posted on 2011-09-20
5
287 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Novice question on VBScript 8 52
VBS Script not working correctly. 1 37
Problem to With line 4 41
Message Logon Windows 2012 R2 Server 16 13
Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now