StephenWonfor

When 6 > 13.  Fishing for data in a simple array.

Discussion created by StephenWonfor on Dec 14, 2015
Latest reply on Dec 29, 2015 by martinsorich

Hi

 

Posting this as a cautionary tale (most likely to myself and possibly not for this first time).   I get caught out by this far too often.
I realize that the default data type for a variable is text unless Draco observes it could be a number, in which case it is treated as  number.
Where I stumble is pulling a "number" out of a variable stack (the stacking quite reasonably makes the data type text) and expecting it to be a number.


#$$Stack simulates data gathering from 4 different records
Set Variable [ $$Stack; Value:"3¶17¶24¶13" ]
Set Variable [ $Test; Value:6 ]
Set Variable [ $Count; Value:1 ]
#
Set Variable [ $Loops; Value:ValueCount($$Stack) ]
Loop
  Set Variable [ $RowTest; Value:Case( $Test > GetValue($$Stack;$Count); $Test & " is apparently greater than " & GetValue($ $Stack;$Count);"Nothing") ]
  Show Custom Dialog [ Message: $RowTest; Buttons: “Oh!” ]
  Set Variable [ $Count; Value:1 + $Count ]
  Exit Loop If [ $Count > $Loops ]
End Loop
#


thus 6 > 3 which is correct and 6 > 13 which is wrong (except for very small values of 13)

 

Case( $Test > GetAsNumber(GetValue($$Stack;$Count) solves this problem.  I am told this is known as "casting" - will work on remembering this fact.

 

ps.  it is reasonable to call the data result of "3¶17¶24¶13" an "array"?


 

Stephen

 

--

 

"No good movie is too long and no bad movie is short enough." -- Roger Ebert

Outcomes