Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to gather a whole record information in a var or array 1

Status
Not open for further replies.

allright

Technical User
Feb 4, 2005
3
US
Hi all,
Can anyone advise how to gather information form a record, i'm looking for the equivalent to the function gather in VFoxpro, so if the table has 50 records i do not have to assign the value to 50 vars, but assign in one shot.

any help is appreciated.

Thx
 
What is the purpose of the VFoxpro gather function ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Not famaliar with VFoxPro, at all. But, may have understood your question....

DAO, or ADO "GetRows" function, will allow you to asign as many records & columns, as you like, to one "2 dimensional" variable.

Here's ADO...
Code:
Dim rec As New ADODB.Recordset, vArray As Variant, x As Integer, y As Integer
    
rec.Open "tblCountries", CurrentProject.Connection, adOpenDynamic, adLockPessimistic

'rec.MoveLast: rec.MoveFirst  'get recordcount

vArray = rec.GetRows(, , Array("txtCountry", "txtCapital", "txtPopulation"))'asked for 3 columns

For x = 0 To UBound(vArray, 2)'loop through records
   For y = 0 To 2             'loop thru columns
   Debug.Print vArray(y, x)
   Next y
Next x
rec.Close: Set rec = Nothing

hope I caught your drift?
 
What is the purpose of the VFoxpro gather function ?

Scatter and Gather are a matched pair of data transfer commands. Scatter takes the data from a record and puts it into memory variables, an object, or an array. Gather does the opposite.

Note that a Fox array allows every element to be of a different type (more of a structure than an array) so the elements of a single array can hold numbers, text, date, booleans and objects.

Geoff Franklin
 
Thank-you Geoff, that was well put.
It appears then that, GetRows(), may be the VBA equivalent.
(VBA arrays, as you implied though, must keep the same data types, in all the elements)
Just to elaborate, on what might be a somewhat unclear example that I gave.

In ADO, the first argument is the number of rows required (default is all.
2nd is starting position, default is 1st.
3rd argument is number of columns.

You could syntax it like this..

vArray = rec.GetRows(100,,3)'1st hundred records, 1st FOUR columns (zero based)

I believe DAO is
vArray = rec.GetRows(3,100) 'reversed, with no start argument.

...and there is also the GetString() function, which returns a tab delimited(rows), comma delimited(fields) STRING, of the requested recordset.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top