Originally posted by Penny Cummings
Help! I am trying to loop through the OBX segment, change some data on the OBX.3 field then put OBX.3 back into the segment. I am using lreplace to replace $obxfield with $obx_3 in position 3 3. When I run my code I get the error 'list doesn't contain element 3'. Here is my code:
#loop through the message and convert OBX.3 to UPPERCASE
foreach loc [lsearch -all -regexp $msg "^OBX"] {
# get the obx segment and obx 3 field from the message
set obxseg [lindex $msg $loc]
set obxfield [split $obxseg $fsep]
set obx_3 [lindex $obxfield 3]
#make all data in obx.3 UPPERCASE
regsub -all -- {.*} $obx_3 {[string toupper {&}]} obx_3
set obx_3 [subst -nobackslashes -novariables $obx_3]
## rebuild segment (put new obx3 back into the segment)
set newobx_3 [lreplace $obxfield 3 3 $obx_3]
set newobx_3 [join $newobx_3 $fsep]
#rebuild msg (put new segment back into the message)
set newmsg [lreplace $msg $loc $loc $newobx_3]
set newmsg [join $newmsg "r"]
msgset $mh $newmsg
};# close loop