Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-20
5
Medium Priority
?
301 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 2000 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

972 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