Author |
Topic: Unicode in data file (Read 533 times) |
|
avdiel1946
New Member
member is offline


Posts: 1
|
 |
Unicode in data file
« Thread started on: Jun 29th, 2015, 09:47am » |
|
I am building a simple address book. My system is windows 8.1 on an hp 23-h050
all-in-one desktop.
Data input starts here ....
msg$ = "New Record #: " print tab(60-len(msg$),8) msg$ : colour 7 colour 3 : print tab(60,8) str$((numrec/12)+1) temp$(0) = chr$(numrec + 1) + chr$(13) + chr$(10) colour 14 : print tab(2,51) "Enter QUIT to terminate add address...." colour 7
.... and ends here:
msg$ = "e-mail: " print tab(60-len(msg$),30) msg$ print tab(2,55) spc(160) input line tab(2,55) "Enter E-MAIL -> " ans$ if ans$ = "" then ans$ = "unknown" if ans$ = "quit" then endproc temp$(11) = ans$ + chr$(13) + chr$(10) colour 5 : print tab(60,30) ans$ : colour 7
Saving the data:
print tab(2,55) "Are these entries correct? (y/n)" : ans$ = get$ print tab(2,55) spc(160) if ans$ = "y" or ans$ = "Y" then print tab(2,55) "Saving data...." path$ = @dir$ + "Address.txt" addr = openout(path$) for i = 0 to numrec print #addr, Address$(i) next for i = 0 to 11 print #addr, temp$(i) next close #addr print tab(2,55) spc(160) endproc else print tab(2,55) spc(150) close #addr endproc endif
The problem is in writing the new data to the disc. The Address$ array writes fine
but the temp$ array does not. Printing the temp$ array to the screen produces the
proper result except for temp$(0). This is what is written to the data file:
ඩഊ湵湫睯൮ഊ湵湫睯൮ഊ湵湫睯൮ഊ湵湫睯൮ഊ湵湫睯൮ഊ湵湫睯൮ഊ湵湫睯൮ഊ湵湫睯൮ഊ湵湫睯൮ഊ湵
湫睯൮ഊ湵湫睯൮ഊ
Why does the Address$ array work but not the temp$ array?
How do I fix this?
thanks....
|
|
Logged
|
|
|
|
rtr2
Guest
|
 |
Re: Unicode in data file
« Reply #1 on: Jun 29th, 2015, 2:47pm » |
|
on Jun 29th, 2015, 09:47am, avdiel1946 wrote:Why does the Address$ array work but not the temp$ array? |
|
In Acorn versions of BBC BASIC (e.g. ARM BASIC as used under RISC OS) PRINT# and INPUT# can write and read arbitrary strings containing any characters, even binary data. However BBC BASIC for Windows (along with the Z80 and MS-DOS versions of BBC BASIC) use a different file format for string data, which has the advantage of being more 'standard' but which cannot be used to store arbitrary binary strings, specifically not strings containing the CHR$(13) CR character which is used as a delimiter.
This may be relevant to your issue because I notice that the temp$(0) record contains binary data:
Code:temp$(0) = chr$(numrec + 1) + chr$(13) + chr$(10) Here, if numrec happened by chance to be 12 the first character of the string would be CHR$(13) and that would break the BB4W string file format. I assume this really is supposed to be CHR$() rather than STR$()!
If this is indeed the cause of your problem you will need to devise an alternative way of storing the data. As you are seemingly storing arrays you may find this Wiki article helpful:
http://bb4w.wikispaces.com/Reading+and+writing+arrays+in+files
Richard.
|
« Last Edit: Jun 30th, 2015, 05:32am by rtr2 » |
Logged
|
|
|
|
|