[RESOLVED] Working with Arrays and checking if an array element contains nothing
Hi Guys,
I have an address field which I split by the vbcrlf character. Now when I split the address and assign it to an array that array could have a different number of elements each time.
I am adding the split data to a listview which has 4 columns.
currently I do this:
Code:
li.SubItems(1) = IIf(AddText(0) = "", "", AddText(0))
li.SubItems(2) = IIf(AddText(1) = "", "", AddText(1))
li.SubItems(3) = IIf(AddText(2) = "", "", AddText(2))
li.SubItems(4) = IIf(IsNull(rs!code), "", rs!code)
that works well if the address is captured correctly, but say I got an address with just "test". Array elements 1,2 and 3 will be "subscript out of range"
Can anyone proved me with a solution or perhaps a better way of doing this.
Re: Working with Arrays and checking if an array element contains nothing
After applying the split to the string, check with the ubound value of the created array to check for the array size.
If suppose you need to check null values in the array, you need to loop thru the array and find and then ignore.
Re: Working with Arrays and checking if an array element contains nothing
Quote:
Originally Posted by Nitesh
Array elements 1,2 and 3 will be "subscript out of range"
Not sure what you mean but your array is ZERO based and apparently it has 3 elements 0, 1 and 2.
Your listview must have at least 5 (five) columns - Item and 4 subitems.
Indexing in listview always starts at 1 (one).
So, from the "indexing" perspective your code looks correct.
However, it can be simplified by doing this:
Code:
Dim i As Integer
For i = 0 To Ubound(AddText)
li.SubItems(i + 1) = AddText(i)
Next i
li.SubItems(4) = "" & rs!code
Although my sample may work I cannot fully guarantee it without actually seeing your data.
Re: Working with Arrays and checking if an array element contains nothing
thanks RhinoBull,
It works. :wave:
Re: [RESOLVED] Working with Arrays and checking if an array element contains nothing