Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Unable to retrieve value from drop down list (values read from textfile)

Reply
 
Old 07-25-2008   #1 (permalink)
Steven Andrews


 
 

Unable to retrieve value from drop down list (values read from textfile)

Hi

I have a txt file containing client names. What I am trying to do is
create a HTA with a drop down box with the list of client names. WHen I
select a client name and click next I will do something with that
information. To start with I thought I'd get a message box telling me
what client I had selected. The drop down box is populated correctly,
but when I select a client and click next, the message box is blank.

clientList.txt contains (sample data)

steven andrews
bob wilson
amanda peterson


What I am using is as follows:


<html>
<SCRIPT Language="VBScript">

sub LoadDropdown

Set oShell = CreateObject( "WScript.Shell" )
TempDirectory=oShell.ExpandEnvironmentStrings("%temp%")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(TempDirectory&"\clientList.txt", 1)
strClientData=objFile.ReadAll
objFile.Close

arrClientData = Split(strClientData,vbNewLine)
For Each strClientData in arrClientData
Set objOption = Document.createElement("OPTION")
objOption.Text = strClientData
DropDown1.Add(objOption)
Next
end Sub


sub NextSelected()
Msgbox "This: "&dropdown1.value
end Sub


</SCRIPT>


<select size="1" name="DropDown1">

</select>

<input id=onebutton class="button" type="button" value="Next"
name="one_button" onClick="NextSelected"><p>
<input id=twobutton class="button" type="button" value="Populate"
name="two_button" onClick="LoadDropDown"<p>
</body>
</html>

My System SpecsSystem Spec
Old 07-25-2008   #2 (permalink)
Steven Andrews


 
 

Re: Unable to retrieve value from drop down list (values read fromtext file)

Bah

Another 10 minutes searching provided this:

<html>
<SCRIPT Language="VBScript">

sub LoadDropdown

Set oShell = CreateObject( "WScript.Shell" )
TempDirectory=oShell.ExpandEnvironmentStrings("%temp%")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(TempDirectory&"\clientList.txt", 1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set objOption = Document.createElement("OPTION")
objOption.Text = strLine
objOption.Value = strLine
DropDown1.Add(objOption)
Loop
objFile.Close
End Sub


sub NextSelected()
Msgbox "This: "&dropdown1.value
end Sub


</SCRIPT>


<select size="1" name="DropDown1">

</select>

<input id=onebutton class="button" type="button" value="Next"
name="one_button" onClick="NextSelected"><p>
<input id=twobutton class="button" type="button" value="Populate"
name="two_button" onClick="LoadDropDown"<p>
</body>
</html>

Essentially a change to the way the file is read and the drop down box
is created. This works fine.

Steve


Steven Andrews wrote:
Quote:

> Hi
>
> I have a txt file containing client names. What I am trying to do is
> create a HTA with a drop down box with the list of client names. WHen I
> select a client name and click next I will do something with that
> information. To start with I thought I'd get a message box telling me
> what client I had selected. The drop down box is populated correctly,
> but when I select a client and click next, the message box is blank.
>
> clientList.txt contains (sample data)
>
> steven andrews
> bob wilson
> amanda peterson
>
>
> What I am using is as follows:
>
>
> <html>
> <SCRIPT Language="VBScript">
>
> sub LoadDropdown
>
> Set oShell = CreateObject( "WScript.Shell" )
> TempDirectory=oShell.ExpandEnvironmentStrings("%temp%")
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile(TempDirectory&"\clientList.txt", 1)
> strClientData=objFile.ReadAll
> objFile.Close
>
> arrClientData = Split(strClientData,vbNewLine)
> For Each strClientData in arrClientData
> Set objOption = Document.createElement("OPTION")
> objOption.Text = strClientData
> DropDown1.Add(objOption)
> Next
> end Sub
>
>
> sub NextSelected()
> Msgbox "This: "&dropdown1.value
> end Sub
>
>
> </SCRIPT>
>
>
> <select size="1" name="DropDown1">
>
> </select>
>
> <input id=onebutton class="button" type="button" value="Next"
> name="one_button" onClick="NextSelected"><p>
> <input id=twobutton class="button" type="button" value="Populate"
> name="two_button" onClick="LoadDropDown"<p>
> </body>
> </html>
My System SpecsSystem Spec
Old 07-25-2008   #3 (permalink)
Old Pedant


 
 

RE: Unable to retrieve value from drop down list (values read from tex

If you care....

You don't HAVE to give a VALUE to each <OPTION> if you don't want to.

Instead, you could code:

sub NextSelected()
Msgbox "This: " & dropdown1.options(dropdown1.selectedIndex).text
end Sub


My System SpecsSystem Spec
Old 07-25-2008   #4 (permalink)
Steven Andrews


 
 

Re: Unable to retrieve value from drop down list (values read fromtex

Old Pedant wrote:
Quote:

> If you care....
>
> You don't HAVE to give a VALUE to each <OPTION> if you don't want to.
>
> Instead, you could code:
>
> sub NextSelected()
> Msgbox "This: " & dropdown1.options(dropdown1.selectedIndex).text
> end Sub
>
>

That actually makes more sense and I think easier to read code... Thanks
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How do i retrieve only the values from array ? PowerShell
Read-Host values into an Array PowerShell
Read values returned from a powershell command in VB.Net PowerShell
How to read Vista registry values containing @DllFilename.dll? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46