Question [RESOLVED] String Issues with FileGet

nevafuse

New member
Joined
Nov 17, 2008
Messages
4
Programming Experience
5-10
I have a class that pulls the ID3 information from an MP3 file. This information is at the very end of the file in plain ASCII. The original author is using FileGet to retrieve just the last 127 characters of each mp3 file. The issue is that this information is put into strings declared like this...

VB.NET:
Public strTag As New String(" ", 3)
Public strTitle As New String(" ", 30)
Public strArtist As New String(" ", 30)

FilePut(intFile, strTitle)
FilePut(intFile, strArtist)
FilePut(intFile, strAlbum)

This part all works fine. But I'm trying to code a property that returns a string like this...

VB.NET:
return strTitle & " - " & strArtist

But for some odd reason it is being very strict about the length of the returned string. It usually just returns the strTitle, and not the " - " or strArtist, and if I switch the positions, it will just return strArtist. So obviously both Strings have information in them.

I'm an intermediate programmer, but just breaking into VB.NET. I'm not sure what the New String(" ",30) part does, but it is definitely interfering with the string concatenation that I'm trying to return. Anyone ever had a similar issue?

I've tried String.Copy, String.Concat, etc. I've also tried doing ReadtoEnd(), but it takes forever for just 10 mp3 files, so I can't imagine how long it would take with a whole library. The only thing that slightly works is if I do...

VB.NET:
return strTitle.SubString(0,5) & " - " & strArtist.SubString(0,5)

But like I said, coincidentally it will only return around 30 characters.
 
Last edited:
Testing Sample

Here is a quick excerpt if you'd like to play around with it...

VB.NET:
Imports System
Imports System.IO

Dim strTag As New String(" ", 3)
Dim strTitle As New String(" ", 30)
Dim strArtist As New String(" ", 30)
'change this to the path for your mp3 file
Dim strFilename As String = "C:\song.mp3"
Dim intFile As Integer = FreeFile()
FileOpen(intFile, strFilename, OpenMode.Binary, _
           OpenAccess.ReadWrite, OpenShare.LockWrite)
Dim lngLOF As Long = LOF(intFile)
If (lngLOF > 128) Then
            ' Check for the ID3v1 tag
            FileGet(intFile, strTag, lngLOF - 127, True)
            If (strTag.ToUpper = "TAG") Then
                FileGet(intFile, strTitle)
                FileGet(intFile, strArtist)
                MsgBox(strTitle & " - " & strArtist)
            Else
                MsgBox("No ID3 Info")
            End If
End If
 
The Id3 tag version you're using is 1.0/1.1, which had 30 chars limit for those fields.
 
I recommend using one of ID3 libraries out there, and to use v2 rather than the old v1. Here's one library: UltraID3Lib (it also supports v1 if you need to read those)
 
Terminating character

Although this issue was forever ago...

I think the issue was that I was getting a terminating character in my string. This caused output not to returning anything past the terminating character.

I wish I could give you the ascii number or hex string, but I don't remember. Good luck.
 
Back
Top