Results 1 to 8 of 8
  1. #1

    Empty dynamic arrays

    Is there an easy way to find out if an array is empty? I have tried looking around and haven't found an "easy" way; it just seems like there should be a quick way to do this. i don't want to create a lot of code for something that can be done easily.

    If someone can point me in the right direction, it would be great.

  2. #2

    Re: Empty dynamic arrays

    I have accomplished it with this code... but wondered if there is a more efficient way:

    On Error Resume Next

    Dim intUBoundSQLarr
    intUBoundSQLarr = UBound(arrSQL, 2)

    If Err.number = 0 Then
    <do stuff>
    <do stuff>
    End If

    I'm a little scared to use on Error Resume Next... What if I don't code for all errors? Then what?

  3. #3
    Join Date
    Sep 2001
    Doncaster, UK

    Re: Empty dynamic arrays

    The above code is not checking a 2-dimensional array.

    Mark Smith.

  4. #4

    Re: Empty dynamic arrays

    Thanks for your reply Mark.

    Row is the second dimension of the array... I had to switch rows and columns because I didn't know how many rows I was going to have, and I could only redim the second dimension. Is this still wrong?

  5. #5

    Re: Empty dynamic arrays

    you can resize only the last dimension of the array.

    I would suggest you do your verification when you build your array. From you post I can see you building a array from SQL. So just make sure that the record set is not null.
    Prashant Patel

  6. #6

    Re: Empty dynamic arrays

    I am building the array in a function and passing out the array.... Can I also pass out the size? I thought I could only pass one thing out of a function? I didn't want to have to go through looping through the results more than once (one function to build, and another to count)... I'm sorry, I feel useless right now.

  7. #7

    Re: Empty dynamic arrays

    In order for you to know array is empty or not you have to loop throught the array. If you want to avoide that you must take care this when you build array.
    Please see the example below. If Record set is null then I write to Result file that no data found and print the Entire SQL then ExitAction.

    <font class="small">Code:</font><hr /><pre>
    Function GetDataFromDatabase(sDatabaseName,sUID,sPWD,sSQL)
    'Declare the array
    dim DbArray()

    TotalRow=GetRowsCountFromDatabase(sDatabaseName,sU ID,sPWD,sSQL)

    'Create the connection string:
    strConn="DRIVER={Microsoft ODBC for Oracle};SERVER=" &amp; sDb &amp; ";User ID=" &amp; sUID &amp; ";Password=" &amp; sPWD &amp; " ;"
    'Establish the connection:
    Set oConn = CreateObject("ADODB.Connection")
    'Server-side cursor
    oConn.CursorLocation = 2
    oConn.Open strConn

    'Create a recordset to hold the results
    Set rs = CreateObject("ADODB.Recordset")
    'Options for CursorType are: 0=Forward Only, 1=KeySet, 2=Dynamic, 3=Static (read-only)
    rs.CursorType = 3
    Set rs.ActiveConnection = oConn
    'Execute the query and put the results into the recordset
    rs.Open sSQL

    ' Verify record set is not null or empty
    if rs.RecordCount &lt;= 0 then
    Reporter.ReportEvent micFail,"Data NOT FOUND for SQL:",sSQL
    end if
    ' Resize the array
    ReDim DbArray(TotalRow,NumberOfColumn)

    ' Assign recordset to an Array
    Do While Not rs.eof
    For j = 0 to NumberOfColumn - 1

    'Close the Recordset
    ' Clear the connection string
    Set strConn=nothing
    ' Clear the connection to a database
    Set oConn=nothing

    End Function
    </pre><hr />
    Prashant Patel

  8. #8

    Re: Empty dynamic arrays

    Thank you.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 03:32 PM.

Copyright BetaSoft Inc.