> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Dion Nicholas
> Sent: 20. kesakuuta 2001 17:35
> To: [EMAIL PROTECTED]
> Subject: RE: <lingo-l> Random Operators >Pekka<
>
>
> At 15:25 20/06/01 +0300, you wrote:
>
> Thanks Pekka, that's exactly what I was trying to achieve.
> I have some questions about this script:
>
> >on randomcalculation
> > Operatorlist = ["+", "-", "*", "/"]
> > commandString = "put"
> > repeat with a = 1 to 4
> > commandString = commandString&&(random(10))&".0"
> > commandString = commandString&&Operatorlist[random(4)]
> > end repeat
> > commandString = commandString&&(random(10))&".0"
>
> >> Why do we repeat the line above?
Well, we could naturally Type it out, but incase you want to be able to do
more calculus operations in a random sequence than 3 then this starts paying
off.
Basically, what I'm saying is that if we want to
DoNumber
DoOperation
DoNumber
DoOperation
DoNumber
.
.
.
DoOperation
DoNumber
DoOperation
DoNumber
DoCalculate
then IMHO the simplest way is
repeat with amount of numbers - 1
DoNumber
DoOperation
end repeat
DoNumber
DoCalculate
You could also do:
commandString =
"put"&&(random(10))&".0"&&Operatorlist[random(4)]&&(random(10))&".0"&&Operat
orlist[random(4)]&&(random(10))&".0" etc...
>
> > put commandString
> > do commandString
>
> >> How do I get the result into my text field? I can get the sum into
> >> a text field but not the result?
Well, basically the "do" command executes a srtring as if it was lingo
in this case, it infact evaluates the string
put 6.0 * 3.0 + 4.0 - 7.0 / 3.0 as a line of lingo
as I start the commandstring with
commandString = "put"
I could also make it:
commandString = "variableName = "
In which case the result of the calculation would be stored in variableName,
for latter use
Let's say, you would like it to print the result into a text/field member by
the name of CalcResult, you should modify the script (oops i think I just
did it for you) into :
on RandomCalc
Operatorlist = ["+", "-", "*", "/"]
XXX = 0
commandString = "XXX = "
repeat with a = 1 to 4
commandString = commandString&&(random(10))&".0"
commandString = commandString&&Operatorlist[random(4)]
end repeat
commandString = commandString&&(random(10))&".0"
do commandString
member("calcResult").text = string(XXX)
end
Note that before i set 'commandstring = "XXX = "' i also set XXX to a bogus
value, so that the compiler would not whine about it. Also note that to
print the result of the calculation (a floating point value), i first need
to convert it into a string by 'string(XXX)'...
The math operations are done as floating point values (&".0"), so that the
result would be accurate.
HTH
Pekka
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]