Files Handling?
Blitz3D Forums/Blitz3D Beginners Area/Files Handling?
| ||
When I create the notepad and put Data in such my name, age and I have create file handling in blitzbasic code and it is reading it from notepad(for example FileName$="PeopleData.txt") FileName$="PeopleData.txt" PeopleFile=WriteFile(FileName$) how can I print them in Windows mode do I put print PeopleFile but when it print and it all number! Do I have convert number to string or somethings? |
| ||
outfile = writefile("PeopleData.txt") writeline outfile,"This is a line of text" writeline outfile,"This is another line of text" writeline outfile,"End of File" ;open in notepad it should look like what you are after closefile outfile end |
| ||
I think he is printing PeopleFile, the integer file handle from WriteFile.PeopleFile = ReadFile( "sample.txt" ) While Not Eof( file ) Print ReadLine( file ) Wend CloseFile PeopleFile WaitKey |
| ||
what I am trying to do is this on my notepad I put some name and age like this David 31 Paul 28 Dan 25 then save it as PeopleData.txt then When code them and somethings isnt right because I want to read the data from Txt files to print on the window mode like this Graphics 640,480,16,2 SetBuffer BackBuffer() FileName$="PeopleData.txt" PeopleData=WriteFile(FileName$) If PeopleData<>0 Print "Data read from < " + FileName$ + " >" Else Print "Could Not Open File: <" + FileName$ + " >" EndIf While Not Eof(PeopleData) print Readline (PeopleData) Wend CloseFile PeopleData WaitKey End Why isnt printing on Window when it was reading from Txt files!? |
| ||
Close the file then open it for reading with ReadFile. |
| ||
because you open the file stream with "WriteFile", but you need to use "ReadFile". "WriteFile()" is for writing something to your disc. "ReadFile()" opens a file and reads the content. FileName$="PeopleData.txt" PeopleData:TStream=ReadFile(FileName$) ... Local Data$ While Not Eof(PeopleData) Data= Readline (PeopleData) Print Data Wend CloseFile PeopleData Did you see also this: "WriteFile()" will clear an existing file for writing new content in it. So after using WriteFile() your txt file will be empty. |
| ||
ahhh right thanks, and now it is print name in console mode but how do I print in window mode?Graphics 640,480,16,2 SetBuffer BackBuffer() FileName$="PeopleData.txt" PeopleData=ReadFile(FileName$) If PeopleData<>0 Print "Data read from < " + FileName$ + " >" Else Print "Could Not Open File: <" + FileName$ + " >" EndIf While Not Eof(PeopleData) PData$= ReadLine (PeopleData) Print PData$ Wend CloseFile PeopleData WaitKey End |
| ||
It alright and I have changed print to text to print on window mode :) thank you everyone for helping *big thump up* |