Reading metastock data files

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
4kjlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

y96andhaCommented:
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
y96andhaCommented:
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
4kjlAuthor Commented:
Edited text of question
0
y96andhaCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.