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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STATMSG COUNTER PROBLEM

Status
Not open for further replies.

teletubby5e

Technical User
Oct 31, 2002
147
US
I am working on a script that reads a text file and performas a change on that record number. I currently have it displayting via statmsg the record number it is on in case the script bombs out, i can see where the problem with that record lies. also, i would like to know about the overall progress of the script. ideally, i would like it to count the number of lines in the text file, and then report back record 1 of 19234, or whatever, but i cant get past the first step even, to say record 1. here is what i have so far, but i keep getting the number 1 reported. thanks, for any ideas ...

RECORD1=1
ITOA RECORD1 RECORD1s
STATMSG "EDITING PART NUMBER %s, RECORD NUMBER %s" NUM1 RECORD1s
ATOI RECORD1s RECORD1
RECORD1=RECORD1+1



 
okay so i now have it working partially by moving the integer string RECORD1=1 to a point above where my loop starts, but still want to do an initial record count of all the lines in the text file opened up by script ...

SDLGFOPEN "FILE" "C\*.*" SINGLE TEST
FOPEN 1 TEST READ TEXT
WHILE !EOF
FGETS 1 LINE1
FEOF 1 EOF
STRTOK NUM1 LINE1 "," 1

so i need to do some sort of fseek to the eof, to do a line count, and then have it return to the top of the text file to do the fgets. thanks, jeff
 
sorry, here is the whole script:

PROC MAIN
STRING LINE1
STRING NUM1
INTEGER iRECORD1
STRING sRECORD1
STRING WAREHOUSE
STRING PARTNUM
STRING BINNUM
STRING COST
STRING TEST
INTEGER EOF

STATCLEAR
iRECORD1=1

; ==== initial logon here
transmit "/MI^M"
MSPAUSE 1000
waitfor "Enter Selection:" FOREVER

transmit "/FM^M"
MSPAUSE 1000
waitfor "Enter Selection:" FOREVER

transmit "PARTSFM^M"
MSPAUSE 1000
waitfor "End Program" FOREVER

; select menu option 4 to change
transmit "4^M"
MSPAUSE 1000
waitfor "Warehouse Search" FOREVER

STRFMT WAREHOUSE "FA^M"
TRANSMIT WAREHOUSE
MSPAUSE 100
waitfor "Description search" FOREVER

; point to text file CONTAINING CUSTOMER NUMBERS
SDLGFOPEN "FILE CONTAINING 2 COL'S OF INFO" "C\*.*" SINGLE TEST
FOPEN 1 TEST READ TEXT
WHILE !EOF
;GETS A LINE OF DATA AND READS INTO STRING LINE1
FGETS 1 LINE1
FEOF 1 EOF
;READS A LINE AND PUT DATA UP TO COMMA IN STRING NUM1
STRTOK NUM1 LINE1 "," 1

STRFMT PARTNUM "%.32s^M" NUM1
STRFMT COST "01^M"
STRFMT BINNUM "FA^M"

TRANSMIT PARTNUM
MSPAUSE 100
waitfor "ther rental" FOREVER

; GO TO BIN FIELD
TRANSMIT "5^M"
MSPAUSE 100
TRANSMIT BINNUM
MSPAUSE 100
waitfor "ther rental" FOREVER

; GO TO COST-1 FIELD
TRANSMIT "18^M"
MSPAUSE 100
TRANSMIT COST
MSPAUSE 100
waitfor "ther rental" FOREVER

; transmit ENTER TO RETURN TO THE PART NUMBER FIELD
transmit "^M"
MSPAUSE 100
WAITFOR "Description search" forever

ITOA iRECORD1 sRECORD1
STATMSG "EDITING PART NUMBER %s, RECORD NUMBER %s of " NUM1 sRECORD1
ATOI sRECORD1 iRECORD1
iRECORD1=iRECORD1+1

;END OF REPEAT
ENDWHILE

;SECTION TO QUIT OUT
TRANSMIT "^M"
MSPAUSE 1000
TRANSMIT "^M"
MSPAUSE 1000
TRANSMIT "^M"
MSPAUSE 1000
TRANSMIT "^M"
MSPAUSE 1000
TRANSMIT "Q^M"
MSPAUSE 1000
TRANSMIT "Q^M"
MSPAUSE 1000
PWEXIT

ENDPROC
 
OK, a couple comments here. On this code:

ITOA iRECORD1 sRECORD1
STATMSG "EDITING PART NUMBER %s, RECORD NUMBER %s of " NUM1 sRECORD1
ATOI sRECORD1 iRECORD1
iRECORD1=iRECORD1+1

I'm not sure why you are using atoi to convert the string back to an integer value since nothing was done on that string value that I see. Second, you can replace the statmsg line with this and eliminate the need for the itoa command:

STATMSG "EDITING PART NUMBER %d, RECORD NUMBER %s of " NUM1 iRECORD1

Also, you'll want to replace this line:

WHILE !EOF

with:

while not feof 1

If you want to read the lines in the file, I would recommend opening and reading the file (with the change above) like you are now complete with the recording of the number of lines, then closing the file, reopening it, and proceeding on with the rest of the script's tasks.

 
you are right, i had my lines out of order, but i was converting it to an integer in order to add 1 to the value. then converting it back to a string value to output via statmsg.

it works almost as desired though. it stats the record number for me, just not the total number of records ...i am just missing the last part. for example it says "processing 11356, out of xxx records" and increments each record by adding one to it when it goes to the next line in the read file loop. i guess that i can do a count of the 'end of line' character using fseek, or replace that character with the same character and get a report of hoy many occurences there are. what do you suggest?

by the way, what is the difference between
WHILE !EOF and while not feof 1 ?
i changed it, but i was just curious.

many thanks for your input in this forum!

jeff
 
What I would to get the number of lines in the file is to open it and read through the file one time, incrementing a counter for each line I read until I get to EOF of the file. Then I would close the file and reopen it to perform the actual line-by-line processing of the file. In other words, you will be reading the file twice, but only care about the actual contents of each record the second time. There's no other way to get the number of lines in the text file that I am aware of.

I thought originally you were not checking for EOF with the feof command but just had while !EOF, which would essentially be an endless loop, but see now that you are using feof, so that portion of the script likely would have been OK to leave as you had it.

 
THANKS. IT IS A LITTLE KLUDGY, BUT IT WORKS.


; === COUNTER SECTION ===
SDLGFOPEN "FILE TO COUNT" "C\*.*" SINGLE TEST
FOPEN 1 TEST READ TEXT
WHILE NOT FEOF 1
FGETS 1 sCOUNTER1
ITOA iCOUNTER1 sCOUNTER1
STATMSG "COUNTING LINE NUMBER %s" sCOUNTER1
iCOUNTER1=iCOUNTER1+1
FEOF 1 EOF
ENDWHILE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top