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

Varible for element number in an array

Status
Not open for further replies.

blumash

Programmer
Oct 2, 2003
50
HU
I have a array with 20 elemnts , each time I have to store a field to another element " store tran to saltot(x) " , saltot is the array and X is the number of elemnt , how can I use the same command all the time with a varibale that is changing???

Thank's
 
I'm not exactly clear on what you are saying, but there are several different ways to use variables:
Code:
FOR nCounter = 1 TO 20
   saltot[nCounter] = tran
NEXT
Will result in all 20 elements having the value of 'tran' in them

If 'tran' is a table field:
Code:
STORE 0 TO nCounter
SCAN 
   nCounter = nCounter + 1
   saltot[nCounter] = tran
   IF nCounter = 20
      EXIT
   ENDIF
ENDSCAN

-Dave Summers-
[cheers]
Even more Fox stuff at:
 
I understand you need macro substitution "&". What are the names of your fields? If they were like tran1, tran2, tran3 and so on, you could use:

For x=1 to 20
store tran&x to saltot(x)
Endfor
 
Thank's TheRembler , saltot is a array with 200 element in it , the problem is that evry time I have to store a field called "tran" to element number x in the array , for example
"store tran to saltot(1)" , next time in the program I have to store the same field to element 2 in the same array
"store tran to saltot(2)" , the number is changing & instead of the numbers I need to put a varibale that I change manualy in the program.

Thank's
 
Hi,

Then Dave understood your problem better than me and gave you good examples. I would only add that you could use 'x' as your variable, like:

x = 1
store tran to saltot(x)

next time, you can change the value of x, let's say:

x = 2
store tran to saltot(x)
 
Thank's , I solved it & now it's working , there was a stupid thing there , when I wrote "store tran to saltot[x]" it gave an program error massage , then I wrote "saltot[x]=tran" this was ok , I don't understand what's the different & why the first command was an error but doesn't matter the second command is doing the same without a program error.

Thank's
 
What was the error number and/or error description you got? I tried your original method in both FPW 2.6 and VFP 6.0 without errors.

Code:
DECLARE saltot[200]
x=2
tran=55
STORE tran TO saltot[x]
? saltot[x]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top