Array question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Array question

CHARLES W SZASZ
I am working on a stack that will have a mainstack and a substack for data. The mainstack will
will have two popup buttons, representing schools. I want to set it up so that the can get the
mileage going from one school (user selects a school that he is traveling from and selects
another school that he going to) and presses the Return key or presses the default button. How
do I code an array to give the mileage between two schools? There are about 80 schools.


Charles Szasz
Lead School Psychologist and Section 504 Coordinator
Kanawha County Schools
(304) 348-7770, Ext. 347


_______________________________________________
use-revolution mailing list
[hidden email]
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Array question

Phil Davis
Hi Charles -

A simple way, yielding approximate distances:

You could first develop a grid that represents the entire geographic
area containing the schools. For simplicity, maybe each block in the
grid would represent a 1-by-1-mile area. Each school has a position
represented by a horizontal & vertical offset from some origin point -
like the topLeft of the grid, or???  When two schools are selected, you
could find the differences between their locations within the grid and
that should give you approximate mileage, but only as the crow flies.


A more complex way, yielding actual distances:

This way requires that you have real info about the distances between
all possible pairs of schools. I think you'd have about 6400 pairs, but
my math may be off. If you do have this info, your array might be
organized like so, with 1 element for each pair of schools:

- Schools are numbered 1 - 80

- Each key has 2 comma-separated parts, organized like this:
     [fromSchoolNumber,toSchoolNumber]

- The loaded 'tDistance' array would have elements that look
   something like this:
     tDistance[1,1] = 0
     tDistance[1,2] = 3.5
     tDistance[1,3] = 5.1
     ...
     tDistance[80,78] = 12.9
     tDistance[80,79] = 2.2
     tDistance[80,80] = 0

Looking up a value could then be a simple matter. If each school's
number corresponds to its line number in the popup lists, it could work
like this:
   put btn 1 into tList -- all school names
   put lineOffset(label of btn 1,tList) into tSchool1Num
   put lineOffset(label of btn 2,tList) into tSchoo21Num
   put tDistance[tSchool1Num,tSchool2Num] into fld "distance"

Hope this helps.
Phil Davis


CHARLES W SZASZ wrote:

> I am working on a stack that will have a mainstack and a substack for data. The mainstack will
> will have two popup buttons, representing schools. I want to set it up so that the can get the
> mileage going from one school (user selects a school that he is traveling from and selects
> another school that he going to) and presses the Return key or presses the default button. How
> do I code an array to give the mileage between two schools? There are about 80 schools.
>
>
> Charles Szasz
> Lead School Psychologist and Section 504 Coordinator
> Kanawha County Schools
> (304) 348-7770, Ext. 347

_______________________________________________
use-revolution mailing list
[hidden email]
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Array question

Alex Tweedly
In reply to this post by CHARLES W SZASZ
CHARLES W SZASZ wrote:

>I am working on a stack that will have a mainstack and a substack for data. The mainstack will
>will have two popup buttons, representing schools. I want to set it up so that the can get the
>mileage going from one school (user selects a school that he is traveling from and selects
>another school that he going to) and presses the Return key or presses the default button. How
>do I code an array to give the mileage between two schools? There are about 80 schools.
>  
>
Not sure if I'm answering precisely the right question here or not - but
here's a couple of answers.

I'm assuming that you will build the data from somewhere external (i.e.
you aren't trying to calculate it based on ZIP code or from an address
database). If you start with the distance info in a simple list, as in

Stanford, Harvard, 5000
Stanford, Berkeley, 50
Berkeley, Harvard, 4960
etc.


you could build an array, as in

-- for ease of use make the array twice as big as it needs to be, by
storing both Stanford,Harvard  and also  Harvard,Stanford

  -- assuming all distances are same in both directions
   repeat for each line L in distanceList
      put item 3 of L into distArray[item 1 of L, item 2 of L]
      put item 3 of L into distArray[item 2 of L, item 1 of L]
   end repeat

and the you could look up distances simply as, e.g.
    put distArray[choiceA, choiceB] into myVar

For only 6400 entries that would be fine - if you grew to storing large
number of schools, you might want to encode the names (to save space),
and you might want to store only half the array (to save space and
marginally save look-up time)
 
  -- number all the schools, and store that number in array
schoolNumber  (assumed to be done already)

  repeat for each line L in distanceList
    put schoolNumber[item 1 of L], schoolNumber[item 2 of L] into temp
    put item 3 of L into tDistance
    sort items of temp numeric
    put tDistance into distArray[temp]
 end repeat

and then look up by
  put choiceA, choiceB into temp   -- or put schoolNumber[choiceA],
schoolNumber[choiceB] into temp
  sort items of temp
  put distArray[temp] into myVar

--
Alex Tweedly       http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.7.3/15 - Release Date: 14/06/2005

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution