views:

194

answers:

2

Using Sax ActiveX Scripting (long story), I have 3 nested if statements which reuse the same return variable. Script looks roughly like:

Dim rtnArray As Variant
If variable1 <> "" Then
    ' Perform SQL query against DB2 database
    rtnArray = DB2SQLSearch(Query)
    If UBound(rtnArray) = 0 Then
        ' ditto
        rtnArray = DB2SQLSearch(Query2)
        MsgBox "Gets this far"
        If UBound(rtnArray) = 0 Then ' Error!
            ' Never make it here

What's odd is that this same code structure is working in a script I wrote last week; I simply changed a couple of the queries and the name of the function (find > replace).

After the 2nd query, I've tried a MsgBox CStr(rtnArray(0)(0)) but it yields Error 10025 in : Array has a different number of indexes.

Error codes correspond to the following manual:
http://www.ftgsoftware.com/manuals/basic32.pdf

A: 

You can either store it in another variable, or ReDim the rtnArray variable to havve the proper size. In order to Redim, you need to know the size.

Cheeso
Unfortunately, it's for query results; I don't know how large it'll be, so I don't know that ReDim will work.In the course of debugging I've tried creating a second array variable just for that inner query, but I get the same errors.
hewhocutsdown
A: 

Figured it out.

In this particular case, the user that I was connecting as had authorization to the first table, but not the second.

This did not throw an error, but there is a message I can check to see whether there was a success or not, so I can look for that and throw my own error, instead of passing back a null array. (it's not a proper Null, frankly I'm still not 100% sure what it is, aside from a Variant. But it sure doesn't like UBound()!

hewhocutsdown
FYI: In normal VBScript, UBound fails on empty arrays that are declared as `Dim arr()` (see http://en.wiki.mcneel.com/default.aspx/McNeel/RsEmptyArray). Maybe this is the case.
Helen
I declared mine as a Variant; see the code above.Interesting article; I'll have to play around with it and see how much of it holds true for Sax.
hewhocutsdown