Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create an drop down list in vbscript.

Status
Not open for further replies.

redlair

Technical User
Jun 29, 2004
54
US
I need to have a user select one of multiple locations and then input the selected location in to a path. When doing a web search all I find, is related to asp and web. I just need a window box with a drop down list to choose one of our locations.
 
This can't be done natively with pure vbscript. You can however create and HTA and do it with a combination of vbscript and HTML.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
To do it without HTML I just prompted with an inputbox that had a simple numeric menu.

ex.
Enter the NUMBER for your selection:

1. choice 1
2. choice 2
3. choice 3


Then I just check to make sure that the person entered a number between 1 and 3 if they didn't then prompt and do it again.

Kinda quick and kinda dirty. But it is also simple, yet effictive.


 
Can you give an example of this input box?
 
Here's a bit of code that should get you started. I use this method to print labels in specific formats. Hope this helps.

mapman04

Dim strMsg,inp01,strTitle,strFlag

strTitle = "Answer Box"

strMsg = "Enter A for Alaska" & vbCR
strMsg = strMsg & "Enter D for Delaware" & vbCR
strMsg = strMsg & "Enter T for Texas" & vbCR

strFlag = False

Do While strFlag = False

inp01 = InputBox(strMsg,"Make your selection")

Select Case inp01
Case "A"
MsgBox "You picked Alaska!",64,strTitle
strFlag = True
Case "D"
MsgBox "You picked Delaware!",64,strTitle
strFlag = True
Case "T"
MsgBox "You picked Texas!",64,strTitle
strFlag = True
Case Else
MsgBox "You made an incorrect selection!",64,strTitle
End Select

Loop

Wscript.Quit
 
inputbox.jpg


That is my inputbox. I am using simiar code as to what is posted above.
 
Thank you for the advice. What If you have 70 Locations or Choices?
 
If you can logically break you choices into groups of about five you can use multiple input boxes.

that is a lot of options for a lowly script.
can your user just type in what they need?


if it is to be it's up to me
 
how about a dummy folder structure which lists all the locations???
you can then launch a FileDialog box and get the user to select the folder or file which has the location name???
silly suggestion perhaps.
 
that's kinda a cool idea. I will have to keep that one in mind
 
Well for something with folders to work you would have to make a directory structure on your harddrive. You would need a folder to represent each choice.

Check out BrowseForFolder:

If you are using strictly Windows XP I know there is a way to use a much nicer file dialog box but I can't find what it is called. (maybe somebody else know off the top of their head)

-Matt
 
Redlair:

As TomThumbKP suggested eariler, try using a HTA. Copy this code into a text file and then save it as "Site.HTA". Then click on it and it should open giving you your drop down box.
(A thanks to TomThumbKP for the assistance with a HTA I was working on.)

mapman04

<HEAD>
<TITLE>Drop Down Menu</TITLE>
<HTA:APPLICATION ID="oMyApp"
APPLICATIONNAME="Drop Down"
BORDER="Dialog"
CAPTION="Yes"
SCROLL="NO"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="Yes"
WINDOWSTATE="maximize">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="VBScript">

Sub Window_OnLoad
Window.Site.Focus
End Sub

Sub btn01_OnClick
Dim strProduct

oElements = Window.Site.SelectedIndex
strProduct = Window.Site.Options(oElements).Text

Select Case strProduct
Case "Ohio"
MsgBox "You selected Ohio",64,"Selection"
Case "Texas"
MsgBox "You selected Texas",64,"Selection"
Case "Site 22"
MsgBox "You selected Site 22",64,"Selection"
Case "Site 70"
MsgBox "You selected Site 70",64,"Selection"
End Select

End Sub

Sub btn02_OnClick
Window.Close
End Sub
</SCRIPT>

<H2>Drop Down Example</H2>
<P>Please select the Site:
<SELECT NAME="Site">
<OPTION>Ohio</OPTION>
<OPTION>Texas</OPTION>
<OPTION>Site 22</OPTION>
<OPTION>Site 70</OPTION>
</SELECT><P>

<BR>
<BR>
<Input Type = "Button" Name = "btn01" VALUE = "SUBMIT">
<Input Type = "Button" Name = "btn02" VALUE = "CLOSE">
<BR>
<BR>

</BODY>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top