I've grown attached to the Javascript
SPLIT method for handling varible length
strings in records. Really wish we had this
in PB products. So this is note to submit
the idea, and then I'll get back to work.
------------------------------------------
Yesterday I needed to do a quick sort on
two such files. One was 22MB and since I have a 64MB PC I thought I'd do a Quick
and Dirty READ-SORT-WRITE. The code below
is the result. It worked and was really
fast on the 22MB file. Then I tried it with
the 80MB file. To my surprise it worked!! Must be a virtual memory implementation of string arrays!?
--------------------------------------------
What follows is the sort program and a
"suggestion" about embeding the Javascript
SPLIT idea into the PB GET$ I/O method.
It should also be considered for a function
within DLL code - SPLIT/UNSPLIT.
============================================
#COMPILE EXE
FUNCTION PBMAIN() AS LONG
REGISTER j AS LONG:REGISTER k AS LONG
LOCAL n AS LONG:LOCAL RecordCount AS LONG
CrLf$=CHR$(13,10)
OPEN "INPUT.DAT" FOR BINARY AS #1
GET$ #1,LOF(1),Text$:CLOSE #1
RecordCount=PARSECOUNT(Text$,CrLf$)-1 ' PARSECOUNT is too big by 1?
DIM AM(1:RecordCount) AS STRING
j=0:n=1
WHILE n<RecordCount
k=INSTR(j+1,Text$,CrLf$)
AM(n)=MID$(Text$,j+1,k-j-1)
INCR n:j=k+LEN(CrLf$)-1
WEND
Text$=""
ARRAY SORT AM() FOR RecordCount
OPEN"OUTPUT.DAT" FOR OUTPUT AS #1
FOR i&=1 TO RecordCount
rint#1,AM(i&):NEXT i&
END FUNCTION
---------------------------------------------
Product Enhancement Idea is below
---------------------------------------------
#COMPILE EXE
GLOBAL MemIN() AS STRING
FUNCTION PBMAIN() AS LONG
LOCAL n AS LONG:LOCAL RecordCount AS LONG
CrLf$=CHR$(13,10)
OPEN "INPUT.DAT" FOR BINARY AS #1
GET$ #1,LOF(1),MemIN(CrLf$):CLOSE #1' See note below
ARRAY SORT MemIN()' Normal sort of an array now allocated in memory
OPEN"OUTPUT.DAT" FOR BINARY AS #1
PUT$ #1,MemIN(CrLf$):close# 'Reverse of Get$ for a string array
END FUNCTION
---------------------------------------------
'*GET$ action with an unallocated string
' array as "sVar"
' First; detect an unallocated string array and start allocation process
' Second; set PARSECOUNT string delimit$ to
' CrLf$ string (default value could be
' chr$(13,10))
' Third; iii&=0
' Fourth; Input file making text breaks at
' delimit$ and and assign to MemIN(iii&++)
' At EOF set UBOUND(MemIN) to i&&&
' Another way of looking at this logic is
' with the Javascript SPLIT method. You
' could read the entire file into a string
' like TEXT$ and use SPILT to create a new
' string array, e.g.
'
' NewArray=Text$.split(CrLf$)
'
' but this takes more than twice as much
' memory. Better to embed the logic in
' ML inside GET$
'///////////////////////////////////////////
' GENERALIZATION
' A two dimensional array would be very
' convenient for files having separate
' delimeters for FIELD separation and LINE
' separation, e.g.
'
' "AAA|BB|C|DDDD"
' "FFFFFFFF|GGGGG|HHHHHHHHHH|KKKKKKKKK"
'
' (A fixed number variable length items,
' 4 in this case, in a variable length
' file - 2 records in this case)
'
' GLOBAL MemIN(,) AS STRING
' GET$ #1,LOF(1),MemIN("|",CHR$(13,10))
'
' SPLIT METHOD
' I use the split method all the time in ' javascript. It saves a lot of
' writing and documents a program pretty ' well. I would love to see it
' or a similar function in PB products, e.g.
'
' ' Unallocated_Array=SPLIT(TEXT$,"|")
'
SPLIT method for handling varible length
strings in records. Really wish we had this
in PB products. So this is note to submit
the idea, and then I'll get back to work.
------------------------------------------
Yesterday I needed to do a quick sort on
two such files. One was 22MB and since I have a 64MB PC I thought I'd do a Quick
and Dirty READ-SORT-WRITE. The code below
is the result. It worked and was really
fast on the 22MB file. Then I tried it with
the 80MB file. To my surprise it worked!! Must be a virtual memory implementation of string arrays!?
--------------------------------------------
What follows is the sort program and a
"suggestion" about embeding the Javascript
SPLIT idea into the PB GET$ I/O method.
It should also be considered for a function
within DLL code - SPLIT/UNSPLIT.
============================================
#COMPILE EXE
FUNCTION PBMAIN() AS LONG
REGISTER j AS LONG:REGISTER k AS LONG
LOCAL n AS LONG:LOCAL RecordCount AS LONG
CrLf$=CHR$(13,10)
OPEN "INPUT.DAT" FOR BINARY AS #1
GET$ #1,LOF(1),Text$:CLOSE #1
RecordCount=PARSECOUNT(Text$,CrLf$)-1 ' PARSECOUNT is too big by 1?
DIM AM(1:RecordCount) AS STRING
j=0:n=1
WHILE n<RecordCount
k=INSTR(j+1,Text$,CrLf$)
AM(n)=MID$(Text$,j+1,k-j-1)
INCR n:j=k+LEN(CrLf$)-1
WEND
Text$=""
ARRAY SORT AM() FOR RecordCount
OPEN"OUTPUT.DAT" FOR OUTPUT AS #1
FOR i&=1 TO RecordCount

END FUNCTION
---------------------------------------------
Product Enhancement Idea is below
---------------------------------------------
#COMPILE EXE
GLOBAL MemIN() AS STRING
FUNCTION PBMAIN() AS LONG
LOCAL n AS LONG:LOCAL RecordCount AS LONG
CrLf$=CHR$(13,10)
OPEN "INPUT.DAT" FOR BINARY AS #1
GET$ #1,LOF(1),MemIN(CrLf$):CLOSE #1' See note below
ARRAY SORT MemIN()' Normal sort of an array now allocated in memory
OPEN"OUTPUT.DAT" FOR BINARY AS #1
PUT$ #1,MemIN(CrLf$):close# 'Reverse of Get$ for a string array
END FUNCTION
---------------------------------------------
'*GET$ action with an unallocated string
' array as "sVar"
' First; detect an unallocated string array and start allocation process
' Second; set PARSECOUNT string delimit$ to
' CrLf$ string (default value could be
' chr$(13,10))
' Third; iii&=0
' Fourth; Input file making text breaks at
' delimit$ and and assign to MemIN(iii&++)
' At EOF set UBOUND(MemIN) to i&&&
' Another way of looking at this logic is
' with the Javascript SPLIT method. You
' could read the entire file into a string
' like TEXT$ and use SPILT to create a new
' string array, e.g.
'
' NewArray=Text$.split(CrLf$)
'
' but this takes more than twice as much
' memory. Better to embed the logic in
' ML inside GET$
'///////////////////////////////////////////
' GENERALIZATION
' A two dimensional array would be very
' convenient for files having separate
' delimeters for FIELD separation and LINE
' separation, e.g.
'
' "AAA|BB|C|DDDD"
' "FFFFFFFF|GGGGG|HHHHHHHHHH|KKKKKKKKK"
'
' (A fixed number variable length items,
' 4 in this case, in a variable length
' file - 2 records in this case)
'
' GLOBAL MemIN(,) AS STRING
' GET$ #1,LOF(1),MemIN("|",CHR$(13,10))
'
' SPLIT METHOD
' I use the split method all the time in ' javascript. It saves a lot of
' writing and documents a program pretty ' well. I would love to see it
' or a similar function in PB products, e.g.
'
' ' Unallocated_Array=SPLIT(TEXT$,"|")
'