Solved

Reading metastock data files

Posted on 1997-05-15
4
1,658 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
Comment Utility
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
Comment Utility
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
Comment Utility
Edited text of question
0
 
LVL 5

Accepted Solution

by:
y96andha earned 200 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now