Reply To: Tcl Help – Removing OBX segment if OBX|5 value is blank

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Tcl Help – Removing OBX segment if OBX|5 value is blank Reply To: Tcl Help – Removing OBX segment if OBX|5 value is blank

#57939
Jonathan Hamilton
Participant

    Don’t set the variable when you do lappend.

    How are you handling re-numbering the set-id in the OBX segments?  You will need to add code to renumber in situations where you remove an OBX.  I typically use a Tcl variable and incr it for each OBX.  If I receive a segment other than OBX after an OBX I reset the variable back to 1.

    I tried to mock up the code to do what you need.  It should get you headed the right direction at least.

    *****************************************************

    set Fld_Sep [cindex $msg 3]; #  Field Separator “|”

    set Com_Sep [cindex $msg 4]; #  Component Separator “^”

    set Rep_Sep [cindex $msg 5]; #  Repetition Separator “~”

    set Esc_Chr [cindex $msg 6]; #  Escape Character “”

    set Sub_Sep [cindex $msg 7]; #  Subcomponent Separator “&”

    set Seg_List [split $msg r]

    set New_Seg_List “”

    set obx_cnt 1

    foreach Segment $Seg_List {

       set Seg_ID [crange $Segment 0 2]

       if { ($Seg_ID == “OBX”) } {

           set Field_List [split $Segment $Fld_Sep]

           set Result_Value [lindex $Field_List 5]

           if { ! ([regexp “^ *$” $Result_Value]) } {

               # Reverse the if logic to only do something if it isn’t true.

               set splitSegment [lreplace $Field_List 1 1 $obx_cnt]

               lappend New_Seg_List [join $splitSegment  $Fld_Sep]

           }

           incr obx_cnt

       } else {

           set obx_cnt 1

       }

    }

    set msg [join $New_Seg_List r]

    #  Replace message with new one created.

    msgset $mh $msg

    ************************************************

    Jonathan