Write type is ok but read type not.

Blitz3D Forums/Blitz3D Beginners Area/Write type is ok but read type not.

Fernhout(Posted 2007) [#1]
What is wrong on the following code.
		Filein =ReadFile ("Data/TopScore.Dat")
		;If file Not exist Then creat one.
		If Filein =0
			FileOut=WriteFile("Data/TopScore.Dat")
			If fileout = 0 Then End; We expand this later
				For x = 1 To 10
					TP_HighScore(x)\Name$ = "NOBODY"
					WriteString (FileOut,TP_HighScore(x)\Name$)
					TP_HighScore(x)\Score = 0
					WriteString (FileOut,TP_HighScore(x)\Score)
					TP_HighScore(x)\date$ = CurrentDate$()
					WriteString (FileOut,TP_HighScore(x)\Date$)
					TP_HighScore(x)\Level = 0
					WriteString (FileOut,TP_HighScore(x)\Level)
				Next
			CloseFile(FileOut)
			Filein =ReadFile ("Data/TopScore.Dat")
		EndIf
		For x = 1 To 10
			TP_HighScore(x)\Name$ = ReadString$( filein )
			TP_HighScore(x)\Score = ReadInt( filein )
			TP_HighScore(x)\Date$ = ReadString$( filein )
			TP_HighScore(x)\Level = ReadByte( filein )
		Next
	    CloseFile(filein)


To write to a file is no problem. All the data is written. But when i want to read this back in to the program i only get the first line in the rest stays empty.


GfK(Posted 2007) [#2]
You're writing data out as Strings, then reading it back as Strings (ok) and Int/Byte (not ok). That's the problem.

You MUST read/write in the same format.


Fernhout(Posted 2007) [#3]
Thanks mate. I see the problem now. I was writing this late in the evening and could not see my misstakes. I see it now. I write all the data as a sting. While it sepose to be string - int - string - byte.
I try it again and now its working. Thanks again.