continue through loop

Clovertech Forums Read Only Archives Cloverleaf Tcl Library continue through loop

  • Creator
    Topic
  • #51165
    Kevin Crist
    Participant

      we have a tclproc that goes through all the dr fields and pads with 0’s up to 5 long. So if  a number is 123 it makes it 00123. Apparently in the dr fields they can have “” in the field and the proc just puts 000″” but apparently this messes up the document in the application. How would i put in the change that if that field is “” then just leave it or else change it. I have messed around with regexp, continue, break and a few others trying to get it going. Any tips on how to do this.

      proc FormatDrNum { DrFldList subSep } {

      set i 0

      foreach Dr $DrFldList {

      set subfldList [split $Dr $subSep]

      lset subfldList 0 [format “%05s” [lindex $subfldList 0]]

       lset DrFldList $i [join $subfldList $subSep]

      incr i

      }

      return $DrFldList

      }

    Viewing 7 reply threads
    • Author
      Replies
      • #69001
        Jim Kosloskey
        Participant

          Kevin,

          Maybe something like this:

          proc FormatDrNum { DrFldList subSep } {

          set i 0

          foreach Dr $DrFldList {

             set subfldList [split $Dr $subSep]

             if {[string equal [lindex $subfldList 0] “”]} {

                 break

             }

             lset subfldList 0 [format “%05s” [lindex $subfldList 0]]

             lset DrFldList $i [join $subfldList $subSep]

             incr i

          }

          return $DrFldList

          }

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

        • #69002
          Kevin Crist
          Participant

            thanks Jim, but i am getting an error now, i will post the whole proc. From what i am understanding is that if i do a break then it will jump completely out of the loop, is that true? If so that is not what i want. Since this checks all possible dr fields in hl7.

            Thanks

            0:TEST] Tcl error:

            msgId = message0

            proc = ‘tpsSoft_DrNum_In’

            args = ”

            result = ‘wrong # args: should be “string equal ?-nocase? ?-length int? string1 string2″‘

            errorInfo: ‘

            wrong # args: should be “string equal ?-nocase? ?-length int? string1 string2”

               while executing

            “string equal [lindex $subfldList 0]”””

               (procedure “FormatDrNum” line 5)

               invoked from within

            “FormatDrNum $repList $subSep”

               (“PV1” arm line 16)

               invoked from within

            “switch -exact [lindex $fldList 0] {

            PD1 {

            if { [llength $fldList] >= [expr $PrimaryPos + 1] } {

            ;# 1) Get …”

               (“foreach” body line 16)

               invoked from within

            “foreach segPos $PosList { ;# For Each Seg in List

            if { $segPos > 0 } { ;# If the Segment was found

            ;# Spli…”

               (“run” arm line 25)

               invoked from within

            “switch -exact — $mode {

              start { }

               run {

                set mh [keylget args MSGID] ;# Get message handle from args

               set dispList [list “CON…”

               (procedure “tpsSoft_DrNum_In” line 52)

               invoked from within

            “tpsSoft_DrNum_In {MSGID message0} {CONTEXT sms_ib_data} {ARGS {}} {MODE run} {VERSION 3.0}”‘

          • #69003

            foreach line $var {
            [code]foreach line $var {

            -- Max Drown (Infor)

          • #69004
            Charlie Bursell
            Participant

              In Jim’s proc make sure there is a space between [lindex $subfldList 0] and “”.

              Change break to continue and it should work.

              FTI.  Instead of  if {[string equal [lindex $subfldList 0] “”]} {

              You could use (Less typing)

              if {[lindex $subfldList 0]  eq “”} {

              Max:

              Do you use regexp and regsub for *EVERY* thing  ðŸ˜†

            • #69005
              Kevin Crist
              Participant

                thanks all for your insights and knowledge. I was able to get this working correctly.

              • #69006

                Charlie Bursell wrote:

                Max:

                Do you use regexp and regsub for *EVERY* thing

                -- Max Drown (Infor)

              • #69007
                Charlie Bursell
                Participant

                  Don’t take it pesonal Max, I was kidding with you  ðŸ˜€

                  Like most programming it is mostly a matter of personal preference.

                  There are only two people that write good code, me and you and sometimes i wonder about you!   😉

                • #69008

                  😀

                  -- Max Drown (Infor)

              Viewing 7 reply threads
              • The forum ‘Tcl Library’ is closed to new topics and replies.