Solved

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

Posted on 2011-09-20
5
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

627 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