Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Blitz => Topic started by: Clyde on May 14, 2009
-
Dear fellow friends,
I always get into trouble with trying to use I/O streams; mostly as I don't use them on a day to day basis, so the grey matter forgets.
Whats supposed to happen is per line 8 entry's, and 12 lines. However thats not the case with the code below. :(
Const AmountX=8
Const AmountY=12
Global TotalInfo=(AmountX*AmountY)
Dim Info( TotalInfo )
For a=0 To TotalInfo-1
Info(a)=Rand(0,12288)
Next
SaveInfo( "BuddiesGirl", ".bas" )
Function SaveInfo( SaveFile$, Extension$=".txt" )
FileOut=WriteFile( SaveFile$+Extension$ )
;
; sort out file values
;
For Index = 0 To TotalInfo-1
;
; Have we reached the very Last entry?
;
If Index = TotalInfo-1 Then
WriteLine Fileout, Str( Info(Index))+" }"
Else
If LineCount < AmountPerLine Then
;
; Carry on as usual with adding a comma between data.
;
WriteLine FileOut, Str(Info( Index ))+","
Else
;
; Cool, I see we have reached the end of the current line, signified by adding ,_
;
WriteLine FileOut, Str(Info( Index ))+",_"
LineCount = 0
End If
End If
LineCount = LineCount + 1
Next
CloseFile FileOut
End Function
Thanks in advance,
Mike F.
-
Const AmountX=8
Const AmountY=12
Global TotalInfo=(AmountX*AmountY)
Dim Info( TotalInfo )
For a=0 To TotalInfo-1
Info(a)=Rand(0,12288)
Next
SaveInfo( "BuddiesGirl", ".bas" )
Function SaveInfo( SaveFile$, Extension$=".txt" )
Local tmpText$ = ""
FileOut=WriteFile( SaveFile$+Extension$ )
;
; sort out file values
;
For Index = 0 To TotalInfo-1
;
; Have we reached the very Last entry?
;
If Index = TotalInfo-1 Then
WriteLine Fileout, Str( Info(Index))+" }"
Else
If LineCount < AmountX-1 Then
;
; Carry on as usual with adding a comma between data.
;
tmpText = tmpText + Str(Info( Index )) + ","
Else
;
; Cool, I see we have reached the end of the current line, signified by adding ,_
;
tmpText = tmpText + Str(Info( Index ))+",_"
WriteLine fileout, tmpText
tmpText = ""
LineCount = 0
End If
End If
LineCount = LineCount + 1
Next
CloseFile FileOut
End Function
-
Many thanks Zawran.
One small thing though, the first line of the data is 8 which is how it should be, but from then on it's in series of 7, until the last line which has a lone some figure.
-
Const AmountX=8
Const AmountY=12
Global TotalInfo=(AmountX*AmountY)
Dim Info( TotalInfo )
For a=0 To TotalInfo-1
Info(a)=Rand(0,12288)
Next
SaveInfo( "BuddiesGirl", ".bas" )
Function SaveInfo( SaveFile$, Extension$=".txt" )
Local tmpText$ = ""
FileOut=WriteFile( SaveFile$+Extension$ )
;
; sort out file values
;
For Index = 0 To TotalInfo-1
If LineCount < AmountX-1 Then
;
; Carry on as usual with adding a comma between data.
;
tmpText = tmpText + Str(Info( Index )) + ","
LineCount = LineCount + 1
Else
;
; Cool, I see we have reached the end of the current line, signified by adding ,_
;
tmpText = tmpText + Str(Info( Index ))+",_"
WriteLine fileout, tmpText
tmpText = ""
LineCount = 0
End If
Next
WriteLine Fileout, " }"
CloseFile FileOut
End Function
-
Cheers Big Z :)