[RESOLVED] Getting specific information from a file?
I open a wave file using
Quote:
Open MyFile For Binary Access Read As #1
The file is a *.wav file and I want to read some specific information like channels, strings, etc...
To read how many channels the audio file contains I use:
Quote:
Dim NumChannels As Integer
Get #1, 23, NumChannels
MsgBox NumChannels
I use the same formula for other kind of data, like long data type. The problem is when I try to do the same using a string.
For example, I want to get the string RIFF, (bytes 1,2,3 and 4 because it's written in the beginning of the file). And I get a msgbox without any value.
I get the RIFF string when I use
Quote:
Dim X$
For N = 1 to 10
X$ = Input (4, #1)
MsgBox X$
Next N
With the RIFF no problem because it's at the beginning of the file, but if I want to get the WAVE string (bytes: 9,10,11 and 12) I've to read RIFF, (other string) and finally WAVE.
How can I access directly to the data I want without reading all the information before that string?
Re: Getting specific information from a file?
You can dim a string with a length of 4
Open the file for binary
use seek to move to the desired position
use get to read the string
Re: Getting specific information from a file?
Quote:
Originally Posted by
DataMiser
You can dim a string with a length of 4
Open the file for binary
use seek to move to the desired position
use get to read the string
Dim a string with a lenght of 4? How can I do that?
Re: Getting specific information from a file?
Dim someString As String * 4
Re: Getting specific information from a file?
Alternately you can Dim the string as usual then initialize it to 4 characters before you use the get method
Code:
Dim MyString as String
MyString=Space(4)
Get #Filenumber,,MyString
Re: Getting specific information from a file?
Re: Getting specific information from a file?
Quote:
Originally Posted by
DataMiser
Alternately you can Dim the string as usual then initialize it to 4 characters before you use the get method
Code:
Dim MyString as String
MyString=Space(4)
Get #Filenumber,,MyString
That doesn't make the string length 4; it just gives it 4 spaces
Dim MyString As String
MyString = Space(4)
MyString = "abcdefgh"
MyString now contains "abcdefgh"
but
Dim MyString As String * 4
MyString = "abcdefgh"
MyString now contains "abcd" only
Re: [RESOLVED] Getting specific information from a file?
Quote:
That doesn't make the string length 4; it just gives it 4 spaces
4 spaces is a length of 4. It is not restricted to 4 though and is still a variable length string but ...
It works for the task at hand.
When you use Get with a string it will get the number of bytes that the string is long. So if .
Code:
Dim MyString As String
Get #1,,Mystring
It gets 0 bytes because MyString is empty
Code:
Dim MyString As String *4
Get #1,,Mystring
It will get 4 bytes because my string is defined as 4 characters
Code:
Dim MyString As String
MyString=Space(4)
Get #1,,Mystring
It will get 4 bytes because MyString is 4 characters long
I've did this many times in the past and it works just fine.
You can even read the entire file into a string [assuming the file is not to big] using
Code:
Dim MyString As String
MyString=Space(lof(1))
Get #1,,Mystring