Adding numbers to a field SOLVED

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Adding numbers to a field SOLVED

Post by calmrr3 » Fri Jan 16, 2015 5:21 pm

Hello,

I am trying to figure out a way of adding numbers to a field (currently I am adding the latitude to a field each time the location changes).

I want each number to be added to the field but on a new line.


Then, when I press the stop button (which stops tracking the location) I would like to be able to get the highest and lowest values.

Currently I have this script on the card which adds the latitude values to the field but they dont take a new line each time one is added:

Code: Select all

global counterVar
global allXCoords

on locationChanged pLatitude, pLongitude, pAltitude
   
   put pAltitude into field "altitude"
   put pLatitude into field "latitude"
   put pLongitude into field "longitude"
   put counterVar into field "counter"
   add 1 to counterVar
   put counterVar into field "counter"
   
   put pLatitude & comma after allXCoords
   put allXCoords into field "allX"
   
end locationChanged  pLatitude, pLongitude, pAltitude


on errorDialog pExecutionError, pParseError
   answer "An error occurred on line: " & item 2 of line 1 of pExecutionError & cr & pExecutionError
end errorDialog
Last edited by calmrr3 on Fri Jan 16, 2015 6:50 pm, edited 1 time in total.

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Adding numbers to a field

Post by dave.kilroy » Fri Jan 16, 2015 5:42 pm

Hi calmrr3

Instead of "put pLatitude into field "latitude"" try "put pLatitude & cr after field "latitude""

And in the code of your 'stop' button (or in a handler on your card that is called by the button) have something like:

Code: Select all

on findMinMax
   put fld "Latitude" into tList
   replace cr with comma in tList
   put max(tList) into tMax
   put min(tList) into tMin
   answer "Max: " & tMax & cr & "Min: " & tMin
end findMinMax
By the way the reason why I change carriage returns to commas is that the max() and min() functions expect a comma delimited list.

Dave
"...this is not the code you are looking for..."

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Adding numbers to a field

Post by calmrr3 » Fri Jan 16, 2015 5:51 pm

Excellent, works perfectly!
Thank you!

Post Reply