Load strings and numbers from file?
BlitzMax Forums/BlitzMax Beginners Area/Load strings and numbers from file?
| ||
| I have a file with some strings, ints and floats on different lines, how do I open it and then get the information out as the right types into my variables? (I tried this and failed so far) |
| ||
| You might want to convert this - or just rip out the few bits you need: http://www.blitzbasic.com/codearcs/codearcs.php?code=1022 or just use something like this: file=writeFile("myfile.dat")
If Not file RuntimeError "could not open file myfile.dat"
writeline file,"Hello"
writeline file,2046
writeline file,3.14
writeline file,"Goodbye"
Closefile file
file=OpenFile("myfile.dat")
If Not file RuntimeError "could not open file myfile.dat"
text$ = ReadLine(file)
Print text$
integer% = ReadLine(file)
print integer%
real# = ReadLine(file)
print real#
text$ = ReadLine(file)
Print text$
Closefile file |
| ||
| what do the $, % and # mean and are they necessary? thanks |
| ||
| $ = String % = Integer # = Float |
| ||
| They are necessary because they tell blitzmax what type of variables they are. % isn't actually needed because if not declared a variable is assumed to be an integer. Floats are for numbers that aren't counting numbers like 12.0564 . Strings are for text like "Hello World". Just in case you didn't know before. |
| ||
| But don't use those stupid symbols, use text:String = integer:Int = real:Float = :) Aaron "I've hated those symbols forever!" Koolen |