Solved

Reading metastock data files

Posted on 1997-05-15
4
1,724 Views
Last Modified: 2012-06-27
I have tried in binary to read metastock data files.  Below is a section of code written in C to read the files.  Is this possible to read the files in VB.  Note, I am not familiar with C at this time.

typedef unsigned char   u_char;
typedef unsigned short  u_short;

/*
 * MASTER file description
 *  floats are in Microsoft Basic format
 *  strings are padded with spaces, not null terminated
 */
struct rec_1 {
    u_short num_files;      /* number of files master contains */
    u_short file_num;       /* next file number to use (highest F#
used) */
    char zeroes[49];
};
struct rec_2to129 {         /* description of data files */
    u_char file_num;        /* file #, i.e., F# */
    char file_type[2];      /* CT file type = 0'e' (5 or 7 flds) */
    u_char rec_len;         /* record length in bytes (4 x num_fields)
*/
    u_char num_fields;      /* number of 4-byte fields in each record
*/
    char reserved1[2];      /*  in the data file */
    char issue_name[16];    /* stock name */
    char reserved2;
    char CT_v2_8_flag;      /* if CT ver. 2.8, 'Y'; o.w., anything
else */
    float first_date;       /* yymmdd */
    float last_date;
    char time_frame;        /* data format:
'I'(IDA)/'W'/'Q'/'D'/'M'/'Y' */
    u_short ida_time;       /* intraday (IDA) time base */
    char symbol[14];        /* stock symbol */
    char reserved3;         /* MetaStock reserved2: must be a space */
    char flag;              /* ' ' or '*' for autorun */
    char reserved4;
};

/*
 * EMASTER data structure
 *  floats are in IEEE format
 *  strings are padded with nulls
 */
struct emashdr {
    u_short num_files;      /* number of files in emaster */
    u_short file_num;       /* last (highest) file number */
    char stuff[188];
};
struct emasdat {
    char asc30[2];          /* "30" */
    u_char file_num;        /* file number F# */
    char fill1[3];
    u_char num_fields;      /* number of 4-byte data fields */
    char fill2[2];
    char flag;              /* ' ' or '*' for autorun */
    char fill3;
    char symbol[14];        /* stock symbol */
    char fill4[7];
    char issue_name[16];    /* stock name */
    char fill5[12];
    char time_frame;        /* data format: 'D'/'W'/'M'/ etc. */
    char fill6[3];
    float first_date;       /* yymmdd */
    char fill7[4];
    float last_date;
    char fill8[116];
};

/* seven-field data file description */
struct dathdr7 {
    u_short max_recs;       /* 0 ==> unlimited size */
    u_short last_rec;       /* dathdr7 = 1; ctdata7 starts with 2 */
    char zeroes[24];
};
struct ctdata7 {
    float date;
    float open;
    float high;
    float low;
    float close;
    float volume;
    float op_int;
};

/* five-field data file description */
struct dathdr5 {
    u_short max_recs;
    u_short last_rec;
    char zeroes[16];
};
struct ctdata5 {
    float date;
    float high;
    float low;
    float close;
    float volume;
};


You mentioned in your response to convert all of the struct declaratons to VB type declerations.  Then can read using the get statement.   Would you have an example of how to
convert the struct declarations to VB type.  Thanks, Keith
0
Comment
Question by:4kjl
  • 3
4 Comments
 
LVL 5

Expert Comment

by:y96andha
ID: 1426317
Yes, that should be possible. You will have to convert all of the struct declarations to VB type declarations. Then you can read the files using the Get statement.
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1426318
For example:

struct rec_1 {
       u_short num_files; /* number of files master contains */
       u_short file_num; /* next file number to use (highest F#
used) */
       char zeroes[49];
};

Type rec_1
        num_files as Integer
        file_num as Integer
        zeroes as String*49
End Type

When using items declared as u_short, you will have to convert negative numbers to positive, any negative number in an Integer should have 65536 added to it. This is because the C-type u_short has a range of 0 to 65535 whereas the VB-type of Integer has a range of 0 to 32767, -32768 to -1.


0
 

Author Comment

by:4kjl
ID: 1426319
Edited text of question
0
 
LVL 5

Accepted Solution

by:
y96andha earned 200 total points
ID: 1426320
I have given you one example. To convert the other structures:

u_short <-> Integer, with the exception noted
char xxx[n] <-> xxx as String*n
float <-> Single
u_char <-> Byte
char <-> String*1

Please comment if you need more directions
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question