Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Arrays
Message
From
15/06/2001 10:19:21
David Fluker
NGIT - Centers For Disease Control
Decatur, Georgia, United States
 
General information
Forum:
Visual FoxPro
Category:
FoxPro 2.x
Title:
Re: Arrays
Miscellaneous
Thread ID:
00519819
Message ID:
00519936
Views:
16
Peter,

A FoxPro 2.6 array can be one dimensional-like a list, or two dimensional-like a grid. Youi reference the items by using the variable name and an index number. The first item in a FoxPro array is number 1, the next is number 2, etc. The syntax is
arVariable[#] ot arVariable(#)
You may use either brackets or parentheses. I'll use brackets in this post.
You want an array of four numbers. This sounds like a list, so to create an array called arNumbers use
DIMENSION arNumbers[4]
I'll follow your requirements as best I can using the first line of your sample numbers.
>1. read in 4 numbers x1,x2x3,x4, sum the numbers, see if numbers equal 100 print x1,x2,x3,x4 else if not error trap
>30,30,23,12 - 2 same
arNumbers[1] = 30
arNumbers[1] = 30
arNumbers[1] = 23
arNumbers[1] = 12

*: Sum the numbers - Is it equal to 100?
nTot = arNumbers[1] + arNumbers[2] + arNumbers[3] + arNumbers[1]
If nTot = 100 
   ?  arNumbers[1], arNumbers[2], arNumbers[3], arNumbers[1]
Endif
or you could put it in a loop - ALEN(arrayname) gives you the number of elements in an array
nTot = 0
For nCntr = 1 TO ALEN(arNumbers)
  nTot = nTot + arNumbers[nCntr]
Next
If nTot = 100 
   ?  arNumbers[1], arNumbers[2], arNumbers[3], arNumbers[1]
Endif
>2. see if one of xi = 100 and all remaining will = 0 print x1,x2,x3,x4, if not go to step 3
You haven't defined xi, but I'll assume it's the items in the array.
IF (arNumbers[1]=100 AND arNumber[2]=0 AND arNumber[3]=0 AND arNumber[4]=0) 
OR  (arNumbers[1]=0 AND arNumber[2]=100 AND arNumber[3]=0 AND arNumber[4]=0)
OR (arNumbers[1]=0 AND arNumber[2]=0 AND arNumber[3]=100 AND arNumber[4]=0)
OR (arNumbers[1]=0 AND arNumber[2]=0 AND arNumber[3]=0 AND arNumber[4]=100)
THEN
   ?  arNumbers[1], arNumbers[2], arNumbers[3], arNumbers[1]
Endif
I'm sorry, I have to leave - I hope Ive given you enough to get your program working.
David.
Previous
Reply
Map
View

Click here to load this message in the networking platform