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

access columns via index

Status
Not open for further replies.

MrDontKnowNothing

Programmer
Jun 26, 2003
94
0
0
DE
hello everybody,

i'd like to scan a table. but instead of using the column-names to access the fields, i'd rather want to use indices, just like acessing an array.
but i don't want to copy the table into a array.

i appreciate any ideas...

cheers

alex
 
I'm not sure exactly what you mean, but you can use KEY() and TAG() to figure out stuff about the indexes of the currently selected table, if your meaning was to do this kind of dynamically. Could you explain a little more about what you are trying to do, or give some psuedo-code?

Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
sorry! actually i do have 2 problems...

1.)
usually, you acces a field via name e.g.:
select name, street from friends

but asume, that "name" is the 1st column and "street" is the 3rd column. now, i wanna do something like this:
select friends(1).value, friends(3).value from friends

2.)
when importing an excelfile, how can i make the first row to field-names?

muchas gracias

alex







 
not as nice as i want it, but it will work.

it seems, that in vp7 accesing fields is done usually over the names, doesn't it?

anyway, thanks a lot for your help!

cheers

alex
 
MrDontKnowNothing,

In addition to what Mike said, check out the AFIELDS()

Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
HI

You have not phrased the question properly.

but asume, that "name" is the 1st column and "street" is the 3rd column. now, i wanna do something like this:
select friends(1).value, friends(3).value from friends


There has to be column2 with something and may be you have not said about that.

You can always get as given below..

USE myTable

aa = FIELD(1)
bb = FIELD(3)

SELECT &aa, &bb FROM DATA\myTable


SELECT EVAL(FIELD(1)), EVAL(Field(2)) FROM ...
will work, but the field size truncations will take place based on the first record selected.

:)



____________________________________________
ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
well, the afields() would be approbriate, but i don't think it would be a good idea to put a lot of data into a array... (eats up memory, doesn't it?)

ramanis version is, what i actually wanted, but is there a way to do it inline? i have tried:

scan
if &field(1) = "" then
wait window 'hello'
endif
endscan

but it didn't work at all. i got the message: missing operand

gracias

alex

 
sorry, this was corresponding to the suggestion with AFIELDS().

probably gonna start my weekend and check out things on monday ;-)

cheers alex
 
Alex,

Another thing to keep in mind: If you rely on field numbers rather than field names, you could run into problems if you ever change the structure of the table. In general, the order of the fields within the structure is not significant. By relying on the field numbers, you are introducing a dependency that would not otherwise be there.

Mike


Mike Lewis
Edinburgh, Scotland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top