Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

16 Experts available now in Live!

Get 1:1 Help Now