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

Populate a select box with VBScript

Status
Not open for further replies.

Romanichine

Programmer
Apr 9, 2002
30
0
0
CA
Hi,

I got a function that receives a string with delimiters and populates a select box (see code below). It works fine on one computer using IE 6.0 but doesn't work on two computers using IE 5.0.

I was wondering if this was a browser issue and, if yes, how to make it work on any browser.

The error we get is "Invalid Argument" on the following line:
cboReport.options.add objOption



======================
Code:
            Sub RefreshList(dataArr, strSource, strComboName)
    

                Dim cboReport
                Dim lngMaxCtr, lngCtr
                Dim arrReport, arrOneReport
                Dim objOption
                Dim i

                Set cboReport = window.Parent.Top("fraMain").document.Forms(strSource).Item(strComboName)

                lngMaxCtr = cboReport.length - 1
                
                For lngCtr = 0 To lngMaxCtr
                    cboReport.remove(0)
                Next
                
                If dataArr = vbNullString Then
                    Exit Sub
                End If
                
                arrReport = Split(dataArr,"^")
               
                
                for i = 0 to UBound(arrReport)
                    arrOneReport = Split(arrReport(i),"|")
                    Set objOption = document.createElement("option")
                    
                    'arrOneReport(0) -> report_id
                    'arrOneReport(1) -> user_id
                    'arrOneReport(2) -> report_string
                    'arrOneReport(3) -> report_name
				objOption.value = arrOneReport(0)
				objOption.text = arrOneReport(3)
                    cboReport.options.add objOption
                next
                
                set objOption = Nothing
                
            End Sub
======================

Thanks,
--
Roman
 
For the record, here is the version working on IE5. You need to specify the window name when creating an Option object on IE5.

======================

Sub RefreshList(dataArr, strSource, strComboName)


Dim cboReport
Dim lngMaxCtr, lngCtr
Dim arrReport, arrOneReport
Dim objOption
Dim i

Set cboReport = window.Parent.Top("fraMain").document.Forms(strSource).Item(strComboName)

lngMaxCtr = cboReport.length - 1

For lngCtr = 0 To lngMaxCtr
cboReport.remove(0)
Next

If dataArr = vbNullString Then
Exit Sub
End If

arrReport = Split(dataArr,"^")


for i = 0 to UBound(arrReport)
arrOneReport = Split(arrReport(i),"|")
Set objOption = window.Parent.Top("fraMain").document.createElement("option")

'arrOneReport(0) -> report_id
'arrOneReport(1) -> user_id
'arrOneReport(2) -> report_string
'arrOneReport(3) -> report_name
objOption.value = arrOneReport(0)
objOption.text = arrOneReport(3)
cboReport.options.add objOption
next

set objOption = Nothing

End Sub

======================

--
Roman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top