Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Help reading binary file

I would like to open the data contained in a binary file in to an
excel worksheet. I can open the binary file in python with the
following script

################################################## #######################
def rsvdat(filename):
header=array.array('c') # Skip header
memsize=array.array('L')
file=open(filename,'rb')
# Define header as 1032 bytes dont use it
header.fromfile(file,1032)
# Define buf size as 4 byte long int
memsize.fromfile(file,1)
# This will give the number of data points (4 bytes floats)
totpts=int(memsize[0]/4.0)
v=array.array('f')
v.fromfile(file,totpts)
file.close()
v=Numeric.array(v) #convert to Numeric type to use
slicing ops
vc=Numeric.zeros(totpts/2,'D')
vc.real=v[::2]
vc.imag=v[1::2]
return vc

Now I want to do it in VBA, so far I got
'================================================= =============
Sub rsvd()
'================================================= =============
Dim Rdata As String
Dim BinaryFile As String
Dim numPts As Long
Dim SVpoint As Single ' 4 bytes right ?
'================================================= =============


FileNum = FreeFile ' Supply next available number
BinaryFile = Application.GetOpenFilename
'Workbooks.Add
Set NewSheet = Sheets.Add(Type:=xlWorksheet)
'NewSheet.Name = BinaryFile 'THIS DOESN"T WORK
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NewSheet.Select

Open BinaryFile For Binary Access Read As #FileNum
Seek #FileNum, 1032 ' Skip header
'numPts = Input(4, #FileNum) DONT LIKE IT, WANTS STRING
Input #FileNum, numPts "WORKS" BUT IT DOESNT RETURN RIGHT VALUE
Range("A1").Value = "Now the data :"
'================================================= =============
' Loop to get total number of points
For k = 1 To numPts
Input #FileNum, SVpoint
Range(Cells(k, 2), Cells(k, 2)).Value = otro
Next k
'================================================= =============
Close #FileNum
End Sub
'================================================= =============

at this point I am stuck !
If I cannot retrieve the total number of points (after 1032 bytes) i
cannot loop, furthermore
if I get the next value (should be a float) always return 0.

Am I using the Input # function correclty, or is there an alternative
to get data form the binary
file

TIA

Luis
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Help reading binary file


workbooks.add
activesheet.name="BINARYFILE"
...

use FileLEN to get the length of file.


cant use INPUT on binary files, you'll need GET/PUT instead.
see VBA help on GET statement

sorry to be brief, hope it gets you on the way.

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Luis wrote :

I would like to open the data contained in a binary file in to an
excel worksheet. I can open the binary file in python with the
following script

FileNum = FreeFile ' Supply next available number
BinaryFile = Application.GetOpenFilename
'Workbooks.Add
Set NewSheet = Sheets.Add(Type:=xlWorksheet)
'NewSheet.Name = BinaryFile 'THIS DOESN"T WORK
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NewSheet.Select

SNIP


Am I using the Input # function correclty, or is there an alternative
to get data form the binary
file

TIA

Luis


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Help reading binary file

That was actually all I needed to know
its is on its way to work now!

"keepITcool" wrote in message ...
workbooks.add
activesheet.name="BINARYFILE"
..

use FileLEN to get the length of file.


cant use INPUT on binary files, you'll need GET/PUT instead.
see VBA help on GET statement

sorry to be brief, hope it gets you on the way.

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Lu

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
reading from another file and pasting to current file, "combobox" Darius New Users to Excel 1 September 26th 05 07:13 AM
Solver returns non binary answer in binary constrained cells Navy Student Excel Worksheet Functions 6 September 1st 05 03:11 PM
How can I read/write file with binary format??? NC Excel Programming 2 May 27th 04 09:35 AM
Reading from file Asif[_3_] Excel Programming 4 November 16th 03 05:28 AM
Excel binary file format Rob Bovey Excel Programming 1 November 8th 03 12:04 PM


All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"