Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    100

    Unanswered: How to see if there is something in an array

    Hi people,

    This question is more about VB but I don't find the solution.
    I have an array of a structure that I defined.
    I want to know in one moment of the program if this array has elements or is empty.
    I cannot use IsEmpty neather the comparison MyArray=Nothing, and so on.
    When the array is "empty" the watcher tell me that its value is Nothing. But I cannot do any comparison!

    Please help.

    Thanks in advance.

  2. #2
    Join Date
    Feb 2004
    Location
    CT,USA
    Posts
    250
    You will need to loop thru your array and look at each value. If you have a value other than null-- it's not empty. This sounds like a function call to me.

    function fIsArrayMT(x as array) as boolean

    dim i as integer
    ' here you may need to Redim the array to be size of one passed

    fIsArrayMT = True ' set to True
    for i = 0 to ubound(x)
    if x(i) <> "" then fIsArrayMT = False ' any occurrance of data = false
    next i

    end function

  3. #3
    Join Date
    Nov 2003
    Posts
    104
    You can initialize the array into some dummy value, like say a NULL or a -1.

    Then you write a FOR/next loop to look at each element. And if u see your dummy value (NULL or -1 or something else), then u return a false meaning the array does not contain anything meaningful. Hope that helps

  4. #4
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    100
    Originally posted by shassouneh
    You can initialize the array into some dummy value, like say a NULL or a -1.

    Then you write a FOR/next loop to look at each element. And if u see your dummy value (NULL or -1 or something else), then u return a false meaning the array does not contain anything meaningful. Hope that helps
    Yes I thought that also. The problem is the array is dynamic, I erase the array (Erase MyArray), then I would like to say MyArray = Null for later comparations with, for example, If IsNull(MyArray). Or whatever value, like Empty. But I cannot set my dynamic array of my own data type to any of these values: Null, Empty, -1 ... The compiler says "type mismatch", I can understand why the compiler doesn't allow me to do that. But I don't get my objective, that is: to know if MyArray has elements or not. I also tried with the functions Len and LenB without any result.

    Thank you all for your help.

    Any idea? I think some people had to find the same problem. But I don't want to create a first element in the array to initialize all the fields of my structure with Null. Cause other function is taking data from this array to fill a ListBox. I prefer to have the array empty.

  5. #5
    Join Date
    Feb 2004
    Location
    CT,USA
    Posts
    250
    Please, give us some code segments of what your are trying to do.

  6. #6
    Join Date
    Nov 2003
    Posts
    104

    not a problem (I don't think)

    Quote Originally Posted by pipeio
    Yes I thought that also. The problem is the array is dynamic, I erase the array (Erase MyArray), then I would like to say MyArray = Null for later comparations with, for example, If IsNull(MyArray). Or whatever value, like Empty. But I cannot set my dynamic array of my own data type to any of these values: Null, Empty, -1 ... The compiler says "type mismatch", I can understand why the compiler doesn't allow me to do that. But I don't get my objective, that is: to know if MyArray has elements or not. I also tried with the functions Len and LenB without any result.

    Thank you all for your help.

    Any idea? I think some people had to find the same problem. But I don't want to create a first element in the array to initialize all the fields of my structure with Null. Cause other function is taking data from this array to fill a ListBox. I prefer to have the array empty.

    Not a problem either

    I think you can use something like this

    Code:
    Dim x as integer
    for x=1 to Len(MyDynamicArray)
          MyDynamicArray(x) = -1
    next x
    Last edited by shassouneh; 04-28-04 at 17:41. Reason: to make the code look more like code rather than text

Posting Permissions

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