Files Handling?

Blitz3D Forums/Blitz3D Beginners Area/Files Handling?

Hotshot2005(Posted 2016) [#1]
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?


Matty(Posted 2016) [#2]
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




Floyd(Posted 2016) [#3]
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



Hotshot2005(Posted 2016) [#4]
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!?


Floyd(Posted 2016) [#5]
Close the file then open it for reading with ReadFile.


Midimaster(Posted 2016) [#6]
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.


Hotshot2005(Posted 2016) [#7]
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



Hotshot2005(Posted 2016) [#8]
It alright and I have changed print to text to print on window mode :)

thank you everyone for helping *big thump up*