1 Reply Latest reply on Oct 7, 2012 3:36 PM by philmodjunk

    Variables evaluate as text rather than numbers

    Malcolm

      Summary

      Variables evaluate as text rather than numbers

      Product

      FileMaker Pro

      Version

      Advanced 12.0v2

      Operating system version

      Mac OS X 10.6.8

      Description of the issue

      Single dollar variables which have been assigned numerical values are being evaluated as text rather than as number.

      Steps to reproduce the problem

      Note that I cannot reproduce the problem in the data viewer. If I could the simplest expression would be:

      Set $x to 150
      set $y to 65
      ( $x < $y ) = 0

      In fact, I have a script which has nested loops. The value of $x is set outside the loops. The value of $y is set inside the loops. I have an exit loop step which uses ($x < $y). On the second run through the loop the test on line 37 below fails.

      Script Name: Generate Wave ( Project, Wave, Size )
      #MF July 2012
      #Waves are selected from Statistical Local Areas (SLA). We begin at SLA level 2. If there are insufficient numbers we proceed to SLA3 then SLA4. Statistical Local Area: Level 4: first three digits. Level 3: L4 + 2 digits. Level 2: L3 + 4 digits. Level 1: L2 + 2 digits
      #Select a specified number of records at random within randomly selected SLAs
      Set Error Capture [ On ]
      Set Variable [ $Project; Value:SP(1) ]
      Set Variable [ $Wave; Value:SP(2) ]
      Set Variable [ $WaveSize; Value:SP(3) ]
      Set Variable [ $FoundSet; Value:0 ]
      #
      If [ IsEmpty( $Project ) ]
      Show Custom Dialog [ Message: "Project ID is unspecified. We cannot proceed"; Default Button: “OK”, Commit: “No” ]
      Exit Script [ ]
      End If
      If [ IsEmpty( $Wave ) ]
      Go to Object [ Object Name: "wavename" ]
      Show Custom Dialog [ Title: "Exit Script"; Message: "The script cannot proceed without a wave name/number"; Default Button: “OK”, Commit: “No” ]
      Exit Script [ ]
      End If
      If [ IsEmpty( $WaveSize ) ]
      Go to Object [ Object Name: "wavesize" ]
      Show Custom Dialog [ Title: "Exit Script"; Message: "The script cannot proceed without a wave size"; Default Button: “OK”, Commit: “No” ]
      Exit Script [ ]
      End If
      # #
      Go to Layout [ “ContactAddrSLA Global” (ContactAddrSLA_gbl) ]
      Show All Records
      If [ myTeam = "teamPoint" ]
      #POINT have already used NSW and TAS
      Constrain Found Set [ Specified Find Requests: Omit Records; Criteria: ContactAddrSLA_gbl::Postcode: “7*” Omit Records; Criteria: ContactAddrSLA_gbl::Postcode: “2*” ] [ Restore ]
      End If
      #
      Loop
      #
      #the aggregation loop - SLA sizes are typically too small, so we need several
      #
      Exit Loop If [ $FoundSet ≥ $WaveSize ] <--- <--- <--- <--- <--- <--- <--- <--- <--- <--- <--- <--- <--- <--- <--- <--- <--- <--- <--- <--- problem occurs on the second loop
      #
      #The basic procedure is to locate a population using SLA chosen at random
      #
      Set Variable [ $j; Value:0 ]
      Go to Layout [ “ContactAddrSLA Global” (ContactAddrSLA_gbl) ]
      If [ Let($aggregator = $aggregator +1; $aggregator > 1 ) ]
      Omit Record
      Exit Loop If [ Get(FoundCount) < 1 ]
      End If
      Go to Record/Request/Page [ Random * Get(FoundCount) ][ No dialog ]
      #
      Loop
      Set Field [ ContactAddrSLA_gbl::gbl_SLA; Left ( ContactAddrSLA_gbl::SLA_L2; Length( ContactAddrSLA_gbl::SLA_L2) - $j ) ]
      Commit Records/Requests[ Skip data entry validation; No dialog ]
      Set Variable [ $j; Value:$j + 1 ]
      #
      Set Variable [ $groupSize; Value:Count(ContactAddr::AddressID_kprime) ] Set Variable [ $prevHits; Value:Count(ContactWaveParty::__id_kf Contact) ]
      Exit Loop If [ ($WaveSize - $FoundSet) ≤ ($groupSize - $prevHits) ]
      Exit Loop If [ Length(ContactAddrSLA_gbl::gbl_SLA) < 4 // SLA Level 4 is three digits, so when we get to that point, drop out and accept the numbers ]
      #
      #
      End Loop
      #
      Go to Related Record [ From table: “Contact”; Using layout: “Contacts List” (Contact) ] [ Show only related records ]
      Constrain Found Set [ Specified Find Requests: Omit Records; Criteria: ContactWaveParty::__id_kf Contact: “*” ] [ Restore ]
      Set Variable [ $foundcount; Value:Get(FoundCount) ]
      #
      If [ ( $WaveSize - $FoundSet) < $FoundCount ]
      #randomise the found set
      Set Variable [ $i; Value:0 ]
      Set Variable [ $n; Value:$FoundCount - ($WaveSize - $FoundSet) ]
      Set Variable [ $d; Value:Get(CurrentDate) ]
      Loop
      Exit Loop If [ Let( $i = $i + 1 ; $i > $n ) ]
      Go to Record/Request/Page [ Round ( Get(FoundCount) * Random ; 0) ][ No dialog ]
      Omit Record
      End Loop
      End If
      #
      Go to Record/Request/Page [ First ]
      Loop
      Set Field [ ContactWaveParty::__id_kf Project; $Project ]
      Set Field [ ContactWaveParty::Wave Number; $wave ]
      Go to Record/Request/Page
      [ Next; Exit after last ]
      End Loop
      Set Variable [ $FoundSet; Value:$FoundSet + Get(FoundCount) ]
      End Loop
      #
      Go to Layout [ original layout ]
      Show Custom Dialog [ Title: "Randomised Selection Complete"; Message: $WaveSize & " records have been selected and marked as Wave # " & $Wave; Default Button: “OK”, Commit: “Yes” ]

      Expected result

      I expect the variables to recognise that the values on both sides of the equation are both numbers and that the evaluation should occur in a numerical context.

      Actual result

      65 is greater than 150

      Workaround

      getasnumber( $var ) fixes the problem

        • 1. Re: Variables evaluate as text rather than numbers
          philmodjunk

               Testing this with the simplest script example that you post in Windows 7 with FMP 12.02, I cannot reproduce this.

               Set Variable [ $x; Value:150 ]
               Set Variable [ $y; Value:2 ]
               If [ $x > $y ]
                      Show Custom Dialog [ Message: $x & ">" & $y; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]
               Else
                      Show Custom Dialog [ Message: "Not" & $x & ">" & $y; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]
               End If

               Results in the custom message 150 > 2 being displayed.

               However, because you cannot explicitly declare a variable's data type like you can a database table, it is very easy to end up with a numerical value stored (and thus evaluated) in text format. This issue may also be one that occurs only on a given platform.