ListBox first row blank (loaded by array)

Doggie
03-24-2003, 08:19 AM
When the following code loads my ListBox, the ListBox contains a blank first row. I suppose I could find and then delete that row, but I'd rather know why this is happening (and correct it) than apply a band-aid.

Thanks!

Range("A" & Format(intTranTypeBegin - 1)).Select
ReDim strArray_TranType(intNumRows, 1 To 5) As String
For intForNex1 = 1 To intNumRows
strArray_TranType(intForNex1, 1) = ActiveCell.Offset(intForNex1, 0).Value
strArray_TranType(intForNex1, 2) = ActiveCell.Offset(intForNex1, 1).Value
strArray_TranType(intForNex1, 3) = ActiveCell.Offset(intForNex1, 2).Value
strArray_TranType(intForNex1, 4) = ActiveCell.Offset(intForNex1, 3).Value
strArray_TranType(intForNex1, 5) = ActiveCell.Offset(intForNex1, 4).Value
Next intForNex1
frmTranType.lstTranType.List() = strArray_TranType

Wamphyri
03-24-2003, 08:27 AM
When the following code loads my ListBox, the ListBox contains a blank first row. I suppose I could find and then delete that row, but I'd rather know why this is happening (and correct it) than apply a band-aid.

My guess is because your array's index starts at 1 while a listbox's list index starts at 0.

Doggie
03-24-2003, 08:35 AM
When the following code loads my ListBox, the ListBox contains a blank first row. I suppose I could find and then delete that row, but I'd rather know why this is happening (and correct it) than apply a band-aid.

My guess is because your array's index starts at 1 while a listbox's list index starts at 0.
OK, I'll have a look at that. Thanks!

Wamphyri
03-24-2003, 08:50 AM
I made a mistake there. Ignore my first post, it is the ramblings of a sleep deprived madman. Actually your array is starting at zero.
You've got a 2 dimensional array the array is (0 to intNumRows, 1 To 5)
Since you are never entering anything into array index (0, 1 to 5) it is an zero length string "". That zero length string is the first element in your array so you are getting a blank line in your listbox. Just change your array to
ReDim strArray_TranType(1 to intNumRows, 1 To 5) As String

Doggie
03-24-2003, 11:05 AM
I made a mistake there. Ignore my first post, it is the ramblings of a sleep deprived madman. Actually your array is starting at zero.
You've got a 2 dimensional array the array is (0 to intNumRows, 1 To 5)
Since you are never entering anything into array index (0, 1 to 5) it is an zero length string "". That zero length string is the first element in your array so you are getting a blank line in your listbox. Just change your array to
ReDim strArray_TranType(1 to intNumRows, 1 To 5) As String
Absolutely correct, it's working now. Many thanks!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum