Ubound does not work (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 14:14
Joined
Sep 21, 2011
Messages
14,269
I may have misunderstood something. +1? In reference to what?
In response to that link I posted. It was almost as you offered, but with +1 added
 

ADIGA88

Member
Local time
Today, 16:14
Joined
Apr 5, 2020
Messages
94
As The_Doc_Man Said you should use Ubound(HLforInvoice,2)

Your SQL "SELECT HorseID FROM tbHorse WHERE Mark=-1;" will return an array a(0, n) 0 because there is one field in the recordset n is the number row in the recordset.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:14
Joined
Feb 28, 2001
Messages
27,172
In response to that link I posted. It was almost as you offered, but with +1 added

No, I didn't miss that point and didn't intend to modify the answer. The point is, why would the OP get 0? And the answer is because he might have been querying the wrong subscript in a two-subscript array. The "+1" would hide the zero and thus gloss over the point being suggested.
 

ADIGA88

Member
Local time
Today, 16:14
Joined
Apr 5, 2020
Messages
94
No, I didn't miss that point and didn't intend to modify the answer. The point is, why would the OP get 0? And the answer is because he might have been querying the wrong subscript in a two-subscript array. The "+1" would hide the zero and thus gloss over the point being suggested.
I think it's normal to get 0 because the first dimension of the array contains the fields of the recordset and in his query only one field retrieved the subscript is 0 (zero-based), if there are two fields the Ubound will return 1.
 

Auntiejack56

Registered User.
Local time
Today, 23:14
Joined
Aug 7, 2017
Messages
175
Yep, you have a two dim array created from "SELECT HorseID FROM tbHorse WHERE ... " etc
So the array has:
dimension 1=Fields (there is 1 field, HorseID, so the ubound for that dimension is 0)
dimension 2=Rows (there are .recordcount rows, so the ubound for that dimension is recordcount - 1)

The upper bound for dimension 1 is Ubound(arrayname, 1) or just Ubound(arrayname)
The upper bound for dimension 2 is Ubound(arrayname, 2)

So you have no problem, just do what Docman said and check the second dimension instead of the first.

Jack
 

Users who are viewing this thread

Top Bottom