Results 1 to 2 of 2

Thread: put into binary file

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    put into binary file

    without explaining too much detail as to why (its a long story) I need to be able to do the following in VB6:

    1) given a double array full of values, store its exact binary representation in memory as a binary file.

    converting to text wont work for me. I am trying to send a file to a colleague for troubleshooting. its an input to a dll and it has some sort of weird numerical error going on. I send a text representation of the array and it does not duplicate the issue. i cant send him the code to generate the error (another long story).

    I suspect there is an issue with irrational binary representations of doubles ...

    anyone know how to do #1 above?

    any help greatly appreciated!

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: put into binary file

    You can save the double array directly to disk and load it back.

    Example:
    Code:
    Private Sub Form_Load()
        Dim d() As Double
        ReDim d(3) As Double
        d(0) = 3424: d(1) = 66720: d(2) = 56: d(3) = 99
        
        Dim intFF As Integer: intFF = FreeFile
        Open "C:\test.txt" For Binary Access Write As #intFF
            Put #intFF, , d
        Close #intFF
    End Sub
    The result is a 32 byte file which is correct since 4 values, 8 bytes each for double data type.

    You can then load the file back into the array.

    Is this what you mean?

    Also, if the dimensions of the array are not known/it is a dynamic array, you will need to write the dimensions of the array to the start of the file so you know how to ReDimension the array back when reading the file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width