read file

Blitz3D Forums/Blitz3D Beginners Area/read file

AJ00200(Posted 2009) [#1]
I have been having some trouble geeting readfile and write file to work
[code]
Function deposit()
String$=""
howmuch#=Input("How much would you like to deposit?")
Print "Make sure a valid flash drive is pluged in!"
Print "Press any key"
Print " "
WaitKey()
file$=ReadFile("f:\key.txt")
While Not Eof(file)

String$=String+ReadString$(file)
Wend
CloseFile(file)
Print contents
End Function
[code]


AJ00200(Posted 2009) [#2]
Help!!!


_PJ_(Posted 2009) [#3]
From what I see there, I think this might help.

There's no write in the above, adn I should mention that iof you WriteInt, String or Float, then you need to Read Int, String or Float to retieve it.

Writefile will wipe your previous entries, so use Openfile to append.

I changed the input to float as money usually comes with decimals, but feel free to change it :)


BAD ME didnt check code.
Fixed below :)




AJ00200(Posted 2009) [#4]
Thanks that looks great. I'll try it out right now.

www.aj00200.htmlplanet.com
AJ00200


AJ00200(Posted 2009) [#5]
What you have looks good, but every time I try to run the program, it says
end function without function


AJ00200


big10p(Posted 2009) [#6]
Remove the EndIf from the second function. You also need to add a Wend in the last function.


AJ00200(Posted 2009) [#7]
No thats not it. I already have. It still says that.


AJ00200(Posted 2009) [#8]
Your missing the Wend in the third func. Where does it go?
Before or after close file?


_PJ_(Posted 2009) [#9]
Sorry, I scribbled that out quickly with some copy and pastes.

This is correct:
Function Withdrawal(fAmount#)
		Accountfile=OpenFile(Filename$)
		SeekFile(Accountfile,FileSize(Accountfile))
		WriteFloat Accountfile,fAmount#
		CloseFile Accountfile
End Function

Function Deposit(fAmount#)
		Accountfile=OpenFile(Filename$)
		SeekFile(Accountfile,FileSize(Accountfile))
		WriteFloat Accountfile,fAmount#
		CloseFile Accountfile
End Function

Function CheckBalance#(fAmount#)
		Transactions#=0		
		Accountfile=OpenFile(Filename$)
		While Not Eof(Accountfile) 
			Transactions#=Transactions#+ReadFloat#(Accountfile)
		Wend
		CloseFile Accountfile
		Return Transactions#
End Function



AJ00200(Posted 2009) [#10]
Thanks a lot. No errors anymore.
AJ00200