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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filling all elements in a row of an array

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I ought to know the answer after all these years. If I have a 2-dimensional array, can I populate all the elements of one row in a single instruction. So :

DIMENSION MyArray(100,4)
MyArray[1] = {"Prodcode", 15, "N", "Product code")
MyArray[2] = {"Desc1", 30, "Y", "Description")
. . . .

I have tried writing this type of code, but VFP accuses me of attempting to specify a date.

Most grateful. Andrew
 
There's nothing built into the language like this (other than SQL-Select), but nothing is keeping you from creating your own udf.
 
Andrew,

As Dan says, there's nothing built into the language that will do this.

The reason you get the error concerning a date was that the curly brackets you are using are used as literal date delimiters in VFP.

If you want to programmatically access the structure of a table (field names, data types, etc.), you could try using COPY STRUCTURE EXTENDED.

Alternatively, you could try something like this:

Code:
ALINES{MyArray, "Prodcode,1,N,Product code", ",")

That's not exactly what you want, but it might give you some idea about how to go about it.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
The best usage of arrays is to be created by some of the A..() functions anyway, like ALINES, ADBOBJECTS() etc, or SQL SELECT ... INTO ARRAY. But you rather work with cursors than with two dimensional arrays in foxpro.

Cursors are as fast as arrays or faster, as they also are in memory, even with a lower footprint in memory. As rows of cursors have predefined types per column the memory footprint of a cursor row is quite like a C struct, while an array allows any type in any element and so is really a variable per element.

Cursors offer processing with any commands and functions you also can use on tables, including indexing for sorting for example.

Bye, Olaf.
 
Thank you all. I had suspected that there was no facility to do multiple-assignments and you have confirmed this. I was really just trying to speed up my data entry since there are about 100 tows, but on reflection it isn't a terrible hardship.

Thanks again.
 
If you already have this in the form above, the easiest is to write it into a csv file and import into cursor, and then, if you really want, select into array.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top