View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Maxi[_2_] Maxi[_2_] is offline
external usenet poster
 
Posts: 94
Default Reading binary file

http://www.justlottery.com/dwnld/INDSuperlotto.rtl
http://www.justlottery.com/dwnld/INDThunderball.rtl
http://www.justlottery.com/dwnld/INDFast.rtl

Can anybody help reading the above three binary file in excel through a
vba? The following macro reads the first file but not through Excel
VBA, it reads to Visual Basic.

Can anybody understand the logic of the below code and convert into
Excel macro?

Option Explicit

Private Type TREC
No As Integer
D As Integer
M As Integer
Y As Integer
Numbers(1 To 10) As Integer
End Type


Private Sub Command1_Click()
Const Fle$ = "c:\t\t.rtl"
Dim B(1 To 28) As Byte
Dim Channel%, L9&, L8&, Max&
Dim Rec As TREC


Me.Cls


Channel = FreeFile
Open Fle For Binary Access Read As Channel
' Get 4 byte header - No of lines
Get #Channel, 1, Max&
Me.Print Max
' --- Now the 28 byte records
For L9 = 1 To 10
Get #Channel, , Rec
Disp Rec.No
Disp Rec.D
Disp Rec.M
Me.CurrentX = Me.CurrentX + TextWidth("XX")
Disp Rec.Y
For L8 = 1 To 10
Disp Rec.Numbers(L8)
Next
Me.Print ""
Next


Close #Channel
End Sub


Private Sub Disp(N%)
Dim S$
S$ = Trim$(N)
Me.CurrentX = Me.CurrentX + TextWidth("XXX") _
- TextWidth(S$)
Me.Print S$;
End Sub


Private Sub Form_Load()
Me.AutoRedraw = True
Me.Width = Screen.Width * 0.75
End Sub