Results 1 to 9 of 9

Thread: File Open and Write VB6

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    8

    File Open and Write VB6

    Hello... I'm new hear and fairly new to VB altogether...
    I'm experimenting with writing files, namely in the Standard MIDI Format,
    Any tips on how exactly to go about this?

    When I open the file from VB 6,
    How should I open?

    Open MIDFILE.mid For Output As #1

    Or... Should I write it as Binary?

    Open MIDFILE.mid For Binary As #1


    The problem I have is...
    When I open for Binary I'm having trouble writing to it... not sure why...
    But I can write okay when I open for Output...

    Any thoughts?

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: File Open and Write VB6

    well when you open a file for output it assumes its text, that is what the majority of the file IO is in VB. The ability to open a file for binary read/write are for all other types of files, so that is what you would need to use... but you know in order to write a midi file it would have to be all bytes...

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    8

    Re: File Open and Write VB6

    Yeah, I know all the byte structures needed for MIDI,
    Just need to know how to write them…

    So I open for binary then?
    Then when I write I’d have to use something like…

    Write #1, Byte1, Byte2 etc…

    ?

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: File Open and Write VB6

    no its more complicated than that... you usually would use an array of bytes and loop it to write to the file..


    the syntax to write the bytes to a file is
    VB Code:
    1. Put #1, [i]byte number[/i], [i]byte[/i]

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    8

    Re: File Open and Write VB6

    Ah, ok...
    Didn't know what the Put command was... Thanks.

  6. #6
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Re: File Open and Write VB6

    The following pdf is a tutorial about file access.

    Hope this helps!!
    Attached Images Attached Images

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    8

    Re: File Open and Write VB6

    Cool thanks for the pdf... I'll be perusing that.

    I guess the other thing I need to do is package bytes into words no?
    A MIDI message can consist of anywhere from 1 to 3 bytes
    So I assume I'd need to write all the bytes for a message at once right?
    Furthermore I need to add Start/Stop bytes (MIDI words consist of 10 bytes)

    So if I wanted to send a "Note ON" message (Midi Message 144)

    The bit-pattern would be:

    what I want to tranmit: 10010000
    what bits get put on the line (read left-to-right): 0 00001001 1
    (note: the spaces are just to show that there is a start and stop bit)
    Last edited by Disposable; Feb 11th, 2005 at 10:06 AM.

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    8

    Re: File Open and Write VB6

    I found this info on how to write the necessary header chunk...
    But can't figure out exactly how to do it...
    ______________________________________________________________

    The header chunk appears at the beginning of the file, and describes the file in three ways. The header chunk always looks like:

    4D 54 68 64 00 00 00 06 ff ff nn nn dd dd


    The ascii equivalent of the first 4 bytes is MThd. After MThd comes the 4-byte size of the header. This will always be 00 00 00 06, because the actual header information will always be 6 bytes.
    ff ff is the file format. There are 3 formats:

    0 - single-track
    1 - multiple tracks, synchronous
    2 - multiple tracks, asynchronous


    Single track is fairly self-explanatory - one track only. Synchronous multiple tracks means that the tracks will all be vertically synchronous, or in other words, they all start at the same time, and so can represent different parts in one song. Asynchronous multiple tracks do not necessarily start at the same time, and can be completely asynchronous.

    nn nn is the number of tracks in the midi file.
    dd dd is the number of delta-time ticks per quarter note. (More about this later)
    -------------------------------------------------------------------------

    Let's say I want to define the Format as "0"
    The number of Tracks as "1"
    And the Division as "10"

    So I'd...

    Open TestFile.mid for Binary As #1

    Then I want to write the header chunk
    To be MThd, the size of the header, Format, Number Of Tracks, Division
    But I don't know how to do this.

    Can anyone point me in the right direction?

    Do I define Header as something then add all the information and then
    Put #1, Header

    ?


    Note, I do already have an ActiveX control that does all this automagically...
    But I want to learn how to do it anyway for my own purpose...
    I don't know C++ (What the ActiveX control is writtenin)
    So I can't examine it's code with any validity...
    Plus it has a lot of other functions I'd have to pick through.
    Last edited by Disposable; Feb 11th, 2005 at 03:04 PM.

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: File Open and Write VB6

    I think that you'd have to either choose the record, or let the next record be used.

    VB Code:
    1. Put #1, , Header

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