| Author |
How read MIDI file content ? ? ?
|
|
| CorfuVBProgrammer 2006-06-25, 3:56 am |
| Just i have try all the posible methods to open file with VB
Like
open filename for input as fn
open filename for binary as fn and so on in VB6
i have try streams in VB.NET, serialization and API
i have try C++ stream methods.
Is any onw that can do that ? ? ? Thanks a lot :D
| |
| Bob O`Bob 2006-06-25, 6:56 pm |
| CorfuVBProgrammer wrote:
> Just i have try all the posible methods to open file with VB
>
> Like
>
> open filename for input as fn
> open filename for binary as fn and so on in VB6
>
> i have try streams in VB.NET, serialization and API
>
> i have try C++ stream methods.
>
> Is any onw that can do that ? ? ? Thanks a lot :D
>
Yes. Lots of people.
All of those /can/ work.
Most likely, you're not doing it right.
Since you've showed NOTHING, and we are not psychic,
we can't guess what you may have done wrong.
Bob
| |
| Larry Serflaten 2006-06-26, 7:56 am |
|
"CorfuVBProgrammer" <merianosnikos@gmail.com> wrote
> All the methods i have use are working and making result but the
> problem is that i getting back only some characters from the file.
Perhaps you're not doing it right.
> For example if the file contain 25000 characters (25K) the i'm getting
> back only 1000characters or 5 characters accordingly the file.
That is not usually what I see, the code I use gets all the characters.
Perhaps the method you use to count the characters needs attention?
Its hard to tell what might be wrong with the code you use, because
you haven't shown us any of it!
LFS
| |
| Rick Rothstein 2006-06-26, 6:56 pm |
| > Do the same with your VB and tell me about . . .
>
> Dim s As String
>
> Open "path\to\midi\file" For Input As #1
> Do While Not EOF(1)
> Line Input #1, s
> Text1.Text = Text1.Text & s
> Loop
> Close #1
>
> It is the most simple method but it doesn't work. It is read only some
> characters and that's all. It has never read full file content.
>
> Any other idea please ? ? ?
Does this do what you want?
Dim FileNum As Long
Dim TotalFile As String
' Let VB generate the file channel number
FileNum = FreeFile
' Reads the whole file into memory all at once
Open "c:\sample\path\FileName.txt" For Binary As #FileNum
TotalFile = Space(LOF(FileNum))
Get #FileNum, , TotalFile
Close #FileNum
See if the TotalFile variable contains what you are looking for.
Rick
| |
| Bob Butler 2006-06-26, 6:56 pm |
| "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:%23UKm$cTmGHA.4164@TK2MSFTNGP03.phx.gbl
>
> Does this do what you want?
>
> Dim FileNum As Long
> Dim TotalFile As String
> ' Let VB generate the file channel number
> FileNum = FreeFile
> ' Reads the whole file into memory all at once
> Open "c:\sample\path\FileName.txt" For Binary As #FileNum
> TotalFile = Space(LOF(FileNum))
> Get #FileNum, , TotalFile
> Close #FileNum
>
> See if the TotalFile variable contains what you are looking for.
Might want to use a byte array to avoid unimess
Dim FileNum As Long
Dim TotalFile() As Byte
' Let VB generate the file channel number
FileNum = FreeFile
' Reads the whole file into memory all at once
Open "c:\sample\path\FileName.txt" For Binary As #FileNum
ReDim TotalFile(1 To LOF(FileNum))
Get #FileNum, , TotalFile
Close #FileNum
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
| Rick Rothstein 2006-06-26, 6:56 pm |
|
"Bob Butler" <tiredofit@nospam.ever> wrote in message
news:eRsQRnTmGHA.748@TK2MSFTNGP02.phx.gbl...
> "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
> news:%23UKm$cTmGHA.4164@TK2MSFTNGP03.phx.gbl
>
> Might want to use a byte array to avoid unimess
Duh (on my part)... that is a good idea!
Rick
| |
| Larry Serflaten 2006-06-26, 6:56 pm |
|
"CorfuVBProgrammer" <merianosnikos@gmail.com> wrote
> Do the same with your VB and tell me about . . .
>
>
> Dim s As String
>
> Open "path\to\midi\file" For Input As #1
> Do While Not EOF(1)
> Line Input #1, s
> Text1.Text = Text1.Text & s
> Loop
> Close #1
>
>
> It is the most simple method but it doesn't work. It is read only some
> characters and that's all. It has never read full file content.
>
> Any other idea please ? ? ?
A MIDI file is not a file of text, Line Input should not be used.
Try this instead: (Be sure Text1 has Multiline set to True)
LFS
Dim s() As Byte
Dim f As Long
Const MIDIfile = "Your\path\to\MIDI\file"
f = FreeFile
Open MIDIfile For Binary As #f
ReDim s(1 To LOF(f))
Get #f, , s
Close #f
For f = 1 To UBound(s)
If s(f) = 0 Then s(f) = 32
Next
Text1.Text = StrConv(s, vbUnicode)
| |
| Larry Serflaten 2006-06-26, 6:56 pm |
|
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote
>
> Duh (on my part)... that is a good idea!
Part of the problem lies also with the textbox not wanting to show Chr(0):
Dim test As String
test = "abcdefg"
Mid(test, 4, 1) = Chr$(0)
Text1.Text = test ' shows "abc"
Which is why some of the other attempts would have also come up short....
LFS
| |
| Rick Rothstein 2006-06-27, 6:56 pm |
| > The Larry Serflaten gave a preaty good idea on how to open midi file. I
> try this method and work. But the file does not play if i try to save
> it and open it for play with any midi player. The time i getting back
> is 0 minutes 0 seconds. Why ? ? ?
You seem to be having a problem understanding that we are not psychic here.
How can we possibly answer your "Why?" question when you have not shown us
the code you are using to Save the file back again???? Please post your
code!
I'm also curious as to what you are trying to ultimately do here. If you
already have the midi file, why are you reading it in and then saving it
back out again and then trying to use the newly saved file?
Rick
| |
| Larry Serflaten 2006-06-27, 6:56 pm |
|
"CorfuVBProgrammer" <merianosnikos@gmail.com> wrote
> The Larry Serflaten gave a preaty good idea on how to open midi file. I
> try this method and work. But the file does not play if i try to save
> it and open it for play with any midi player. The time i getting back
> is 0 minutes 0 seconds. Why ? ? ?
The file data had to be changed for it to show properly in the textbox.
If you want to keep the data intact, then keep an unmodified copy to
save back to a file. The data is meaningless to the eye, why show it
in a textbox?
LFS
| |
| Bob Butler 2006-06-29, 7:55 am |
| "CorfuVBProgrammer" <merianosnikos@gmail.com> wrote in message
news:1151584254.963517.294550@d56g2000cwd.googlegroups.com
> Open "C:\nn.mid" For Output As #1
> Print #1, StrConv(s, vbUnicode)
> Close #1
dim ff as long
on error resume next
kill "c:\nn.mid"
on error goto 0
ff=freefile
open "C:\nn.mid" for binary As #ff
Put #ff,, s
close #ff
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
|
|
|
|