Duh!
forgetting that mid$(s,1) copies from the first character of the string, not the second. Will they ever learn?
Announcement
Collapse
No announcement yet.
Problem reading UDT as strings from binary file
Collapse
X
-
Originally posted by Chris Holbrook View PostI have loaded each row of each array into a string (not asciz) , preceded by an identifying character
Code:' "C" is an array identifier in this case sTemp(n) = "C" + PEEK$(VARPTR(gCA(i)), SIZEOF(tCPH)) ' etc, then .... put# hfile, sTemp()
Leave a comment:
-
-
Code:OPEN sAppName FOR [B]BINARY[/B] AS #hfile FILESCAN #hfile, RECORDS TO nrecs DIM sTemp(0 TO nrecs - 1) ' sTemp is a string array GET #hfile, 1, [B]sTemp()[/B]
With a dynamic string array, it is assumed the file was written in the PowerBASIC and/or VB packed string format using PUT of an entire string array. If a string is shorter than 65535 bytes, a 2-byte length WORD is followed by the string data.
You may be running into length words and/or array bound violations, the latter of course can cause all kinds of weird things to happen.
Of course, "CODE [which stores the data] NOT SHOWN" so this may not be a consideration at all.
Leave a comment:
-
-
Problem reading UDT as strings from binary file
Searching for a way of storing a variable number of different array (both strings & UDTs) and a couple of non-array UDTs, I have loaded each row of each array into a string (not asciz) , preceded by an identifying character. The file resulting from this looks convincing.
Reloading the file looks like this:
Code:hfile = FREEFILE OPEN sAppName FOR BINARY AS #hfile FILESCAN #hfile, RECORDS TO nrecs DIM sTemp(0 TO nrecs - 1) ' sTemp is a string array GET #hfile, 1, sTemp() CLOSE #hfile DIM gCA(%lotsandlots) AS GLOBAL tCPH DIM gEB(%lotsandlots) AS GLOBAL STRING FOR i = 0 TO UBOUND(sTemp) SELECT CASE LEFT$(sTemp(i),1) CASE "F" POKE$ VARPTR(Fstuff), MID$(sTemp(i),1) ' Fstuff is a UDT CASE "C" POKE$ VARPTR(gCA(lcx)), MID$(sTemp(i),1) INCR lcx CASE "E" gEB(lex) = MID$(sTemp(i),1) INCR lex END SELECT NEXT REDIM PRESERVE gCA( 0 TO lcx) AS GLOBAL tCPH REDIM PRESERVE gEB( 0 TO lex) AS GLOBAL STRING
Where am I going wrong?Tags: None
-
Leave a comment: