I am using Access 2003 and was using this code to cut mp3 files into smaller parts:
Private Sub cmdCut_Click()
Dim bytData() As Byte
bytData = ReadFile(App.Path & "\music.mp3", 1, 30000)
Call WriteFile(App.Path & "\1.mp3", bytData)
bytData = ReadFile(App.Path & "\music.mp3", 30001)
Call WriteFile(App.Path & "\2.mp3", bytData)
End Sub
Private Function ReadFile(ByVal strFileName As String, Optional ByVal lngStartPos As Long = 1, Optional ByVal lngFileSize As Long = -1) As Byte()
Dim FilNum As Integer
FilNum = FreeFile
Open strFileName For Binary As #FilNum
If lngFileSize = -1 Then
ReDim ReadFile(LOF(FilNum) - lngStartPos) <-------------------------
----------
---- Error here
Else
ReDim ReadFile(lngFileSize - 1)
End If
Get #FilNum, lngStartPos, ReadFile
Close #FilNum
End Function
Private Function WriteFile(ByVal strFileName As String, bytData() As Byte, Optional ByVal lngStartPos As Long = -1, Optional ByVal OverWrite As Boolean = True)
Dim FilNum As Integer
FilNum = FreeFile
If OverWrite = True And Dir(strFileName) <> "" Then
Kill strFileName
End If
Open strFileName For Binary As #FilNum
If lngStartPos = -1 Then
Put #FilNum, LOF(FilNum) + 1, bytData
Else
Put #FilNum, lngStartPos, bytData
End If
Close #FilNum
End Function
It worked just fine. Then, I had to reformat the hard drive and put a fresh install of XP Pro. I reinstalled Office 2003 and reinstalled Office 2003 Service Pack 3. Now the code won't work. I get a "Subscript Out of range" error on the first read line (indicated above). It seems to be that the code to Dim a byte array has stopped working. But I don't see why, since it *was* working just fine before.
Can anyone help? What can I do to make this run again?
Start Free Trial