Results 1 to 5 of 5

Thread: [RESOLVED] Working with Arrays and checking if an array element contains nothing

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Resolved [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.

  2. #2
    Addicted Member
    Join Date
    Oct 2006
    Location
    Chennai, India
    Posts
    198

    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.
    Regards
    Srinivasan Baskaran
    India

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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.

  4. #4

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Working with Arrays and checking if an array element contains nothing

    thanks RhinoBull,

    It works.

  5. #5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width