Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Arrays
Message
General information
Forum:
Visual FoxPro
Category:
FoxPro 2.x
Title:
Re: Arrays
Miscellaneous
Thread ID:
00519656
Message ID:
00519740
Views:
19
Peter,

By "how would I write the array", I'm assuming you mean "how would I place the numeric values in the first array".

Here's how I'd take care of the whole task, assuming the above:
*-- Define private variables
PRIVATE pnLoop, ;
        pnMaxVal, ;
        pnTotVal, ;
        plNumMatch

pnLoop     = 0
pnMaxVal   = 0
pnTotVal   = 0
plNumMatch = .f.

*-- Declare the arrays
DECLARE ArrNums[ 4, 4 ]
DECLARE ArrRslt[ 4, 3 ]

*-- Assign the numeric values to the ArrNums array
ArrNums[ 1, 1 ] = 30
ArrNums[ 1, 2 ] = 30
ArrNums[ 2, 1 ] = 40
*-- and so forth, until all 16 are assigned

*-- Scan the ArrNums array
FOR pnLoop = 1 TO ALEN( ArrNums, 1 )
  *-- Check for similarity between items
  *-- NOTE: YES, there is a better way to do this,
  *--       but this is simpler to cut and paste (BG)
  IF ArrNums[ pnLoop, 1 ] = ArrNums[ pnLoop, 2 ] OR ;
     ArrNums[ pnLoop, 1 ] = ArrNums[ pnLoop, 3 ] OR ;
     ArrNums[ pnLoop, 1 ] = ArrNums[ pnLoop, 4 ] OR ;
     ArrNums[ pnLoop, 2 ] = ArrNums[ pnLoop, 3 ] OR ;
     ArrNums[ pnLoop, 2 ] = ArrNums[ pnLoop, 4 ] OR ;
     ArrNums[ pnLoop, 3 ] = ArrNums[ pnLoop, 4 ]

    plNumMatch = .T.

  ENDIF && Check values of ArrNums

  *-- Determine the maximum value
  pnMaxVal = MAX( ArrNums[ pnLoop, 1 ], ;
                  ArrNums[ pnLoop, 2 ], ;
                  ArrNums[ pnLoop, 3 ], ;
                  ArrNums[ pnLoop, 4 ]  ;
                  ) 

  *-- Total the items
  pnTotVal = ArrNums[ pnLoop, 1 ] + ;
             ArrNums[ pnLoop, 2 ] + ;
             ArrNums[ pnLoop, 3 ] + ;
             ArrNums[ pnLoop, 4 ]

  *-- Write the values to the ArrRslt array
  ArrRslt[ pnLoop, 1 ] = plNumMatch
  ArrRslt[ pnLoop, 2 ] = pnMaxVal
  ArrRslt[ pnLoop, 3 ] = pnTotVal

  *-- Reset the private variables
  *-- to their default values
  plNumMatch = .f.
  pnMaxVal   = 0
  pnTotVal   = 0

NEXT && pnLoop

*-- The ArrRslt array now holds the values you desire
*-- and you can check them/report on them however you want

*** YOUR CODE GOES HERE ***

*-- Clean up and return
*-- NOTE: All array values will *DISAPPEAR*
*-- when you RETURN unless:
*-- 1) you store them
*-- 2) you pass them back to the calling module
*-- 3) you DECLARE the arrays -before- you call this module
RETURN
I'm certain that, after seeing this code, you can easily write the code you desire for the area marked *** YOUR CODE GOES HERE *** to further use the values you want.

>HOW WOULD I WRITE THE ARRAY.. I AM NOT VERY GGOD AT ARRAYS...
Evan Pauley, MCP
Positronic Technology Systems LLC
Knoxville, TN

If a vegetarian eats vegetables, what does a humanitarian eat?
Previous
Reply
Map
View

Click here to load this message in the networking platform