reading binary files, can't be done 
Author Message
 reading binary files, can't be done

Here's a simple question:  Write a file with microsoft fortran
powerstation with the command:

REAL* 4 A, B,C
WRITE(2) A, B, C

Is there anyway to read this file in Microsoft Visual Basic and get
real values of A,B and C?  We have tried most everything.  If you have
a VB code snippet that works, please email.  Note there is no problem
reading a binary file created withVB.
===================================================
Visit my homepage at http://www.*-*-*.com/ ~rlang



Tue, 24 Nov 1998 03:00:00 GMT  
 reading binary files, can't be done

I have used Fortran for years, but here's my two cents. I assume the data
is stored as a 4 byte real, which is the same format as the VB Single
data type, therefore:

Dim A As Single, B As Single, C As Single
Open "filename" For Binary As #1
Get #1, , A
Get #1, , B
Get #1, , C
Close #1

Good Luck,
Mike



Tue, 24 Nov 1998 03:00:00 GMT  
 reading binary files, can't be done


writes

Quote:
>Here's a simple question:  Write a file with microsoft fortran
>powerstation with the command:

>REAL* 4 A, B,C
>WRITE(2) A, B, C

>Is there anyway to read this file in Microsoft visual basic and get
>real values of A,B and C?  We have tried most everything.  If you have
>a VB code snippet that works, please email.  Note there is no problem
>reading a binary file created withVB.
>===================================================
>Visit my homepage at http://www2.netdoor.com/~rlang

Please send in the file contents and I'll 'av a look...

      \\?//    

/-----\(_)/-----------------------------------------------------\

| .oooO   Oooo.   Head of Software Development, Impact Software |
| (   )___(   )      1 Percy Street, Sheffield, S3 8AU, England |
\--\ ( _|_ ) /--------------------------------------------------/
    \_)   (_/



Fri, 27 Nov 1998 03:00:00 GMT  
 reading binary files, can't be done


Quote:
>writes
>>Here's a simple question:  Write a file with microsoft fortran
>>powerstation with the command:

>>REAL* 4 A, B,C
>>WRITE(2) A, B, C

>>Is there anyway to read this file in Microsoft visual basic and get
>>real values of A,B and C?

If the fortran file is opened with form='binary',
the following seems to work:

Declare Function hread Lib "kernel32" Alias "_hread" (ByVal hFile As Long, lpBuffer As Any, ByVal lBytes As Long) As Long
Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long
Declare Function lopen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long

Dim x(3) As Single
filehandle& = lopen("my_fortran_binary_file", 0)
dummy& = hread(filehandle&, x(1), 12)
For i = 1 To 3
debug.print x(i)
Next i
dummy& = lclose(filehandle&)

If the file is opened with form='unformatted',
insert a line to read a two byte header:
dummy&=hread(filehandle&, tmp%, 2).

I don't know the exact format for 'unformatted' fortran file.  
It has some paddings.

Hope this helps.

Bo Yu
Brookhaven National Lab



Fri, 04 Dec 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Binary files - what am I doing wrong?

2. VB3 Binary FILES READ READ READ

3. File opened for Binary read BUT instr doesn't seem to work

4. 'Canned' data in VB program

5. Binary Files in BASICA - Can It be done?

6. reading binary file and writing into a random access file

7. Reading File Header Info (Binary Files)

8. VB -- Long File Name , Fast Binary File Read / Write , interface with DLL

9. Reading File Header Info (Binary Files)

10. Reading File Header Info (Binary Files)

11. ADO thinks DBMS is done, but DBMS ain't done

12. Cans access2.0 engine access btrieve files?

 

 
Powered by phpBB® Forum Software