home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Test an array for empty?

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2632
Discussions: 200,998, Posts: 2,379,965, Members: 246,365
Old March 20th, 2002, 09:55 AM   Digg it!   #1 (permalink)
ph34r t3h g04t
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 19,579
Blog Entries: 7
Test an array for empty?

How do you test an array to see if it's empty? Basically, here's what I got:

VB6! Make sure you look at both functions or it probably won't make all that good a sense. Anyway, I need to check to see if aFiles has any data. It errors in the For Each loop if it doesn't. What? I could use For i = 0 to UBound(aFiles)?? I know, I just want to do it this way. And knowing how to test an unset array would be nice too...

Code:
Public Sub DirectoryMain()
    Dim Directory As New DirChooser
    Dim sLocation As String
    Dim fMaster As String
    Dim fCopy As String
    Dim aFiles() As String
    Dim sFile As Variant
    
    On Error GoTo ErrorHandler
    sLocation = Directory.GetFolderName
    
    fMaster = "Q:\cad\acad\validation-tool\qc2k.mdb"
    fCopy = sLocation & "qc2k.mdb"
    FileCopy fMaster, fCopy

    aFiles = MakeDrawingArray(sLocation)
    ' TriQuickSortString is an array sorting function not shown here.
    TriQuickSortString aFiles
    
    ' Now here is where I would like to test aFiles
    ' to see if it's been given any data by assigning
    ' it to the MakeDrawingArray function...
    For Each sFile In aFiles
        If UCase(Right(sTemp2, 8)) <> "TITL.DWG" _
        And UCase(Right(sTemp2, 12)) <> "TBLKINFO.DWG" Then
            ThisDrawing.Application.Documents.Open sLocation & sFile
        End If
    Next
    
    Exit Sub
    
ErrorHandler:
    Resume Next
End Sub

Public Function MakeDrawingArray(ByVal sLocation As String)
    Dim aFiles() As String
    Dim sFile As String
    Dim z As Integer
    
    sFile = Dir(sLocation & "*.dwg")
    ReDim aFiles(0) As String
    aFiles(0) = sFile
    sFile = Dir
    z = 1
    
    While sFile <> ""
        ReDim Preserve aFiles(z) As String
        aFiles(z) = sFile
        sFile = Dir
        z = z + 1
    Wend
    
    MakeDrawingArray = aFiles
        
End Function
I think that should do it... Thanks.

-Whir

Last edited by Whir : March 20th, 2002 at 10:00 AM.
Whir is online now   Reply With Quote
Old March 20th, 2002, 03:43 PM     #2 (permalink)
Senior Member
 
Join Date: Oct 2001
Posts: 881
Send a message via AIM to zskillz
you could check to see if the size of the array is 0...

or, you could check to see if each value in the array is 'null' or something like that with a while loop... if a value != 'null', then break from the loop and return that it's not empty.

-Z
zskillz is offline   Reply With Quote
Old March 21st, 2002, 01:40 PM     #3 (permalink)
ph34r t3h g04t
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 19,579
Blog Entries: 7
If you dim an array as you have to to do what I'm doing 'Dim aFiles() as String' it doesn't support array methods. Therefor, no aFiles.Count. UBound(aFiles) similarly doesn't work if the there are no values in the array, and a For Each temp in aFiles would error because there are no 'temp's in aFiles when it's empty. aFiles(0) will also error because there's nothing there to check.

I thought there was a way to do something like If aFiles Is Empty or something like that, but that only works for a certain type of array and it's not the one I'm using. :P

-Whir
Whir is online now   Reply With Quote
Old March 22nd, 2002, 12:45 AM     #4 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,402
jeez everybody is doing things the hard way lol

If Not IsEmpty(aArrayName) Then
Set aArrayName = Nothing
End

lol
arghh I rmember that lol....
sorry misread
Have you tried IsNull(aArray) or if aarray Is nothing ?
__________________
Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.
vass0922 is online now   Reply With Quote
Old March 25th, 2002, 05:32 PM     #5 (permalink)
ph34r t3h g04t
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 19,579
Blog Entries: 7
Ya, I've tried If Not Is Empty, Is Null, Is Nothing... Silly me, I was using a For To statement to ReDim the array. Hey dummy, is your integer 0? No? Then there are values in the array huh? Sometimes I'd like to shoot my fingers for not thinking of this stuff.

Also, you can make a seperate function that uses an error handler, and check for a value in Array(0). If it doesn't error it returns false, if it errors, it hits the error handler and returns true. Found that on Planet Source Code by a guy name Citizen Suicide. Kind of a hack way to do it, but it does work.

After figuring out (FINALLY) how to declare a control's connection to a database after initialization (thanks to MSDN for once) I finally got the app done. It's only been what, four months?

-Whir
Whir is online now   Reply With Quote
Old March 25th, 2002, 06:02 PM     #6 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,402
Quote:
After figuring out (FINALLY) how to declare a control's connection to a database after initialization (thanks to MSDN for once) I finally got the app done.

That's why I just do it all in code, no ado controls.
Just put in the correct references and off you go
Requires more code, but far more dynamic.

LOL check to see if element 0 has a value???
Ok now I've done some half a55 before but that's THIN LOL

Do you assign it a default value just in case it really isn't supposed to have a value?
Like if it doesn't have a value put in 0 so its more reliable to test?
vass0922 is online now   Reply With Quote
Old March 26th, 2002, 01:35 PM     #7 (permalink)
ph34r t3h g04t
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 19,579
Blog Entries: 7
No, see, that was another guy's method I found on PSC. I wouldn't do that because it's really hack and I'm not (ya right).

The problem I have with using code for connections is that I have to bind controls to the connection and I have NO idea how to do it. MSDN doesn't give me anything on it, and the guy that used to teach me stuff here doesn't have time anymore. If you have an ADO, or DAO in this case, control you can just bind text boxes to the control and voila, you're done.

To sovle the array problem, I just made my array builder assign Array(0) as False if it doesn't get redimed at all. Then I just test for that. It doesn't make sense, but if you saw the way I built the modules, you'd understand and probably show me an easier way to do it. :P

-Whir
Whir is online now   Reply With Quote
Old March 27th, 2002, 12:30 AM     #8 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,402
ahh binding...
I've never really had the oppurtunity to bind...
I always had variable table names, and many times column names so couldn't bind anything through the controls.

arghhh that really sucked making a stored procedure in T-SQL with variable table names

mostly I updated the controls on an event... whether it be changing rows in the recordset or whatever.


-- edit --
Cool, my 2400th post
vass0922 is online now   Reply With Quote
Old March 27th, 2002, 11:00 AM     #9 (permalink)
ph34r t3h g04t
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 19,579
Blog Entries: 7
Ya, that was the other option, which isn't bad, or hard, just a lot more code. :P Call me a wuss, but I'd rather let the controls take care of it, since that's what they're there for. :P

-Whir
Whir is online now   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3099)
Charges against non-tippers dropped.. (22)
Health Care Rationing (17)
Foxconn Blackops x48 MoBo (5)
Nvidia GTX 260 problem (14)
Delete an OS (17)
Laptop with wireless problem. (13)
Wireless Televisions. (12)
windows vista security holes (19)
CPU fan stops spinning randomly (11)
Regular Build (11)
Point and Shoot Camera Suggestions. (9)
[F@H SPAM 11/16/09] ! 1/2 months to.. (41)
windows 7 problem (7)
Recent Discussions
Outputing 1080p from my PC to my 720p.. (0)
panasonic dmr ez48veb recorder (0)
add ram to existing (3)
Need help getting speakers to work (2)
Nvidia GTX 260 problem (14)
Laptop with wireless problem. (13)
Point and Shoot Camera Suggestions. (9)
Is the PSU I received dead? (16)
FreeAgent drive software not x64 comp.. (1)
Intel 5100 AGN issues fixed yet? (28)
Foxconn Blackops x48 MoBo (5)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (41)
Print spooler problem (17)
Q9650 vs. Q9550 (2)
Desktop Calendar Application (2)
Looking for new motherboard (1)
soundmon.exe (8)
Jedi Academy Problem (3)
Can a page file be "too big".. (1)
Size after cutting 700Mb file is 2.5 .. (0)
Delete an OS (17)
windows vista security holes (19)
updating BIOS via winflash, claims fi.. (1)
New Server Configuration Suggestions (0)
cheap gaming laptop? (12)


All times are GMT -4. The time now is 12:32 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28