check field for numeric value

Clovertech Forums Cloverleaf check field for numeric value

  • Creator
    Topic
  • #120383
    JD
    Participant

      Hello – I’m checking a field for numeric value. If the field is numeric (integer or double) then I need to clear another field in the hl7 message.

      The inline code is fine up to the point where I try to assign the outcome of the check of the numeric value.   The outcome of the check (0 or 1) is not passed to $xlateOutVals. What am I doing wrong? Is there a better way to check the field for a numeric value?

      Inline code below with debug and all, and some comments. Testing with numeric field = 111.111

      set out $xlateInVals // out is 111.111
      #set out [string is integer -strict $xlateInVals]
      #echo WHAT IS OUT ****** $out
      if {[string is double -strict $out]} { /// return 1 if numeric
      echo OUT is numeric $out // prints 1
      set out “1” // explicitely setting out
      echo NEW OUT is numeric $out // prints 1
      set $xlateOutVals $out // keeps what is in $xlateInValues
      echo NEW XOUTVALS $xlateOutVals // prints 111.111
      } else {
      echo OUT is NOT numeric $out
      set out “0”
      echo NEW OUT is NOT numeric $out
      set $xlateOutVals $out
      }
      #set $xlateOutVals $out

      Thank you in advance.

    Viewing 1 reply thread
    • Author
      Replies
      • #120384
        Jim Kosloskey
        Participant

          First, xlateInxxx and xlateOutxxx are lists and should be treated as such using list commands to reference.

          Mostly, though – I think, is this command:

          set $xlateOutVals $out

          should be set xlateOutVals $out (no $ in front of xlateOutVals), But using a list command like lreplace would be better.

           

           

          email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

          • #120385
            JD
            Participant

              Hello – thank you!  Removing the $ from xlateOut* did it.   Point about lists and lreplace noted.  JD

          • #120386
            Charlie Bursell
            Participant

              Just a point.  You can tighten up your code quite a bit.

              An integer can qualify as a double but not vice versa.  So:

              set xlateOutVals  [ list [string is double -strict [lindex $xlateInVals 0]]]

               

          Viewing 1 reply thread
          • You must be logged in to reply to this topic.