Iteration in TCL HELP!

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Iteration in TCL HELP!

  • Creator
    Topic
  • #49859
    Gena Gill
    Participant

    Using TCL, I need to compare OBX 3 subfield 0 and OBX 5, and if OBX 3(0) equals FLUIDML, and OBX 5 equals 0, then I need to change the value of OBX 3(0), to FLUIDMLNO.

    I have other conditions in a complex translation that use these values, so changing this in the preproc is the easiest.

    My biggest problems seems to be that I can’t get beyond reading the first iteration of the OBX segment.  No errors are being returned when I watch the output, and what’s Echoing back is always just the first iteration.  

    I’m attaching the TCL that I’m trying to use.  Any assistance would be greatly appreciated!

Viewing 4 reply threads
  • Author
    Replies
    • #63898
      Tom Rioux
      Participant

      You obviously have the message already broken down into segments and have set it to the variable “$segments”.  The problem with the lsearch is that it will go out and find the first occurance of the OBX and ignore any others.  You have already found this out.  My suggestion is to loop through the $segments variable with a foreach such as:

      foreach seg $segment

      Then, using an IF statement or a switch statement, go out and find your OBX segments.  Then perform the necessary functions to grab the fields you need within the OBX.  

      I’m sure Charlie or Jim may have a more efficient way of doing this but you could start with this.  Let us know if you need anything assistance.

      Hope this helps….

      Tom Rioux

      Baylor Health Care

    • #63899
      Gena Gill
      Participant

      OK, moving the foreach above where I’m setting the OBX 3 and 5 values worked.  I’m not getting the echo that I expect on one of the values, so I’ll need to work on that.

      Thanks for your help!

    • #63900
      John Hamilton
      Participant

      You may also need to add the -all to the lsearch otherwise it will only return the first index and I am sure you want to check all segments.

    • #63901
      Gena Gill
      Participant

      As I was looking at the change I made with the foreach, it was doing something odd.  For each iteration of OBX it was returning the value only from the first iteration.

      Here’s the changed info

      #Set OBX

      set obxloc [lsearch -regexp $segments “^OBX”]

      set obx [lindex $segments $obxloc]

      set obx_fields [split $obx $fldsep]

      foreach seg $segments {

      #Get OBX 3 and OBX 5 values

      set obx_3_fields [lindex $obx_fields 3]

      set obx_3_sub [split $obx_3_fields $subsep]

      set obx_3 [lindex $obx_3_sub 0]

      set obx_5_fields [lindex $obx_fields 5]

      set obx_5 [lindex $obx_5_fields 5]

      if {[cequal “FLUIDML” $obx_3] && [cequal “0” $obx_5]} {

      echo “FLUIDML is 0”

      subst [FLUIDMLNO $obx_3}

      } else {

      echo “NO CHANGE”

      }

    • #63902
      John Hamilton
      Participant

      This might help you. Try it I don’t have your test data so I could not debug it but this should help.

                 set segments [msgget $mh ]

                 set obxloc [lsearch -all -regexp $segments “^OBX”]

                 foreach seg_id $obxloc {

                  set segmnt [lindex $segments $seg_id]

                  set obx_fields_lst [split $segmnt |]

                  set obx_3_fields [lindex $obx_fields_lst 3]

                  set OBX_3_sub_flds [split obx_3_fields ^]

                  set OBX_3_CHK [lindex OBX_3_sub_flds 0]

                  set OBX_5_CHK  [lindex $obx_fields_lst 5]

                  # echo it out to help debug

      echo == $OBX_3_CHK ++ $OBX_5_CHK ++

      if { ! [string compare  “FLUIDML” $OBX_3_CHK ] && ! [string compare  “0” $OBX_5_CHK ]} {

      echo “FLUIDML is 0”

                    } else {

                      echo “NO CHANGE”

                     }

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

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,292
Replies
34,435
Topic Tags
286
Empty Topic Tags
10