Analyze Variant Elements Within Variant Array

  • Hi,


    Within my code, I have an array called Possible which is an array of type Variant with size (1 to 9, 1 to 9). Each element within the array can either be:

    1) empty

    2) a single element

    3) multiple elements


    what I am looking to do is loop though each element within Possible and see if the number of sub-elements in each position is 1 or not. I have tried using the following code but it is giving me an error:

    Code
    For i = 1 to 9
        For j = 1 to 9
            If UBound(Possible(i,j)) = 1 then
                'do some stuff here
            end If
        Next j
    Next i
  • UBound will raise an error if the argument is not an array. If the element is a scalar, like a Long or String, that will cause an error.


    I also suggest making the loop constraints dynamic.

    I think you want something like this:


    Jeff


    Making the world a better place one fret at a time | | |·| |·| |·| |·| | |:| | |·| |·|

  • Hi Jeff,


    Thank you for your response. I'm not quite sure your suggestion will work for what I'm trying to do though. I don't care about the ones that are empty and the ones that have more than one element are an array (i.e. I only care about the scalar elements). If I do something like:

    will this work the way I expect it to?

  • I showed all the choices for completeness so it would be clear the logic I was using. You don't need to use all of them.

    I tested your idea and it seems to work.

    Jeff


    Making the world a better place one fret at a time | | |·| |·| |·| |·| | |:| | |·| |·|

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!