Reading a strange binary

 BBS: Inland Empire Archive
Date: 03-10-92 (21:44)             Number: 84
From: STEVE HALKO                  Refer#: NONE
  To: IAN HUITSON                   Recvd: NO  
Subj: Reading a strange binary       Conf: (2) Quik_Bas
IH>Each record in the file contains a 2 byte integer representing the
IH>date, and 4 byte single precision values for each of the high,
IH>low, close, open, volume and open interest for a given
IH>date(record).  In all each record is 26 bytes long.  The date
IH>system uses 1/1/83 (mm/dd/yy) as the base date
IH>ie day 1 = 1/1/83

  I'd define each record as a user-defined TYPE:

  TYPE BinaryData
    BaseDate AS INTEGER
    High AS SINGLE
    Low AS SINGLE
    Clos AS SINGLE
    Opn AS SINGLE
    Vol AS SINGLE
    OpenInterest AS SINGLE
  END TYPE
  DIM MyData AS BinaryData
  OPEN "MYFILE.DAT" FOR BINARY AS #1
  GET #1,,MyData
  '(Do what you want with the data here)
  CLOSE
  END

  This will read each record in.  To access any one element in the
  record, use the "period" notation, e.g. the high would be accessed
  with variable name MyData.High, the date as MyData.BaseDate, etc.

  The only other problem is converting the base date to a real date.
  For that, you might want to use a 3rd party library.  Lots of them
  have routines for doing date arithmetic.  Also, check the back posts
  on this echo - every so often some date arithmetic code pops up.

  Also note that the names of the individual elements in the TYPE
  definition have to be chosen as something other than QB keywords -
  that's why I stayed away from Open, Close, and Date as variable names.

 * SLMR 2.1a * "They pelted us with rocks and garbage!" -Letterman

--- DB B1061/002487
 * Origin: Gulf Coast BBS -QuickSHARE #2- (904)563-2547 HST/V.32bis (1:365/12)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET