Array question

Phil Davis davis.phil at comcast.net
Wed Jun 15 02:08:15 EDT 2005


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



More information about the use-livecode mailing list