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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve Values from ListBox 2

Status
Not open for further replies.

RClarkeJr

Programmer
Nov 10, 2004
20
US
Hi Guys,

I have a listbox which contains up to 5 files which a user can attach to an email. I am having difficulty writing vbscript which will grab all the values in the listbox. Can someone please help? Thank you in advance.
 
Can you show some of the code for the listbox and for how you are trying to grab the data?

[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]
 
This is the code to add the file to the listbox
Code:
Sub cmdAddF_OnClick
	Dim optOption
	Dim lstIndex
	Dim lstCount	
	Set optOption = document.createElement("OPTION")
	lstIndex = document.FORM1.lstForms.selectedIndex		
	If document.FORM1.txtFile.value = "" then
		lstCount = document.FORM1.lstFile.length
		document.FORM1.txtComment.value = lstCount
			If lstCount = 5 then
				MsgBox "You have Exceeded the Maximum of Five (5) files", , "Fax It"
				Exit Sub
			End if
		optOption.text = document.FORM1.lstForms.value
		optOption.value = document.FORM1.lstForms.value	
		document.FORM1.lstFile.add optOption
		FileNames = optOption.text 		
	Else
		lstCount = document.FORM1.lstFile.length
		document.FORM1.txtComment.value = lstCount
			If lstCount = 5 then
				MsgBox "You have Exceeded the Maximum of Five (5) files", , "Fax It"
				Exit Sub
			End if
		optOption.text = document.FORM1.txtFile.value 
		optOption.value = document.FORM1.txtFile.value
		document.FORM1.lstFile.add optOption
		FileNames = optOption.value
		
		
	End If
End Sub

This is the only code I have so far for the retrieving
Code:
Sub CheckFileList
	Dim lstIndex
	lstIndex = 0
	
	
	
End Sub
 
So I would get the lsitbox object then create a collection of its children and iterate through them getting the INNERText of each.

[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]
 
TomThumbKP,

Stupid question, how would I do that?
 
This will clean up duplicate code in your original Sub, and give you the foundation for your second one:

Code:
Sub cmdAddF_OnClick
    Dim optOption
    Dim lstIndex
    Dim lstCount    
    lstCount = document.FORM1.lstFile.length
    document.FORM1.txtComment.value = lstCount
    If lstCount >= 5 then
        MsgBox "You have Exceeded the Maximum of Five (5) files", , "Fax It"
    Else
      Set optOption = document.createElement("OPTION")
      lstIndex = document.FORM1.lstForms.selectedIndex        
      If document.FORM1.txtFile.value = "" then
        optOption.text = document.FORM1.lstForms.value
        optOption.value = document.FORM1.lstForms.value    
      Else
          optOption.text = document.FORM1.txtFile.value 
          optOption.value = document.FORM1.txtFile.value
      End If
    End If
    document.FORM1.lstFile.add optOption
    FileNames = optOption.value
End Sub

Sub CheckFileList
    Dim lstIndex
    For lstIndex = 0 to document.FORM1.lstFile.length - 1
      'Do whatever with document.FORM1.lstFile(lstIndex).value
    Next
End Sub

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top