File Reading Problem


I am writing a program in VB, and I have created a file format that holds

wave (.wav) files, along with a short description. My problem is that,

using VB, I cannot read more than one of the wave files within a file. This

is happening because at the end of a wave file is and end of file marker.

VB is presuming that this is the end of the file altogether, and won't read

past it. Please could someone tell me how to do this?

Thanks in advance!

J. Worthington



  • I am assuming you are using a method other than "Get" to retrieve the contents of the file. Line Input and Input both stop at the first Chr$(26) (I think) that they encounter and assume that there is no more file to get. Get, however, is a binary mode read, it "doesn't care" where the end of the file is, in fact, if you have a zero byte file, you can read the 10 millionth byte in the file correctly, the file will just be extended.

    Here's a function I use so often that I put it into an ocx with some others:

    Pass the name of the file and a non-fixed string variable. It puts the file's contents into the string and returns true if it was successful and false if it wasn't.

    Public Function GetFile(ByVal FileName As String, ByRef FileText As String) As Boolean

    Dim HChunk As String * 65526

    Dim LChunk As String * 10000

    Dim MChunk As String * 1000

    Dim SChunk As String * 100

    Dim TChunk As String * 10

    Dim OChunk As String * 1

    FFile = FreeFile

    On Error GoTo hError

    Open FileName For Input As FFile


    Open FileName For Binary As FFile

    TotalFile = LOF(FFile)

    NumH = TotalFile 65526

    TotalFile = TotalFile - NumH * 65526

    NumL = TotalFile 10000

    TotalFile = TotalFile - NumL * 10000

    NumM = TotalFile 1000

    TotalFile = TotalFile - NumM * 1000

    NumS = TotalFile 100

    TotalFile = TotalFile - NumS * 100

    NumT = TotalFile 10

    TotalFile = TotalFile - NumT * 10

    NumO = TotalFile

    If NumH > 0 Then

    For I = 1 To NumH

    Get #FFile, , HChunk

    FileText = FileText & HChunk



    End If

    If NumL > 0 Then

    For I = 1 To NumL

    Get #1, , LChunk

    FileText = FileText & LChunk



    End If

    If NumM > 0 Then

    For I = 1 To NumM

    Get #1, , MChunk

    FileText = FileText & MChunk



    End If

    If NumS > 0 Then

    For I = 1 To NumS

    Get #1, , SChunk

    FileText = FileText & SChunk



    End If

    If NumT > 0 Then

    For I = 1 To NumT

    Get #1, , TChunk

    FileText = FileText & TChunk



    End If

    If NumO > 0 Then

    For I = 1 To NumO

    Get #1, , OChunk

    FileText = FileText & OChunk



    End If

    GetFile = True

    Exit Function


    GetFile = False

    Exit Function

    End Function

    Hope this helps!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!