Empty Row added to Listbox???

Hi,
I have a really annoying problem and hopefully someone here can help?

I have a listbox which gets populated from a database - but my listbox keeps inserting an empty row at the end.
I have no idea how / why this is happening??

Here is my code which populates the listbox:

[code]// ---------------------------------------- CLEAR THE LISTBOX AND RETURN THE RESULTS AS A RECORDSET
MembersWindow.Listbox2.deleteAllRows
MembersRS = MembersDB.sqlSelect(sql )

// ---------------------------------------- POPULATE THE MEMBERS LISTBOX FROM THE RECORDSET RESULTS
while not MembersRS.eof
MembersWindow.Listbox2.AddRow
MembersWindow.Listbox2.Cell(MembersWindow.Listbox2.LastIndex, 1) = MembersRS.Field(“Description”).StringValue
MembersWindow.Listbox2.Cell(MembersWindow.Listbox2.LastIndex, 2) = MembersRS.Field(“Name”).StringValue
MembersWindow.Listbox2.Cell(MembersWindow.Listbox2.LastIndex, 3) = MembersRS.Field(“Age”).StringValue
MembersWindow.Listbox2.RowTag(MembersWindow.Listbox2.LastIndex) = MembersRS.Field(“id”).IntegerValue
MembersRS.moveNext
wend[/code]

Surely this code should not be inserting an empty row?

Thank you all in advance.

Not unless the recordset is returning more rows than you think it should

Don’t quite understand what you mean Norman?
My database contains 25 entries, but everytime the listbox gets repopulated via the above method - there are 26 rows?

My money would be on there being an extra blank row in your DB. Have you looked at the DB in an SQL editing program?

Yes - as per my previous post - the database contains 25 entries. The listbox when repopulated displays 26 :frowning:
This is why I cannot work out what’s happening?

Check the value of “count”

MembersRS = MembersDB.sqlSelect(sql )
dim seeVal As integer = membersRS.count

Your code doesn’t create extra rows
I lifted it and made a small sample app with exactly your code (just cut & paste from you original post)
It adds one row when I have 1 row in the DB (which my code created literally 4 lines earlier)
When I have 10 rows it puts 10 in the list

Something else is going on

Thats is why I am so confused.
That method code is called from the Window.Open event, and also each time a member is added.

I have no idea where else to even look :frowning:

I’d certainly check that MembersRS.Count is indeed 25

Have no idea how to modify my code to do that - nothing seems to work and I am now going brain dead :frowning:

How are you refreshing the listbox when you add a record, could it be this code that is adding the blank row?

I’m probably wrong here, but have you tried trim?
http://documentation.xojo.com/index.php/Trim

literally what roger posted

MembersRS = MembersDB.sqlSelect(sql )
dim seeVal As integer = membersRS.count // <<<<<<<< put a break point on this line and when you get to the break hit step over

look at the value in the debugger

Have you tried adding “break” after the “wend” and checking the listbox values there?

If RowCount is 26 then add some code to the loop that breaks just before the 26th. If RowCount is 25 then you can step forward and find where something else is adding it.

This is absurd.
This code works (but adds an empty row):

[code]// ---------------------------------------- CLEAR THE LISTBOX AND RETURN THE RESULTS AS A RECORDSET
MembersWindow.Listbox2.deleteAllRows
MembersRS = MembersDB.sqlSelect(sql )

// ---------------------------------------- POPULATE THE MEMBERS LISTBOX FROM THE RECORDSET RESULTS
while not MembersRS.eof
MembersWindow.Listbox2.AddRow
MembersWindow.Listbox2.Cell(MembersWindow.Listbox2.LastIndex, 1) = MembersRS.Field(“Description”).StringValue
MembersWindow.Listbox2.Cell(MembersWindow.Listbox2.LastIndex, 2) = MembersRS.Field(“Name”).StringValue
MembersWindow.Listbox2.Cell(MembersWindow.Listbox2.LastIndex, 3) = MembersRS.Field(“Age”).StringValue
MembersWindow.Listbox2.RowTag(MembersWindow.Listbox2.LastIndex) = MembersRS.Field(“id”).IntegerValue
MembersRS.moveNext
wend[/code]

But this code (with your additional check) - causes a This Item Does Not Exist error:

[code]// ---------------------------------------- CLEAR THE LISTBOX AND RETURN THE RESULTS AS A RECORDSET
MembersWindow.Listbox2.deleteAllRows
MembersRS = MembersDB.sqlSelect(sql )
dim seeVal As integer = membersRS.count

// ---------------------------------------- POPULATE THE MEMBERS LISTBOX FROM THE RECORDSET RESULTS
while not MembersRS.eof
MembersWindow.Listbox2.AddRow
MembersWindow.Listbox2.Cell(MembersWindow.Listbox2.LastIndex, 1) = MembersRS.Field(“Description”).StringValue
MembersWindow.Listbox2.Cell(MembersWindow.Listbox2.LastIndex, 2) = MembersRS.Field(“Name”).StringValue
MembersWindow.Listbox2.Cell(MembersWindow.Listbox2.LastIndex, 3) = MembersRS.Field(“Age”).StringValue
MembersWindow.Listbox2.RowTag(MembersWindow.Listbox2.LastIndex) = MembersRS.Field(“id”).IntegerValue
MembersRS.moveNext
wend[/code]

Shouldn’t be MembersRS.RECORDCount?

Docs

Ok - yes Joseph, it should have been record count :slight_smile:

I did as Norman advised, and stepped over, and it states 25, as expected. But 26 rows are still displayed :frowning: ;(

there has to be somewhere else you have a call to addrow
this loop isn’t it

After the wend put this

msgbox str(ListBox2.ListCount)

What do you get?

Also do it before the “While” to see if there is any contents in the listbox prior to you adding the records from the database.