Data Text Files
Blitz3D Forums/Blitz3D Programming/Data Text Files| 
 | ||
| Hi, it's been a while since I posted here...hope it's still active. Does anyone know if there's a way to get Blitz to write to a text file in a 2D format. Like this... 00110100 00101101 00400201 20301104 38848832 00300500 Whenever i try, it starts a new line every time, like this.... 0 0 1 1 0 1 0 0 etc... Can anyone help me with this? Thank you ^_^ | 
| 
 | ||
| 
dim myarray(10,10)
;populate array
for x=0 to 10
	for y=0 to 10
		myarray(x,y)=rand(0,9)
	next
next
;create file and write to it
outfile=writefile("test.txt")
if outfile<>0 then 
	for y=0 to 10
		lineoftext$=""
		for x=0 to 10
			lineoftext$=lineoftext$+str(myarray(x,y))
		next
		writeline outfile,lineoftext
	next
	closefile outfile
else
;error occured opening file to write
endif 
something along those lines should work... | 
| 
 | ||
| Thank you so much...VERY helpful...But I don't want random values.  I want to take information from a TYPE to do this. type A field X,Y,frame end type Is there a way to make A\Frame determine what number is saved to the file? Thank you. | 
| 
 | ||
| Unless your Type list is int he right order for X and Y's you're making things more complicated for yourself. Is it necessary to have the text file in the format presented? It may be easier to just save the entire Type list, including all fields... 
;create file and write to it
outfile=WriteFile("test.txt")
For IterA.A=Each A
	WriteLine outfile,(Str(IterA\X)+" , "+Str(IterA\Y)+" , "+Str(IterA\Frame))
Next
CloseFile outfile
;create file and write to it
infile=ReadFile("test.txt")
sline$=ReadLine(infile)
While Not(Eof(infile))
	
	XLine$=Trim$(Left$(sline$),Instr(","))
	YLine$=Trim$(Left$(sline$),Instr(","))
	FrameLine$=Trim$(Right$(sLine$),Len(sLine$-Len(YLine$)))
	
	newA.A = New A
	
	NewA\X=XLine$
	NewA\Y=YLine$
	NewA\Frame=FrameLine$
	sline$=ReadLine(infile)
Wend
CloseFile outfile
 |