Writing text area to file

BlitzPlus Forums/BlitzPlus Programming/Writing text area to file

dirkduck(Posted 2003) [#1]
Hey everyone. This should be a really simple problem, but for some reason I can't get it to work correctly. I'm working on just a simple notepadish part of a project, and I can't save/load text files from a text area. I can load it in line-by-line and then add a char(10) or char(13) to the end of the line to make a line break, and it looks fine, but then trying to save the file I get all sorts of problems. Since there is only a writeline (I believe writestring adds some information to the beginning of the string), im trying to break the textareatext string into lines with this:
	f=WriteFile(file$)
	temp_len=0
	temp$=TextAreaText(g_text) ;whole file
	For i=0 To TextAreaLen(g_text,2) ;count lines	
		WriteLine(f,Mid$(temp$,temp_len,TextAreaLineLen(g_text,i)))
		temp_len=TextAreaChar(g_text,i+1)
	Next
	CloseFile(f)
   


but it doesn't keep the line "structure" and then opening it in the actual notepad it has the added char(10/13)'s (showing up as boxes). I'm kind of stumped on how to accomplish this (maybe im just missing something...). Thanks for any help.


Floyd(Posted 2003) [#2]
TextAreaText has CR/LF at the of each line except the last.
WriteLine writes a string and appends a CR/LF at the end.
So this should do what you want.

WriteLine f, TextAreaText(g_text)



dirkduck(Posted 2003) [#3]
Hey Floyd, thanks for the reply. That worked fine for saving if I write directly into the text area, but if I load some text in from a file, it writes it out all as one line (when viewed in notepad). Heres my loadfile function, im sure it's the culprit:

Function open_file(file$)
	SetTextAreaText(g_text,"",2)
	f=ReadFile(file$)
	While Not Eof(f)
		temp$=ReadLine(f)+Chr(13)
		AddTextAreaText(g_text,temp$)
		temp$=""
	Wend
	
	CloseFile(f)
End Function


Could someone tell me whats wrong with it? Thanks.


dirkduck(Posted 2003) [#4]
Finally got it working, just needed to change:
temp$=ReadLine(f)+Chr(13)

to:

temp$=ReadLine(f)+Chr(13)+Chr(10)

incase anyone has the same problem and wants to know :).