Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strextract/ substr question 1

Status
Not open for further replies.

SAMMEE12

Technical User
Aug 9, 2004
10
US
Sorry, but I'm in need of some advice/help. I have just jumped into the dialogbox world because until I found this site, I couldn't figure out how to make them work. What I am doing is capturing a file and using some of the strings for info to send on to other scripting as is or for editing. Anyways, I'll try to be brief:

One of the lines in my capture file looks like this:

TN 040 0 05 05 KEY 00 H MARP DES 997693 31 DEC 2003

I am extracting the four numerical sequences after "TN" and may sometime in the future want/need the 6 numbers after "DES", the four numbers are put into separate editboxes, here's how I did that:

fgets 0 s19
len = 5
strdelete S19 Pos Len
strextract TNa S19 "K" nItem
strextract TNb S19 "K" nItem
strextract TNc S19 "K" nItem
strextract TNd S19 "K" nItem
substr tn1 tna 0 3
substr tn2 tnb 4 4
substr tn3 tnc 6 7
substr tn4 tnd 9 10

This displays the four number fields perfectly, in the four boxes this would show: 040 0 05 05
What I have discovered is that in fact the second "captured" box (tn2) also has the (tn3) data which I discovered as soon as I went to send it for further processing. I've tried changing the start/stop substr capture field, but the above example is the only one I found that works. I also tried putting the substr directly beneath each relevant strextract, but this had no effect. I have been able to somewhat use this as it is since if I need to edit the boxes and I clear what is there it sends fine. The rub is that if I need to send unedited, I would need to send only the tn1, tn2 and tn4 data since tn2 mysteriously has the tn3 data.
I have tried to be brief and many thanks to the contributors to this board, because if I couldn't have read back thru nearly 2 years worth of archives I never would have gotten this far. I've obviously made some errors though. I started scripting to save time, but eeehhh... as time marches on the validity of that reason wanes. I guess the triumph over challenge is enough motivation and this is a pleasant forum so... Anyone have a thought/solution to clear this up and if anyone knows of a way to move the cursor from editbox to editbox other than the one "TAB" key or a mouse click I would appreciate it. Thanks.
 
I seem to have found my own solution but I have no idea why this works.

fgets 0 s19
len = 5
strdelete S19 Pos Len
strextract TNa S19 "K" nItem
strextract TNb S19 "K" nItem
strextract TNc S19 "K" nItem
strextract TNd S19 "K" nItem
substr tn1 tna 0 3
substr tn2 tnb 3 3
substr tn3 tnc 5 4
substr tn4 tnd 9 10
I have to "hack" like crazy to make this stuff work. I wish I knew rather than my trial and error method but I digress. Whether it helps/matters [ nItem = 0 ] was mistakenly left out of what I thought might be pertinent. Once again thanks. Nudge, "tab" key...any other way?
 
The reason that the original script was getting extra information is that the last parameter to the substr command (the number of characters to copy) was longer than needed and so was getting extra information. Actually, your current script is getting extra information as well, but it is only spaces. The below code gets just the data with no extra spaces:

substr tn1 tna 0 3
substr tn2 tnb 4 1
substr tn3 tnc 6 2
substr tn4 tnd 9 2

What I do to determine if extra, nonprintable characters are being included in a string is to use a usermsg command like this:

usermsg "X%sX" tn1

If everything is as I expected, I would get output like X040X. However, if I see some spaces between the X and the data, or some graphical blocks, then I know I have some extra data I did not plan on.


aspect@aspectscripting.com
 
Thank You very much, knob. I may have never "hacked" my way into figuring that out. It seems you're the resident expert and the most likely to answer here. Thanks once again for sharing your knowledge.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top