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

Text to Excel (csv file) script *** beta 1

Status
Not open for further replies.

ptsul

Technical User
Joined
Mar 22, 2006
Messages
131
Location
PT
Hi all

Here is a nice tool ... well not yet ... but it will be when it's completly finished.
But the time (and brain)is not much to finish it ...
So for now enjoy this one. It work (mais ou menos) more or less ... Try it.
please keep the version number(V05c) when you compile for future reference
************************************************************
TFC Script- Text to CSV - 1º part
********************************save and compile from here

;TFC - TXT FILTER TO CSV v05C_Beta - By JMF CMPTSUL01
;TFC - TXT to CSV Fields
; - Tested - bugs detected - ok for small and logical filter sequences
;******************************* Global Variables Definition *********************************

string Swait[41],Scsvfrx[41],Stext[41],Scsvftx[41],Ssepchar[41],srowdata1
string Swttmunt,Swttmwf,smaxcycl,Smaxcr,stxpacing,smaxrow,scollimit,Swindes1,spercent
string Slista = ",00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19"
string Slist0
string Slist1 = ",1,2,3,4,5,6,7,8,9,10,12,16,18.20,24,28,32,48,64,96,128,180,224,255"
string Slist2 = ",S0,S2,S3,S4,S5,S6,S7,S8,S9,I0,I1,I2,I3,I4,I5,I6,I7,I8,I9,L0,L1,L2,L3,L4,F0,F1,F2,F3,F4"
integer Iconstsw[41],icsvcolsw[41],Iuntilsw[41],Ientersw[41]
integer Ilpstrt,Ilpend,imaxrow,icntline,ipercent,switch1,switch2,switch3
integer Ialwayssw,Iwaitfsw,Itstmodsw,ilpforeversw,ilpwrsw,iopttoudssw,iudssavsw
integer iwttmunt,iwttmwf,imaxcycl,itxpacing,imaxcr,icnvhrsw,icollimit

string SFileSpec1,Sfilecsv
string sfilespec2,sfilesav,Sfiletfs,Stemp1
string sfilespec3,sfiletxt
string Srowdata[3000]
; string Scoldata[41]

;*********************************************************************************************

proc main ; ****************************************************************************

;*** Define Variables

integer icnt0

;*** Define Variables Default Values

sfilespec1 = "c:\*.csv", sfilespec2 = "c:\*.tfs",sfilespec3 = "c:\*.txt;*.cap"
slist0 = slista
for icnt0 = 0 upto 40
Ssepchar[icnt0] = " "
endfor
stemp1 =""
switch1 = 1,switch2=1,switch3=1
Ialwayssw=0,Iwaitfsw=0,Itstmodsw=0,ilpforeversw=0,ilpwrsw=0
icnvhrsw=1,iopttoudssw=0,iudssavsw = 1
atoi swttmunt iwttmunt
atoi swttmwf iwttmwf
atoi smaxcycl imaxcycl
atoi smaxcr imaxcr
atoi scollimit icollimit
atoi stxpacing itxpacing

;** exec
call clearjanela

; strcat stemp1 sfilespec2
; strextract sfilespec2 stemp1 "*.tfs" 0
; strcat stemp1 sfilespec3
; sfilespec3 = stemp1
; usermsg "%s" sfilespec3

call janela
; call readfile
usermsg "Operation Finished"
call finalize

endproc ;*********************************************************************


proc janela ; *********** janela principal e sub-menus ***************************

;*** Define Variables

string Sfiletemp0
integer event


;*** Define Variables Values

;** janela principal

dialogbox 0 0 0 530 350 135 " TFC Text Filter Tool - Script v05C 041004 By JMF 062004 - Compta Sul "

groupbox 1 14 0 124 263 " Expect "
groupbox 2 265 0 1 290 ""
; groupbox 3 229 0 285 263 " "

text 10 3 12 10 12 "01" left
editbox 12 17 10 56 12 swait[1] 20
editbox 13 74 10 20 12 Ssepchar[1] 20
editbox 14 132 10 55 12 Stext[1] 255

editbox 22 17 24 56 12 Swait[2] 20
editbox 23 74 24 20 12 Ssepchar[2] 20
editbox 24 132 24 55 12 Stext[2] 255

editbox 32 17 39 56 12 Swait[3] 20
editbox 33 74 39 20 12 Ssepchar[3] 20
editbox 34 132 39 55 12 Stext[3] 255

editbox 42 17 53 56 12 Swait[4] 20
editbox 43 74 53 20 12 Ssepchar[4] 20
editbox 44 132 53 55 12 Stext[4] 255

text 50 3 68 10 12 "05" left
editbox 52 17 66 56 12 Swait[5] 20
editbox 53 74 66 20 12 Ssepchar[5] 20
editbox 54 132 66 55 12 Stext[5] 30

editbox 62 17 80 56 12 Swait[6] 20
editbox 63 74 80 20 12 Ssepchar[6] 20
editbox 64 132 80 55 12 Stext[6] 30

editbox 72 17 95 56 12 Swait[7] 20
editbox 73 74 95 20 12 Ssepchar[7] 20
editbox 74 132 95 55 12 Stext[7] 30

editbox 82 17 109 56 12 Swait[8] 20
editbox 83 74 109 20 12 Ssepchar[8] 20
editbox 84 132 109 55 12 Stext[8] 30

editbox 92 17 122 56 12 Swait[9] 20
editbox 93 74 122 20 12 Ssepchar[9] 20
editbox 94 132 122 55 12 Stext[9] 30

text 100 3 138 10 12 "10" left
editbox 102 17 136 56 12 swait[10] 20
editbox 103 74 136 20 12 Ssepchar[10] 20
editbox 104 132 136 55 12 Stext[10] 30

editbox 112 17 151 56 12 swait[11] 20
editbox 113 74 151 20 12 Ssepchar[11] 20
editbox 114 132 151 55 12 Stext[11] 30

editbox 122 17 165 56 12 Swait[12] 20
editbox 123 74 165 20 12 Ssepchar[12] 20
editbox 124 132 165 55 12 Stext[12] 30

editbox 132 17 178 56 12 Swait[13] 20
editbox 133 74 178 20 12 Ssepchar[13] 20
editbox 134 132 178 55 12 Stext[13] 30

editbox 142 17 192 56 12 Swait[14] 20
editbox 143 74 192 20 12 Ssepchar[14] 20
editbox 144 132 192 55 12 Stext[14] 30

text 150 3 208 10 12 "15" left
editbox 152 17 207 56 12 Swait[15] 20
editbox 153 74 207 20 12 Ssepchar[15] 20
editbox 154 132 207 55 12 Stext[15] 30

editbox 162 17 221 56 12 Swait[16] 20
editbox 163 74 221 20 12 Ssepchar[16] 20
editbox 164 132 221 55 12 Stext[16] 30

editbox 172 17 234 56 12 Swait[17] 20
editbox 173 74 234 20 12 Ssepchar[17] 20
editbox 174 132 234 55 12 Stext[17] 30

editbox 182 17 248 56 12 Swait[18] 20
editbox 183 74 248 20 12 Ssepchar[18] 20
editbox 184 132 248 55 12 Stext[18] 30

editbox 192 17 262 56 12 Swait[19] 20
editbox 19 74 262 20 12 Ssepchar[19] 20
editbox 194 132 262 55 12 Stext[19] 30

text 200 3 278 10 12 "20" left
editbox 202 17 276 56 12 Swait[20] 20
editbox 203 74 276 20 12 Ssepchar[20] 20
editbox 204 132 276 55 12 Stext[20] 30

text 210 269 12 10 12 "21" left
editbox 212 282 10 56 12 swait[21] 20
editbox 213 339 10 20 12 Ssepchar[21] 20
editbox 214 397 10 55 12 Stext[21] 255

editbox 222 282 24 56 12 Swait[22] 20
editbox 223 339 24 20 12 Ssepchar[22] 20
editbox 224 397 24 55 12 Stext[22] 255

editbox 232 282 39 56 12 Swait[23] 20
editbox 233 339 39 20 12 Ssepchar[23] 20
editbox 234 397 39 55 12 Stext[23] 255

editbox 242 282 53 56 12 Swait[24] 20
editbox 243 339 53 20 12 Ssepchar[24] 20
editbox 244 397 53 55 12 Stext[24] 255

text 250 269 68 10 12 "25" left
editbox 252 282 66 56 12 Swait[25] 20
editbox 253 339 66 20 12 Ssepchar[25] 20
editbox 254 397 66 55 12 Stext[25] 30

editbox 262 282 80 56 12 Swait[26] 20
editbox 263 339 80 20 12 Ssepchar[26] 20
editbox 264 397 80 55 12 Stext[26] 30

editbox 272 282 95 56 12 Swait[27] 20
editbox 273 339 95 20 12 Ssepchar[27] 20
editbox 274 397 95 55 12 Stext[27] 30

editbox 282 282 109 56 12 Swait[28] 20
editbox 283 339 109 20 12 Ssepchar[28] 20
editbox 284 397 109 55 12 Stext[28] 30

editbox 292 282 122 56 12 Swait[29] 20
editbox 293 339 122 20 12 Ssepchar[29] 20
editbox 294 397 122 55 12 Stext[29] 30

text 300 269 138 10 12 "30" left
editbox 302 282 136 56 12 swait[30] 20
editbox 303 339 136 20 12 Ssepchar[30] 20
editbox 304 397 136 55 12 Stext[30] 30

editbox 312 282 151 56 12 swait[31] 20
editbox 313 339 151 20 12 Ssepchar[31] 20
editbox 314 397 151 55 12 Stext[31] 30

editbox 322 282 165 56 12 Swait[32] 20
editbox 323 339 165 20 12 Ssepchar[32] 20
editbox 324 397 165 55 12 Stext[32] 30

editbox 332 282 178 56 12 Swait[33] 20
editbox 333 339 178 20 12 Ssepchar[33] 20
editbox 334 397 178 55 12 Stext[33] 30

editbox 342 282 192 56 12 Swait[34] 20
editbox 343 339 192 20 12 Ssepchar[34] 20
editbox 344 397 192 55 12 Stext[34] 30

text 350 269 208 10 12 "35" left
editbox 352 282 207 56 12 Swait[35] 20
editbox 353 339 207 20 12 Ssepchar[35] 20
editbox 354 397 207 55 12 Stext[35] 30

editbox 362 282 221 56 12 Swait[36] 20
editbox 363 339 221 20 12 Ssepchar[36] 20
editbox 364 397 221 55 12 Stext[36] 30

editbox 372 282 234 56 12 Swait[37] 20
editbox 373 339 234 20 12 Ssepchar[37] 20
editbox 374 397 234 55 12 Stext[37] 30

editbox 382 282 248 56 12 Swait[38] 20
editbox 383 339 248 20 12 Ssepchar[38] 20
editbox 384 397 248 55 12 Stext[38] 30

editbox 392 282 262 56 12 Swait[39] 20
editbox 393 339 262 20 12 Ssepchar[39] 20
editbox 394 397 262 55 12 Stext[39] 30

text 400 269 278 10 12 "40" left
editbox 402 282 276 56 12 Swait[40] 20
editbox 403 339 276 20 12 Ssepchar[40] 20
editbox 404 397 276 55 12 Stext[40] 30


radiogroup 500 Ilpstrt
radiobutton 501 196 10 32 12 "SL 01"
radiobutton 502 196 24 32 12 "SL 02"
radiobutton 503 196 38 32 12 "SL 03"
radiobutton 504 196 52 32 12 "SL 04"
radiobutton 505 196 66 32 12 "SL 05"
radiobutton 506 196 80 32 12 "SL 06"
radiobutton 507 196 94 32 12 "SL 07"
radiobutton 508 196 108 32 12 "SL 08"
radiobutton 509 196 122 32 12 "SL 09"
radiobutton 510 196 136 32 12 "SL 10"
radiobutton 511 196 150 32 12 "SL 11"
radiobutton 512 196 164 32 12 "SL 12"
radiobutton 513 196 178 32 12 "SL 13"
radiobutton 514 196 192 32 12 "SL 14"
radiobutton 515 196 206 32 12 "SL 15"
radiobutton 516 196 220 32 12 "SL 16"
radiobutton 517 196 234 32 12 "SL 17"
radiobutton 518 196 248 32 12 "SL 18"
radiobutton 519 196 262 32 12 "SL 19"
radiobutton 520 196 276 32 12 "SL 20"
radiobutton 521 456 10 32 12 "SL 21"
radiobutton 522 456 24 32 12 "SL 22"
radiobutton 523 456 38 32 12 "SL 23"
radiobutton 524 456 52 32 12 "SL 24"
radiobutton 525 456 66 32 12 "SL 25"
radiobutton 526 456 80 32 12 "SL 26"
radiobutton 527 456 94 32 12 "SL 27"
radiobutton 528 456 108 32 12 "SL 28"
radiobutton 529 456 122 32 12 "SL 29"
radiobutton 530 456 136 32 12 "SL 30"
radiobutton 531 456 150 32 12 "SL 31"
radiobutton 532 456 164 32 12 "SL 32"
radiobutton 533 456 178 32 12 "SL 33"
radiobutton 534 456 192 32 12 "SL 34"
radiobutton 535 456 206 32 12 "SL 35"
radiobutton 536 456 220 32 12 "SL 36"
radiobutton 537 456 234 32 12 "SL 37"
radiobutton 538 456 248 32 12 "SL 38"
radiobutton 539 456 262 32 12 "SL 39"
radiobutton 540 456 276 32 12 "SL 40"
endgroup
radiogroup 600 Ilpend
radiobutton 601 232 10 32 12 "EL 01"
radiobutton 602 232 24 32 12 "EL 02"
radiobutton 603 232 38 32 12 "EL 03"
radiobutton 604 232 52 32 12 "EL 04"
radiobutton 605 232 66 32 12 "EL 05"
radiobutton 606 232 80 32 12 "EL 06"
radiobutton 607 232 94 32 12 "EL 07"
radiobutton 608 232 108 32 12 "EL 08"
radiobutton 609 232 122 32 12 "EL 09"
radiobutton 610 232 136 32 12 "EL 10"
radiobutton 611 232 150 32 12 "EL 11"
radiobutton 612 232 164 32 12 "EL 12"
radiobutton 613 232 178 32 12 "EL 13"
radiobutton 614 232 192 32 12 "EL 14"
radiobutton 615 232 206 32 12 "EL 15"
radiobutton 616 232 220 32 12 "EL 16"
radiobutton 617 232 234 32 12 "EL 17"
radiobutton 618 232 248 32 12 "EL 18"
radiobutton 619 232 262 32 12 "EL 19"
radiobutton 620 232 276 32 12 "EL 20"
radiobutton 621 492 10 32 12 "EL 21"
radiobutton 622 492 24 32 12 "EL 22"
radiobutton 623 492 38 32 12 "EL 23"
radiobutton 624 492 52 32 12 "EL 24"
radiobutton 625 492 66 32 12 "EL 25"
radiobutton 626 492 80 32 12 "EL 26"
radiobutton 627 492 94 32 12 "EL 27"
radiobutton 628 492 108 32 12 "EL 28"
radiobutton 629 492 122 32 12 "EL 29"
radiobutton 630 492 136 32 12 "EL 30"
radiobutton 631 492 150 32 12 "EL 31"
radiobutton 632 492 164 32 12 "EL 32"
radiobutton 633 492 178 32 12 "EL 33"
radiobutton 634 492 192 32 12 "EL 34"
radiobutton 635 492 206 32 12 "EL 35"
radiobutton 636 492 220 32 12 "EL 36"
radiobutton 637 492 234 32 12 "EL 37"
radiobutton 638 492 248 32 12 "EL 38"
radiobutton 639 492 262 32 12 "EL 39"
radiobutton 640 492 276 32 12 "EL 40"
endgroup


pushbutton 900 205 337 36 11 "Start"
pushbutton 901 287 337 36 11 "Quit"
editbox 903 329 318 194 12 Swindes1 64
pushbutton 904 342 334 42 11 "Open File"
pushbutton 905 403 334 42 11 "Save As"
pushbutton 906 462 334 42 11 "Clear All"
pushbutton 907 6 307 42 11 "Open File"
pushbutton 908 70 307 42 11 "Show File"
text 910 175 308 20 10 smaxrow left
text 911 5 327 194 10 sfilecsv center
checkbox 912 209 297 116 11 "Fill w/comma empty fields (csv)" switch1
checkbox 913 209 307 116 11 "Del initial Line spaces (txt)" switch2
checkbox 914 209 317 116 11 "Del initial Field spaces (csv)" switch3
text 916 5 297 194 10 Sfiletxt center
text 917 329 297 194 10 Sfiletfs center
text 918 116 308 60 10 "Number of Rows:" left
pushbutton 919 6 337 42 11 "New File"
pushbutton 920 70 337 42 11 "Save As"
text 922 256 339 18 10 Spercent center

groupbox 930 205 290 118 43 "Options"
groupbox 931 255 332 20 18 ""
groupbox 932 2 320 200 31 " Select Destination File (.CSV file)"
groupbox 933 2 290 200 30 " Select Source File (.Txt or .Cap)"
groupbox 934 327 290 200 60 " Open/Save - Text Filter Script Files (.tfs)"



enddialog

;*** default window starts


disable DLGCTRL 0 900
disable DLGCTRL 0 908

dlgupdate 0 0,420
dlgupdate 0 900,922

;***** janela swyching control - Hold until EXECUTE is pressed

while 1
dlgevent 0 Event
switch Event
case 0
yield
endcase
;** case 901 - CANCEL WINDOW
case 901
dlgdestroy 0 cancel
usermsg "Operation Canceled"
call finalize
endcase
;** case 904 - OPEN TFS FILE
case 904
sfiletemp0 = Sfiletfs
if sdlgfopen "Select the file .tfs " sfilespec2 SINGLE Sfiletfs
call openscript
endif
if nullstr Sfiletfs
Sfiletfs = sfiletemp0
elseif nullstr Sfiletfs
disable DLGCTRL 0 900
elseif ilpstrt > (ilpend - 100)
disable DLGCTRL 0 900
elseif nullstr Sfiletxt
disable DLGCTRL 0 900
elseif nullstr Sfilecsv
disable DLGCTRL 0 900
else
enable DLGCTRL 0 900
endif
dlgupdate 0 0,420
dlgupdate 0 900,922
endcase
;** case 905 - SAVE .UDS FILE
case 905
call savescript
endcase
;** case 906 - CLEAR WINDOW FIELDS
case 906
call clearjanela
endcase

;** case 907 - select and show txtfile

case 907
if sdlgfopen "Selecione o ficheiro .txt ou .cap " SFileSpec3 SINGLE SFiletxt
call showtxtfile
enable DLGCTRL 0 908
dlgupdate 0 0,420
dlgupdate 0 900,922
endif
if nullstr Sfiletxt

elseif nullstr Sfiletfs
disable DLGCTRL 0 900
elseif ilpstrt > (ilpend - 100)
disable DLGCTRL 0 900
elseif nullstr Sfiletxt
disable DLGCTRL 0 900
elseif nullstr Sfilecsv
disable DLGCTRL 0 900
else
enable DLGCTRL 0 900
endif
dlgupdate 0 0,420
dlgupdate 0 900,922


endcase

;*** cse 908 Show txt file
case 908
fileview sfiletxt
endcase
;** case 912 - option window switch1
case 912
dlgupdate 0 912
endcase
;** case 913 - option window switch2
case 913
dlgupdate 0 913
endcase
;** case 914 - option window switch3
case 914
dlgupdate 0 914
endcase

;** case 919 - select new csv file

case 919
if sdlgfopen "Select file *.csv " SFileSpec1 SINGLE SFilecsv
endif
dlgupdate 0 911
if nullstr Sfilecsv

elseif nullstr Sfiletfs
disable DLGCTRL 0 900
elseif ilpstrt > (ilpend - 100)
disable DLGCTRL 0 900
elseif nullstr Sfiletxt
disable DLGCTRL 0 900
elseif nullstr Sfilecsv
disable DLGCTRL 0 900
else
enable DLGCTRL 0 900
endif
dlgupdate 0 0,420
dlgupdate 0 900,922


endcase
;*** cse 920 save as csv file
case 920
if sdlgsaveas "Select file .csv to save " SFileSpec1 SFilecsv
endif
dlgupdate 0 911
if nullstr Sfilecsv

elseif nullstr Sfiletfs
disable DLGCTRL 0 900
elseif ilpstrt > (ilpend - 100)
disable DLGCTRL 0 900
elseif nullstr Sfiletxt
disable DLGCTRL 0 900
elseif nullstr Sfilecsv
disable DLGCTRL 0 900
else
enable DLGCTRL 0 900
endif

endcase

;** case 500 e 600
case 500
if ilpstrt > ilpend-100
alarm 2
errormsg " Start Loop Can't Be Bigger Than End Loop "
disable DLGCTRL 0 900
elseif nullstr Sfiletfs
disable DLGCTRL 0 900
else
enable DLGCTRL 0 900
endif
endcase
case 600
if ilpend-100 < ilpstrt
alarm 2
errormsg " End Loop Can't Be Smaller Than Start Loop "
disable DLGCTRL 0 900
elseif nullstr Sfiletfs
disable DLGCTRL 0 900
elseif nullstr Sfiletxt
disable DLGCTRL 0 900
elseif nullstr Sfilecsv
disable DLGCTRL 0 900
else
enable DLGCTRL 0 900
endif
endcase

;** case 900 all ready exit janela & execute UDS

case 900
disable dlgctrl 0 900,920
enable dlgctrl 0 922

call readfile

exitwhile
endcase
endswitch
endwhile
dlgdestroy 0 OK
return

endproc ;**************************** end of janela **************************

; end of 1º part ***************************************

 
merge this to the 1º part and save/compile together

*****************************************************
TFC V05c - 2ºpart
***********************************copy from here



proc readfile ;******** Processar texto e gravar para csv

string stemp0 ;stemp1
integer icntlp,icntllow,icntlhigh,endsw,len,cnttemp = 1,pos
integer icntrow,icntrlow,icntrhigh
;*** definitions

; ilpstrt = ilpstrt - 500
; ilpend = ilpend - 600

icntlp = 0
icntllow = ilpstrt - 500
icntlhigh = ilpend - 600
icntrlow = 0
icntrhigh = imaxrow



;******************** Write the header row to csv file

if fopen 3 SFilecsv write text ; Open file for write.
for icntlp = icntllow upto icntlhigh
strlen swait[icntlp] len
fwrite 3 swait[icntlp] len
fwrite 3 ";" 1
endfor
fputs 3 ""


;******************** read and


for icntrow = icntrlow upto icntrhigh

srowdata1 = srowdata[icntrow]

if not nullstr srowdata1
icntline=icntline+1
;******************** teste - retirar espacos em branco na linha texto
if switch2 ==1
strchr srowdata1 ' ' Pos

if pos == 0

while 1
strlen srowdata1 Len
strchr srowdata1 ' ' Pos

if Pos == 0

strdelete srowdata1 0 1
; usermsg "%s" srowdata1
else

exitwhile
endif
endwhile
endif
endif

strextract stemp0 srowdata1 " " 0 ; Ssepchar[0] 0Ssepchar[2]

;********************* waitfor loop

for icntlp = icntllow upto icntlhigh



if strcmp stemp0 swait[icntlp]
strextract stext[icntlp] srowdata1 Swait[icntlp] 1


; strextract stemp1[icntlp] stext[icntlp] Ssepchar[icntlp] 0



;******************** delete spaces before characters

if switch3 == 1

if not nullstr stext[icntlp] ; Check to see if name is null.

while 1
strlen stext[icntlp] Len ; Get length of string entered.
strchr stext[icntlp] ' ' Pos ; Find first occurrence of space.


if Pos == 0 ; Check to see if index is negative.

strdelete stext[icntlp] 0 1

else

exitwhile
endif
endwhile
endif

endif
;********************
if icntlp == icntlhigh
endsw = 1
endif
;******************** fill empty colums with ;
if switch1 == 1
while cnttemp < icntlp
fwrite 3 ";" 1
cnttemp=cnttemp+1
endwhile
endif
;********************

strlen stext[icntlp] len
fwrite 3 stext[icntlp] len
cnttemp=cnttemp+1

fwrite 3 ";" 1
if endsw == 1
fputs 3 ""
cnttemp = 1
endif
endsw=0
ipercent=(icntline*100)/imaxrow
itoa ipercent spercent

dlgupdate 0 0,420
dlgupdate 0 900,922

exitfor
endif


endfor
endif
endfor

else
usermsg "Erro ao tentar escrever no ficheiro .csv ! Verifique se se encontra aberto por outro programa."

endif
fclose 3


return

#comment
; introduzir ";" caso data blank
else

fwrite 3 ";" 1
if endsw == 1
fputs 3 ""
endif
endsw=0


while 1

if not nullstr stext[icntlp] ; Check to see if name is null.
strlen stext[icntlp] Len ; Get length of string entered.
strchr stext[icntlp] ' ' Pos ; Find first occurrence of space.
if Pos == 0 ; Check to see if index is negative.
strreplace stext[icntlp] " " ""
Pos = 0 ; Set position to zero position.
else
Pos++
exitwhile ;Pos++ ; If space found, set pos to next
endif ; character.
endif
endwhile


#endcomment






endproc ;*********************************************************************


proc whattosave ;*********************************************************************

;*** Define Variables

string stemp0
integer icntlp,icntllow,icntlhigh,endsw

; integer icntrow,icntrlow,icntrhigh
; integer icntcol,icntclow,icntchigh
; integer icntirow,icntirow1,icntilow,icntihigh
; integer icnt0,itemp0,imincol,imaxcol


;*** definitions

ilpstrt = ilpstrt - 500
ilpend = ilpend - 600


#comment


#endcomment
icntlp = 0
icntllow = ilpstrt
icntlhigh = ilpend

pause 1
strextract stemp0 srowdata1 Ssepchar[0] 0
usermsg " field 1 - > %s" stemp0




;*** Loop (SL/EL)
for icntlp = icntllow upto icntlhigh

;** test 1 field
usermsg " count - > %d" icntlp
;strextract stext[icntlp] srowdata1 swait[icntlp] 1
usermsg " stext - > %s" stext[icntlp]
usermsg " swait - > %s" swait[icntlp]
if strcmp stemp0 swait[icntlp]

strextract stext[icntlp] srowdata1 Ssepchar[icntlp] 1
if icntlp = icntlhigh
endsw = 1
endif
usermsg " stext - > %s" stext[icntlp]
call savetocsv with icntlp,endsw
endsw=0
;exitfor
endif

endfor

return



endproc ;*********************************************************************

proc savetocsv ;*** janela CASE 205 - SAVE FILE (.csv)*****************
param integer icntlp,endsw

integer len

if fopen 3 SFilecsv write text ; Open file for read.

usermsg "save count - > %d" icntlp
usermsg "save text - > %s" stext[icntlp]
strlen stext[icntlp] len
usermsg " stext lenght - > %d" len
fwrite 3 stext[icntlp] len ;Sfilespec1 ;fputs 2 "Blank line1"
fwrite 3 ";" 1 ;Sfilespec2 ;fputs 2 "Blank line2"
if endsw == 1
fputs 3 ""
endif
fclose 3
endif

return

endproc ;*********************************************************************

proc openscript ;*** janela CASE 204 - OPEN TFS FILE *********************************

integer icnt0

if fopen 1 Sfiletfs read text ; Open file for read.

fgets 1 stemp1 ;Sfilespec1 ;fputs 2 "Blank line1"
fgets 1 stemp1 ;Sfilespec2 ;fputs 2 "Blank line2"

;** uds
if iudssavsw == 1
fgets 1 Swindes1
for icnt0 = 1 upto 40
fgets 1 Scsvfrx[icnt0]
fgets 1 Swait[icnt0]
fgets 1 Ssepchar[icnt0]
fgets 1 Stext[icnt0]
fgets 1 Scsvftx[icnt0]
fgets 1 Stemp1
atoi Stemp1 Iconstsw[icnt0]
fgets 1 Stemp1
atoi Stemp1 icsvcolsw[icnt0]
fgets 1 Stemp1
atoi Stemp1 Ientersw[icnt0]
fgets 1 Stemp1
atoi Stemp1 Iuntilsw[icnt0]
endfor
fgets 1 Stemp1
atoi Stemp1 Ilpstrt
fgets 1 Stemp1
atoi Stemp1 Ilpend
fgets 1 Stemp1
atoi Stemp1 iopttoudssw
endif
endif

fclose 1
enable DLGCTRL 0 917
dlgupdate 0 0,917
dlgupdate 0 500,700
return

endproc ;*********************************************************************

proc savescript ;*** janela CASE 205 - SAVE WINDOW SCRIPT FILE (.tfs)*****************

integer icnt0

if sdlgsaveas "File name .tfs to save " SFileSpec2 SFilesav
if fopen 2 SFilesav write text ; Open file for read.

fputs 2 stemp1 ;Sfilespec1 ;fputs 2 "Blank line1"
fputs 2 stemp1 ;Sfilespec2 ;fputs 2 "Blank line2"


;** Uds
if iudssavsw == 1
fputs 2 Swindes1
for icnt0 = 1 upto 40
fputs 2 Scsvfrx[icnt0]
fputs 2 Swait[icnt0]
fputs 2 Ssepchar[icnt0]
fputs 2 Stext[icnt0]
fputs 2 Scsvftx[icnt0]
itoa Iconstsw[icnt0] Stemp1
fputs 2 Stemp1
itoa icsvcolsw[icnt0] Stemp1
fputs 2 Stemp1
itoa Ientersw[icnt0] Stemp1
fputs 2 Stemp1
itoa Iuntilsw[icnt0] Stemp1
fputs 2 Stemp1
endfor
itoa Ilpstrt Stemp1
fputs 2 Stemp1
itoa Ilpend Stemp1
fputs 2 Stemp1
itoa iopttoudssw Stemp1
fputs 2 Stemp1
endif
endif
fclose 2
endif
enable DLGCTRL 0 917
dlgupdate 0 1,920
return

endproc ;*********************************************************************

proc clearjanela ;******************************** not working *************************************

;** case 206 - CLEAR WINDOW FIELDS and set to saved options settings

Sfilesav ="c:\clear.tfs"
Sfiletfs="c:\clear.tfs"
iopttoudssw = 0
if fopen 2 Sfiletfs read text ; Open file for read.
fgets 2 Sfilespec1
fgets 2 Sfilespec2
else
fopen 2 SFilesav write text
fputs 2 Sfilespec1
fputs 2 Sfilespec2
fclose 2
endif
fclose 2
disable DLGCTRL 0 900
if nullstr sfilecsv
disable DLGCTRL 0 908
endif
disable DLGCTRL 0 917
dlgupdate 0 0,917
; sfilespec2 ="c:\*.tfs"
Sfiletfs = sfilespec2



return

endproc ;*********************************************************************

proc showtxtfile ; ****** Case 220 Read txtfile and show header and 1'row *************



fileview sfiletxt

;* Read csv file line's and find imaxrow

imaxrow = 0
if fopen 0 sfiletxt READ TEXT
while not feof 0
while 1
fgets 0 srowdata[imaxrow]
;* Stop reading file
if nullstr srowdata[imaxrow]
exitwhile
else
imaxrow = imaxrow + 1
endif
endwhile
endwhile
fclose 0
endif
itoa imaxrow smaxrow
dlgupdate 0 0,918
dlgupdate 4 1 5
return

endproc ;*********************************************************************


proc finalize ;*********************************************************************

usermsg "GoodBye!"

halt

endproc ;*****************************************************************************
; END OF TFC V05c SCRIPT ***********************************

 
OK!
How to use it?
for example, to test, a filter for digital sets (try with a small file first)
1º - capture a LD20 PRT - 2000
2º - clean the file, removing errors, bugs, and the inicial lines - PRT bla bla... until the first DES (keep DES in file) cause it's part of the loop to search the fields, atleast in this filter we are using. As you will see the filter is set between the DES and DATE.
3º - run the script, select the TFC filter file or define a new one - but for now select the example I post here.
4º - select the captured file (source file) .txt or .cap

5º - select the destination file *.CSV - which will be the result file after the filtering process.

6º - and START.

Et voila - Já está ... done!

Example:
copy to notepad and save as: TFCDsetsv05c_00.tfs
*******************************************************
DSETS filter for V05c
*******************************************************
0
0
LD20 Dsets Sets v05c_01 - Rls >22 V05b - teste

DES
6


0
0
0
0

TN
12


0
0
0
0

TYPE
4


0
0
0
0

CUST
2


0
0
0
0

FDN
3


0
0
0
0

TGAR
12


0
0
0
0

NCOS
7


0
0
0
0

SGRP
1


0
0
0
0

RNPG
2


0
0
0
0

SCI
2


0
0
0
0

SSU
3


0
0
0
0

XLST
2


0
0
0
0

SCPW
5


0
0
0
0

CLS
24


0
0
0
1


12


0
0
1
0

HUNT



0
0
0
0

EHT



0
0
0
0

EFD



0
0
0
0
501
LHK



0
0
0
0

LPK



0
0
0
0

KEY



0
0
0
0

01



0
0
0
0

02



0
0
0
0

03



0
0
0
0

04



0
0
0
0

05



0
0
0
0

06



0
0
0
0

07



0
0
0
0

08



0
0
0
0

09



0
0
0
0

10



0
0
0
0

11



0
0
0
0

12



0
0
0
0

13



0
0
0
0

14



0
0
0
0

15



0
0
0
0

DATE



0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0
501
637
0
********* end file **** don't save this ********************
 
you have way to much time on your hands, that is a great script.. looks like a few months of banging ones head against the wall.. thanks

john poole
bellsouth business
columbia,sc
 
Another example

***********************************************************
0
0
ALL TNB - Rls >22 para a versao TFC05 - varios FTR e KEY

DES



0
0
0
0

TN



0
0
0
0

TYPE



0
0
0
0

CUST



0
0
0
0

WRLS



0
0
0
0

DN



0
0
0
0

RTMB



0
0
0
0

SIGL



0
0
0
0

TGAR



0
0
0
0

NCOS



0
0
0
0

RNPG



0
0
0
0

XLST



0
0
0
0

SCPW



0
0
0
0

HUNT



0
0
0
1

ETH



0
0
1
0

FDN



0
0
0
0

EFD



0
0
0
0

RCO



0
0
0
0
501
FTR


0
0
5
0
0

FTR



0
0
0
0

FTR



0
0
0
0

FTR



0
0
0
0

FTR



0
0
0
0

KEY



0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0

DATE



0
0
0
0
501
640
0
***********************************************************
 
Filter for 500 sets

**** don't copy this line, only after*******************


500 Sets - Rls >22

DES



0
0
0
0

TN



0
0
0
0

TYPE



0
0
0
0

CUST



0
0
0
0

WRLS



0
0
0
0

DN



0
0
0
0

HUNT



0
0
0
0

TGAR



0
0
0
0

NCOS



0
0
0
0

SGRP



0
0
0
0

RNPG



0
0
0
0

XLST



0
0
0
0

SCPW



0
0
0
0

FTR



0
0
0
1

DATE



0
0
1
0





0
0
0
0





0
0
0
0





0
0
0
0
501



0
0
5
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0





0
0
0
0
501
615
0
********** don't copy this line ********************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top