Author Topic: [B2D] Streaming Blues  (Read 3054 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
[B2D] Streaming Blues
« 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. :(

Code: [Select]
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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: [B2D] Streaming Blues
« Reply #1 on: May 14, 2009 »
Code: [Select]
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

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: [B2D] Streaming Blues
« Reply #2 on: May 17, 2009 »
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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: [B2D] Streaming Blues
« Reply #3 on: May 17, 2009 »
Code: [Select]
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

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: [B2D] Streaming Blues
« Reply #4 on: May 19, 2009 »
Cheers Big Z :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: