Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 9 of 9

Thread: Check If Array Is Set

  1. #1
    Join Date
    20th July 2006
    Posts
    50

    Check If Array Is Set

    Hello.
    I would like to know if there is a straight forward way to check if dynamic array is set (initialized)?
    Is Nothing doesnt work with arrays and I dont want to use On Error GoTo becouse I dont like making jumps inside code.
    Sorry for this simple question but there is nothing about this in book i use and I couldnt find it in this forum.
    Last edited by Thor; April 29th, 2007 at 16:17.

  2. #2
    Join Date
    19th July 2004
    Location
    Tokyo, Japan
    Posts
    8,479

    Re: Check If Array Is Set.

    Quote Originally Posted by Thor
    Hello.
    I would like to know if there is a straight forward way to check if dynamic array is set (initialized)?
    Is Nothing doesnt work with arrays and I dont want to use On Error GoTo becouse I dont like making jumps inside code.
    Sorry for this simple question but there is nothing about this in book i use and I couldnt find it in this forum.
    How about

    IsArray function?

    Excel Video Tutorials / Excel Dashboards Reports


  3. #3
    Join Date
    20th July 2006
    Posts
    50

    Re: Check If Array Is Set.

    Is array checks if variable is array. It doesnt check if it was initialized.

    VB:
     
    Dim myArray() As String 
    msgbox IsArray( my Array ) 
    
    
    This will return true.

  4. #4
    Join Date
    19th July 2004
    Location
    Tokyo, Japan
    Posts
    8,479

    Re: Check If Array Is Set.

    I just want to know why do you need this?
    Because, if you declared an array variable, it is already there as an array.

    Excel Video Tutorials / Excel Dashboards Reports


  5. #5
    Join Date
    20th July 2006
    Posts
    50

    Re: Check If Array Is Set.

    Well I need dynamic array.
    So I dont set it size at the beginning because well I don't know how big array I need.
    Then when I populate array I need position of last element. But if its not initialize UBound will throw error.

    Of course I can get around this in few ways but having some straight forword way to check if array is initialized would simplyfie code (a little).
    Plus I thought that this should be possible but I just couldn't find it so I just wanted to know.
    But if this is not possible in VBA then no problem, really.
    It is just bugging me.

  6. #6
    Join Date
    18th September 2005
    Location
    Hampshire, UK
    Posts
    1,278

    Re: Check If Array Is Set.

    Hi

    Could you test to see if the Ubound of the array is 0? Eg:

    VB:
    Sub test() 
        Dim myArray() As String, l As Long 
        On Error Resume Next 
        l = UBound(myArray) 
        On Error Goto 0 
        Debug.Print l 
    End Sub 
    
    

    Excel Video Tutorials / Excel Dashboards Reports


  7. #7
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310

    Re: Check If Array Is Set.

    Some googling returned this suggestion by C Pearson.
    VB:
    Sub x() 
         
        Dim strX() As String 
         
        If (Not Not strX) <> 0 Then 
            MsgBox "Allocated" 
        Else 
            MsgBox "Unallocated" 
        End If 
         
        Redim strX(3) As String 
         
        If (Not Not strX) <> 0 Then 
            MsgBox "Allocated" 
        Else 
            MsgBox "Unallocated" 
        End If 
         
    End Sub 
    
    

    Cheers
    Andy


  8. #8
    Join Date
    2nd December 2004
    Location
    Frankfurt, D
    Posts
    383

    Re: Check If Array Is Set.

    Andy,

    great hint!!!

    filippo

    Excel Video Tutorials / Excel Dashboards Reports


  9. #9
    Join Date
    20th July 2006
    Posts
    50

    Re: Check If Array Is Set

    Hehe. Works. Great.
    Thanks Andy Pope.
    I tested many things but (Not Not) , strange.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Check/Compare Array Elements
    By nb- in forum EXCEL HELP
    Replies: 2
    Last Post: May 12th, 2008, 06:44
  2. Check If Variable Holds An Array
    By Ktrasler in forum EXCEL HELP
    Replies: 4
    Last Post: April 4th, 2008, 10:01
  3. Check If Element Exists In Array
    By Lavner in forum EXCEL HELP
    Replies: 5
    Last Post: December 3rd, 2007, 16:39
  4. Check If Value Exists In an Array
    By tkmanoj in forum EXCEL HELP
    Replies: 15
    Last Post: September 11th, 2007, 06:37
  5. Check for presence of a value in an array
    By slickity in forum EXCEL HELP
    Replies: 4
    Last Post: October 15th, 2005, 03:09

Bookmarks

Posting Permissions

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