TCL routine to check a string and make sure they are numbers

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf TCL routine to check a string and make sure they are numbers

  • Creator
    Topic
  • #50009
    Mike Wilson
    Participant

    I am very new at using cloverleaf and TCL, But does anyone know of a way to check a segment of a message and make sure it only contains numbers?  Thanks in advance for any help.

Viewing 6 reply threads
  • Author
    Replies
    • #64480

      In what context are you working? A tps proc? Xlate?

      Basically, this can be done with a regular expression. I’m sure there are other ways to do it, too.

      Here is a sample regexp:

      Code:

      if {[regexp -all {[^0-9]} “123456z”]} {
         puts “not only digits”
      } else {
         puts “only digits”
      }

      -- Max Drown (Infor)

    • #64481
      Mike Wilson
      Participant

      It is a tps proc.  The users are required to input an account number into a field.  Then, when the messages is passed through the interface the current filter finds a field and if it meets the correct criteria it sends it on.  This is working fine, Up until now none of the lab techs have ever entered anything but the correct information into the field.  However, one of them could not read the acct# and actually put CAN’TREAD# in the field which caused major problems in the interface and the database of the receiving program.  I need to make sure this never happens again.  Thanks again.

    • #64482
      Jim Kosloskey
      Participant

      Mike,

      As Max indicated, there is another way to do this.

      You could use the string is class Tcl command.

      Something like string is digit or string is alpha .

      Jim Kosloskey

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

    • #64483
      Amol Kulkarni
      Participant

      Mike,

      Perhaps this might be useful:

      proc check_Alpha {} {

       upvar xlateId       xlateId        

             xlateInList   xlateInList    

             xlateInTypes  xlateInTypes  

             xlateInVals   xlateInVals    

             xlateOutList  xlateOutList  

             xlateOutTypes xlateOutTypes  

             xlateOutVals  xlateOutVals  

         set code  [lindex $xlateInVals 0]

         set suppmsg “transaction suppressed, value is alpha”

                echo >$code<    if {[ctype alpha $code]} {            set xlateOutVals [lindex $xlateInVals 0]    } else {            set xlateOutVals $suppmsg    }            return $xlateOutVals }

    • #64484
      Jim Kosloskey
      Participant

      Amol,

      I have tried to phase out the use of the old extended Tcl c commands (ctype, etc.) in favor of the native and enhanced string command.

      Charlie Bursell has indicated the use of string is more beneficial.

      Jim Kosloskey

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

    • #64485
      Amol Kulkarni
      Participant

      Jim,

      I am an old person  ðŸ™‚ (actually in the old dog catagory); but yes you are correct i should be changing these old tcls as i come across them.

      🙂 Amol

    • #64486
      Charlie Bursell
      Participant

      Boy ask you guys how to start a car and you tell me how to build an engine  ðŸ˜€

      As Jim said, the string commands are the most ergonomic.  Why would you want to write a proc to do something that could be done with a single core level command?

             string is digit $var

      returns 1(true) if all digits  else returns 0 (false).  Use this way the empty string would always be true.  If you want the emty string to return false:

             

             string is digit -strict $var

Viewing 6 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,296
Replies
34,439
Topic Tags
287
Empty Topic Tags
10