-
Jul 16th, 2015, 10:16 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Getting specific information from a file?
I open a wave file using
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:
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
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?
-
Jul 16th, 2015, 12:31 PM
#2
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
-
Jul 16th, 2015, 12:52 PM
#3
Thread Starter
Hyperactive Member
Re: Getting specific information from a file?
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?
-
Jul 16th, 2015, 01:14 PM
#4
Re: Getting specific information from a file?
Dim someString As String * 4
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 16th, 2015, 01:47 PM
#5
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
-
Jul 16th, 2015, 01:58 PM
#6
Thread Starter
Hyperactive Member
Re: Getting specific information from a file?
-
Jul 16th, 2015, 02:05 PM
#7
Re: Getting specific information from a file?
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
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 16th, 2015, 08:11 PM
#8
Re: [RESOLVED] Getting specific information from a file?
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|