Read Floatvalues out of a file
Blitz3D Forums/Blitz3D Programming/Read Floatvalues out of a file
| ||
Hello, i want to read Float values out of ascii (.txt) file. All values are seperated with a tab. So it is no problem to identify every value. The Problem is to make one Floatvalue out of the single bytes the values consist of. Readfloat doesnt work cause the file wasnt created by blitz. |
| ||
right, So what you need to do:Dim numbers(maxnumbers) filehandle=readfile(filename$) while not eof(filehandle) receivedline$=readline(filename$) readstart=1 currentnumber=0 repeat nexttab=instr(receivedline$,chr$(9),readstart) ;Chr$(9)? thats tab, right? if nexttab>0 then thisstring$=mid$(receivedline$,1,nexttab) ;This will contain your number. numbers(currentnumber)=thisstring$ currentnumber=currentnumber+1 receivedline$=mid$(receivedline$,nexttab+1) endif until nexttab=0 End while After which, all of your numbers will be stored in the numbers() array, from numbers(0) till numbers(currentnumber-1). The above code is untested, let me know of any problems- i dont have blitz here at work. |
| ||
If it's a text file, can't you just read it in as a string and then use Float() to convert it? |
| ||
[edit] I was in a bad mood. |
| ||
Thank you, i never thought that it is possible to convert a string into a number without any special commands or programming, only float=string. thanks a lot for the fast response and sorry for my english (Berlin/Germany) |
| ||
Looking at my code above, it could be done easier, but you get the gist :) |