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

List View Error - 35600 1

Status
Not open for further replies.

lykeat

Programmer
Sep 1, 2003
22
MY
Microsoft Windows Common Controls 6.0(SP6)
c:\windows\system32\mscomctl.ocx

Hi,

I am using the listview from the component category Microsoft Windows Common Controls 6.0(SP6), the ocx is mscomctl.ocx.

I had no problem during the design time. After I compiled my code into .EXE, it will shows the following error message.

Run-tme error '35600'"
Index out of bounds.

Following are my coding:

Private Sub Form_Load()
Me.Show

Dim Con
Dim RS
SQL = "SELECT * FROM Customer"
Set Con = CreateObject("ADODB.Connection")


Con.Open frmLogin.ConString

Set RS = CreateObject("ADODB.Recordset")
RS.Open SQL, Con

Dim i As Integer
i = 0
While Not RS.EOF
i = i + 1
lvCustomer.ListItems(i).Text = lvCustomer.ListItems.Add(, , RS(0))
lvCustomer.ListItems(i).SubItems(1) = RS(1)
lvCustomer.ListItems(i).SubItems(2) = RS(2)
RS.MoveNext
Wend
RS.Close
Con.Close
End Sub

The lvCustomer is my listview name.

I preset the view to 3-lvwReport and the columns in the property pages. My OS is Windows XP2 with SP 2

Thanks in advance.
 
hmmm

try this, as I suspect your problems relate to the use of indexes..

Code:
  Dim Con [COLOR=blue]as ADODB.Connection [/color]
  Dim RS [COLOR=blue]as ADODB.Recordset 
  Dim SQL as string
  Dim lvItem as listitem
  [/color]
    
SQL = "SELECT * FROM Customer"
    Set Con = [COLOR=blue]new ADODB.Connection[/color]
  
    
    Con.Open frmLogin.ConString
    
    Set RS = [COLOR=blue]new ADODB.Recordset[/color]
    RS.Open SQL, Con
    
    [COLOR=blue]Do until RS.EOF
       
       Set lvItem = lvCustomer.ListItems.Add(,,RS.Fields.Item(0).Value
       with lvItem.ListSubItems
         .Add ,,RS.Fields.Item(1).Value
         .Add ,,RS.Fields.Item(2).Value
       end with[/color]

        RS.MoveNext
    [COLOR=blue]Loop[/color]
    RS.Close
    Con.Close  
Set lvItem = nothing
set RS = Nothing
Set Con = nothing

I would strongly suggest that you use the variable typing abilities of VB, as it is good practice and makes your code more robust. Likewise, with very few exceptions, people use Option Explicit at the top of each code module (you can configure VB to do it automatically (tools -> Options -> editor and tick the Require Variable declaration box)) doing so will prevent subtle errors from creeping in with mis named variables. As a final point, I personally don't like using ordinals to access recordset fields - I find it easier to use the field name (there is a small performance penalty though)

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Thanks, I'll try this out then feedback to u later.
:)
 
Hi mattKnight: thanks for your helpful post. It solves my problem. I did practice to set the option explicit in my coding, but I never know that it can be do it automatically. Although it is less readable in ordinal form, but I feel that the performance is the most important issue. I heard that using datagrid is better than listview in term of performance, is that true? I might considering to use datagrid.

Once again, thanks a lot.

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top