Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Crash on converting string to byte

Crash on converting string to byte

Scheduled Pinned Locked Moved Visual Basic
game-dev
32 Posts 3 Posters 129 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Member Alienoiz

    Hello all...im new and im not even a coder. I just do some apps once in a while to keep the head busy and exercise my mind. im actually trying to make an mp3 tagger. All is good but i cannot tag new files..only pre-tagged files...it says it cannot convert string to byte in the "Track" and "Genre" fields. This is the class im using

    Imports System.IO

    Public Class MP3ID3v1

    ' Constructor
    Public Sub New(Optional ByVal Filename As String = "")
        MyBase.New()
        If (Filename <> "") Then Me.Filename = Filename
    End Sub
    

    #Region " Declarations "

    ' Genres
    Public Enum Genres As Byte
        Blues = 0
        ClassicRock = 1
        Country = 2
        Dance = 3
        Disco = 4
        Funk = 5
        Grunge = 6
        HipHop = 7
        Jazz = 8
        Metal = 9
        NewAge = 10
        Oldies = 11
        Other = 12
        Pop = 13
        RnB = 14
        Rap = 15
        Reggae = 16
        Rock = 17
        Techno = 18
        Industrial = 19
        Alternative = 20
        Ska = 21
        DeathMetal = 22
        Pranks = 23
        Soundtrack = 24
        EuroTechno = 25
        Ambient = 26
        TripHop = 27
        Vocal = 28
        JazzFunk = 29
        Fusion = 30
        Trance = 31
        Classical = 32
        Instrumental = 33
        Acid = 34
        House = 35
        Game = 36
        SoundClip = 37
        Gospel = 38
        Noise = 39
        AlternRock = 40
        Bass = 41
        Soul = 42
        Punk = 43
        Space = 44
        Meditative = 45
        InstrumentalPop = 46
        InstrumentalRock = 47
        Ethnic = 48
        Gothic = 49
        Darkwave = 50
        TechnoIndustrial = 51
        Electronic = 52
        PopFolk = 53
        Eurodance = 54
        Dream = 55
        SouthernRock = 56
        Comedy = 57
        Cult = 58
        Gangsta = 59
        Top40 = 60
        ChristianRap = 61
        PopFunk = 62
        Jungle = 63
        NativeAmerican = 64
        Cabaret = 65
        NewWave = 66
        Psychadelic = 67
        Rave = 68
        Showtunes = 69
        Trailer = 70
        LoFi = 71
        Tribal = 72
        AcidPunk = 73
        AcidJazz = 74
        Polka = 75
        Retro = 76
        Musical = 77
        RocknRoll = 78
        HardRock = 79
        None = 255
    End Enum
    
    ' Frame types
    Public Enum FrameTypes As Byte
        Title = 0
        Artist = 1
        Album = 2
    
    J Offline
    J Offline
    jschell
    wrote on last edited by
    #14

    Debugging methodology - there are others though. Start removing or commenting out code until the error goes away. Obviously you must give some thought to exactly which code you do this to. Then when the error goes away you have found the problem. Then you can create a much smaller example code to test that functionality and figure out how to make it work correctly. Then you fix the original code and put everything else back.

    1 Reply Last reply
    0
    • L Lost User

      Fine, but you need to be certain.

      M Offline
      M Offline
      Member Alienoiz
      wrote on last edited by
      #15

      i tried this but no luck:

          If CheckBox5.Checked = True Then
                          Dim txt = TextBox5.Text
                          Dim tt As Integer = Convert.ToInt32(txt)
                          tt = objMP3V1.Frame(MP3ID3v1.FrameTypes.Track) & vbLf
                          objMP3V1.Update()
                      End If
                      If CheckBox6.Checked = True Then
                          objMP3V1.Frame(MP3ID3v1.FrameTypes.Comment) = TextBox6.Text
                          objMP3V1.Update()
                      End If
      
                      If CheckBox7.Checked = True Then
                          Dim xt = ComboBox1.SelectedValue
                          Dim xx As Integer = Convert.ToInt32(xt)
                          xx = objMP3V1.Frame(MP3ID3v1.FrameTypes.Genre) & vbLf
                          objMP3V1.Update()
                      End If
      
      L 1 Reply Last reply
      0
      • M Member Alienoiz

        i tried this but no luck:

            If CheckBox5.Checked = True Then
                            Dim txt = TextBox5.Text
                            Dim tt As Integer = Convert.ToInt32(txt)
                            tt = objMP3V1.Frame(MP3ID3v1.FrameTypes.Track) & vbLf
                            objMP3V1.Update()
                        End If
                        If CheckBox6.Checked = True Then
                            objMP3V1.Frame(MP3ID3v1.FrameTypes.Comment) = TextBox6.Text
                            objMP3V1.Update()
                        End If
        
                        If CheckBox7.Checked = True Then
                            Dim xt = ComboBox1.SelectedValue
                            Dim xx As Integer = Convert.ToInt32(xt)
                            xx = objMP3V1.Frame(MP3ID3v1.FrameTypes.Genre) & vbLf
                            objMP3V1.Update()
                        End If
        
        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #16

        Member Alienoiz wrote:

        i tried this but no luck:

        Why are you trying to store 32 bit integer values in 8 bit byte fields?

        M 2 Replies Last reply
        0
        • L Lost User

          Member Alienoiz wrote:

          i tried this but no luck:

          Why are you trying to store 32 bit integer values in 8 bit byte fields?

          M Offline
          M Offline
          Member Alienoiz
          wrote on last edited by
          #17

          well..,like i say..im no coder...i just read snippets and try by error!

          1 Reply Last reply
          0
          • L Lost User

            Member Alienoiz wrote:

            i tried this but no luck:

            Why are you trying to store 32 bit integer values in 8 bit byte fields?

            M Offline
            M Offline
            Member Alienoiz
            wrote on last edited by
            #18

            can it be here?

            ' Fix the length of the frames
            strTitle = LSet(mobjFrame(0), Len(strTitle))
            strArtist = LSet(mobjFrame(1), Len(strArtist))
            strAlbum = LSet(mobjFrame(2), Len(strAlbum))
            strYear = LSet(mobjFrame(3), Len(strYear))
            bytTrack = mobjFrame(4)
            strComment = LSet(mobjFrame(5), Len(strComment))
            bytGenre = mobjFrame(6)

            sorry im blind about it for now :(((

            L 1 Reply Last reply
            0
            • M Member Alienoiz

              can it be here?

              ' Fix the length of the frames
              strTitle = LSet(mobjFrame(0), Len(strTitle))
              strArtist = LSet(mobjFrame(1), Len(strArtist))
              strAlbum = LSet(mobjFrame(2), Len(strAlbum))
              strYear = LSet(mobjFrame(3), Len(strYear))
              bytTrack = mobjFrame(4)
              strComment = LSet(mobjFrame(5), Len(strComment))
              bytGenre = mobjFrame(6)

              sorry im blind about it for now :(((

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #19

              Sorry, I really have no idea what that code is trying to do, so I cannnt say whether it is correct or not.

              M 1 Reply Last reply
              0
              • L Lost User

                Sorry, I really have no idea what that code is trying to do, so I cannnt say whether it is correct or not.

                M Offline
                M Offline
                Member Alienoiz
                wrote on last edited by
                #20

                hey..i changed my library..im now using UltraID3lib.....it seems im making it but i have another question... how do i make mass edit in a listbox? im using this code that was working previously but is not working now:

                Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

                    If ListBox1.SelectedItem = "" Then
                        Dim r8 As DialogResult = MessageBox.Show(Me, "No File Selected!",
                                               "Select Files", MessageBoxButtons.OK)
                
                
                    Else
                        If CheckBox1.Checked = False And CheckBox2.Checked = False And CheckBox3.Checked = False And CheckBox4.Checked = False And CheckBox5.Checked = False And CheckBox6.Checked = False And CheckBox7.Checked = False Then
                            Dim r8 As DialogResult = MessageBox.Show(Me, "Select a tag to enter!",
                                              "Select Tags", MessageBoxButtons.OK)
                        Else
                            Dim fil = ListBox1.SelectedItems
                            Dim fil2 As String
                            For Each fil2 In fil
                
                                If CheckBox1.Checked = True Then
                                    myMp3.ID3v2Tag.Title = TextBox1.Text
                                    myMp3.Write()
                                End If
                
                
                                If CheckBox2.Checked = True Then
                                    myMp3.ID3v2Tag.Artist = TextBox2.Text
                                    myMp3.Write()
                                End If
                
                
                                If CheckBox3.Checked = True Then
                                    myMp3.ID3v2Tag.Album = TextBox3.Text
                                    myMp3.Write()
                                End If
                
                
                                If CheckBox4.Checked = True And TextBox4.Text <> "" Then
                                    On Error Resume Next
                                    myMp3.ID3v2Tag.Year = Short.Parse(TextBox4.Text)
                                    myMp3.Write()
                                    On Error Resume Next
                                End If
                
                
                                If CheckBox5.Checked = True And TextBox5.Text <> "" Then
                                    myMp3.ID3v2Tag.TrackNum = Short.Parse(TextBox5.Text)
                                    myMp3.Write()
                                    On Error Resume Next
                                End If
                
                
                                If CheckBox6.Checked = True Then
                                    myMp3.ID3v2Tag.Comments = TextBox6.Text
                                    myMp3.Write()
                                End If
                
                                If CheckBox7.Checked = True Then
                                    If ComboBox1.Text = "01 - User" Then
                                        myMp3.ID3v2Tag
                
                L 1 Reply Last reply
                0
                • M Member Alienoiz

                  hey..i changed my library..im now using UltraID3lib.....it seems im making it but i have another question... how do i make mass edit in a listbox? im using this code that was working previously but is not working now:

                  Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

                      If ListBox1.SelectedItem = "" Then
                          Dim r8 As DialogResult = MessageBox.Show(Me, "No File Selected!",
                                                 "Select Files", MessageBoxButtons.OK)
                  
                  
                      Else
                          If CheckBox1.Checked = False And CheckBox2.Checked = False And CheckBox3.Checked = False And CheckBox4.Checked = False And CheckBox5.Checked = False And CheckBox6.Checked = False And CheckBox7.Checked = False Then
                              Dim r8 As DialogResult = MessageBox.Show(Me, "Select a tag to enter!",
                                                "Select Tags", MessageBoxButtons.OK)
                          Else
                              Dim fil = ListBox1.SelectedItems
                              Dim fil2 As String
                              For Each fil2 In fil
                  
                                  If CheckBox1.Checked = True Then
                                      myMp3.ID3v2Tag.Title = TextBox1.Text
                                      myMp3.Write()
                                  End If
                  
                  
                                  If CheckBox2.Checked = True Then
                                      myMp3.ID3v2Tag.Artist = TextBox2.Text
                                      myMp3.Write()
                                  End If
                  
                  
                                  If CheckBox3.Checked = True Then
                                      myMp3.ID3v2Tag.Album = TextBox3.Text
                                      myMp3.Write()
                                  End If
                  
                  
                                  If CheckBox4.Checked = True And TextBox4.Text <> "" Then
                                      On Error Resume Next
                                      myMp3.ID3v2Tag.Year = Short.Parse(TextBox4.Text)
                                      myMp3.Write()
                                      On Error Resume Next
                                  End If
                  
                  
                                  If CheckBox5.Checked = True And TextBox5.Text <> "" Then
                                      myMp3.ID3v2Tag.TrackNum = Short.Parse(TextBox5.Text)
                                      myMp3.Write()
                                      On Error Resume Next
                                  End If
                  
                  
                                  If CheckBox6.Checked = True Then
                                      myMp3.ID3v2Tag.Comments = TextBox6.Text
                                      myMp3.Write()
                                  End If
                  
                                  If CheckBox7.Checked = True Then
                                      If ComboBox1.Text = "01 - User" Then
                                          myMp3.ID3v2Tag
                  
                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #21

                  Sorry, I have no idea what you mean by "this code that was working previously but is not working now:". You need to explain what happens when you run this code and why that is not correct. Alternatively, use the debugger to step through the code to try and find out what is going on.

                  M 1 Reply Last reply
                  0
                  • L Lost User

                    Sorry, I have no idea what you mean by "this code that was working previously but is not working now:". You need to explain what happens when you run this code and why that is not correct. Alternatively, use the debugger to step through the code to try and find out what is going on.

                    M Offline
                    M Offline
                    Member Alienoiz
                    wrote on last edited by
                    #22

                    well...i just want to apply this code

                    If CheckBox6.Checked = True Then
                    myMp3.ID3v2Tag.Comments = TextBox6.Text
                    myMp3.Write()
                    End If

                                    If CheckBox7.Checked = True Then
                                        If ComboBox1.Text = "01 - User" Then
                                            myMp3.ID3v2Tag.Genre = TextBox7.Text
                                            myMp3.Write()
                                        Else
                                            myMp3.ID3v2Tag.Genre = ComboBox1.Text
                                            myMp3.Write()
                                        End If
                                    End If
                    

                    ........to all selected items in a listbox!!

                    L 1 Reply Last reply
                    0
                    • M Member Alienoiz

                      well...i just want to apply this code

                      If CheckBox6.Checked = True Then
                      myMp3.ID3v2Tag.Comments = TextBox6.Text
                      myMp3.Write()
                      End If

                                      If CheckBox7.Checked = True Then
                                          If ComboBox1.Text = "01 - User" Then
                                              myMp3.ID3v2Tag.Genre = TextBox7.Text
                                              myMp3.Write()
                                          Else
                                              myMp3.ID3v2Tag.Genre = ComboBox1.Text
                                              myMp3.Write()
                                          End If
                                      End If
                      

                      ........to all selected items in a listbox!!

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #23

                      OK, go ahead.

                      M 1 Reply Last reply
                      0
                      • L Lost User

                        OK, go ahead.

                        M Offline
                        M Offline
                        Member Alienoiz
                        wrote on last edited by
                        #24

                        i have been searching but i cannot find anything to use...could you gimme a help please?

                        L 1 Reply Last reply
                        0
                        • M Member Alienoiz

                          i have been searching but i cannot find anything to use...could you gimme a help please?

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #25

                          No, because I have no idea what your problem is. You need to show the code you are using, and explain what the problem is and where it occurs.

                          M 1 Reply Last reply
                          0
                          • L Lost User

                            No, because I have no idea what your problem is. You need to show the code you are using, and explain what the problem is and where it occurs.

                            M Offline
                            M Offline
                            Member Alienoiz
                            wrote on last edited by
                            #26

                            OK...so i have a listbox with files (mp3) and im trying to edit the tags..i can do one by one but i do not know how to tag them all at once. i want to implement this code in all files of the listbox just by using a button.

                            If CheckBox1.Checked = True Then
                            myMp3.ID3v2Tag.Title = TextBox1.Text
                            myMp3.Write()
                            End If

                                            If CheckBox2.Checked = True Then
                                                myMp3.ID3v2Tag.Artist = TextBox2.Text
                                                myMp3.Write()
                                            End If
                            
                            
                                            If CheckBox3.Checked = True Then
                                                myMp3.ID3v2Tag.Album = TextBox3.Text
                                                myMp3.Write()
                                            End If
                            
                            
                                            If CheckBox4.Checked = True And TextBox4.Text <> "" Then
                                                On Error Resume Next
                                                myMp3.ID3v2Tag.Year = Short.Parse(TextBox4.Text)
                                                myMp3.Write()
                                                On Error Resume Next
                                            End If
                            
                            
                                            If CheckBox5.Checked = True And TextBox5.Text <> "" Then
                                                myMp3.ID3v2Tag.TrackNum = Short.Parse(TextBox5.Text)
                                                myMp3.Write()
                                                On Error Resume Next
                                            End If
                            
                            
                                            If CheckBox6.Checked = True Then
                                                myMp3.ID3v2Tag.Comments = TextBox6.Text
                                                myMp3.Write()
                                            End If
                            
                                            If CheckBox7.Checked = True Then
                                            If ComboBox1.Text = "01 - User" Then
                                                myMp3.ID3v2Tag.Genre = TextBox7.Text
                                                myMp3.Write()
                                            Else
                                                myMp3.ID3v2Tag.Genre = ComboBox1.Text
                                                myMp3.Write()
                                            End If
                            
                                            If CheckBox8.Checked = True Then
                            
                                            End If
                            
                            
                            
                                        End If
                            
                            L 1 Reply Last reply
                            0
                            • M Member Alienoiz

                              OK...so i have a listbox with files (mp3) and im trying to edit the tags..i can do one by one but i do not know how to tag them all at once. i want to implement this code in all files of the listbox just by using a button.

                              If CheckBox1.Checked = True Then
                              myMp3.ID3v2Tag.Title = TextBox1.Text
                              myMp3.Write()
                              End If

                                              If CheckBox2.Checked = True Then
                                                  myMp3.ID3v2Tag.Artist = TextBox2.Text
                                                  myMp3.Write()
                                              End If
                              
                              
                                              If CheckBox3.Checked = True Then
                                                  myMp3.ID3v2Tag.Album = TextBox3.Text
                                                  myMp3.Write()
                                              End If
                              
                              
                                              If CheckBox4.Checked = True And TextBox4.Text <> "" Then
                                                  On Error Resume Next
                                                  myMp3.ID3v2Tag.Year = Short.Parse(TextBox4.Text)
                                                  myMp3.Write()
                                                  On Error Resume Next
                                              End If
                              
                              
                                              If CheckBox5.Checked = True And TextBox5.Text <> "" Then
                                                  myMp3.ID3v2Tag.TrackNum = Short.Parse(TextBox5.Text)
                                                  myMp3.Write()
                                                  On Error Resume Next
                                              End If
                              
                              
                                              If CheckBox6.Checked = True Then
                                                  myMp3.ID3v2Tag.Comments = TextBox6.Text
                                                  myMp3.Write()
                                              End If
                              
                                              If CheckBox7.Checked = True Then
                                              If ComboBox1.Text = "01 - User" Then
                                                  myMp3.ID3v2Tag.Genre = TextBox7.Text
                                                  myMp3.Write()
                                              Else
                                                  myMp3.ID3v2Tag.Genre = ComboBox1.Text
                                                  myMp3.Write()
                                              End If
                              
                                              If CheckBox8.Checked = True Then
                              
                                              End If
                              
                              
                              
                                          End If
                              
                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #27

                              You just need a couple of loops:

                              ForEach file in the ListBox
                              Open the file
                              ForEach CheckBox in the Form
                              adjust the tags as required
                              Next
                              Save and Close the updated file
                              Next

                              Put the code into a subroutine and pass it the list of filenames from the ListBox.

                              M 1 Reply Last reply
                              0
                              • L Lost User

                                You just need a couple of loops:

                                ForEach file in the ListBox
                                Open the file
                                ForEach CheckBox in the Form
                                adjust the tags as required
                                Next
                                Save and Close the updated file
                                Next

                                Put the code into a subroutine and pass it the list of filenames from the ListBox.

                                M Offline
                                M Offline
                                Member Alienoiz
                                wrote on last edited by
                                #28

                                should be something like this right?

                                Dim items = ListBox1.SelectedItem()
                                For Each items In ListBox1.SelectedItems

                                                If CheckBox1.Checked = True Then
                                                    myMp3.ID3v2Tag.Title = TextBox1.Text
                                                    myMp3.Write()
                                

                                Next
                                End If

                                is not working :((((

                                L 1 Reply Last reply
                                0
                                • M Member Alienoiz

                                  should be something like this right?

                                  Dim items = ListBox1.SelectedItem()
                                  For Each items In ListBox1.SelectedItems

                                                  If CheckBox1.Checked = True Then
                                                      myMp3.ID3v2Tag.Title = TextBox1.Text
                                                      myMp3.Write()
                                  

                                  Next
                                  End If

                                  is not working :((((

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #29

                                  Your first two lines duplicate each other:

                                  Dim items = ListBox1.SelectedItem() // get a list of the SelectedItem(s)
                                  For Each items In ListBox1.SelectedItems // do the same, but duplicating the variable name

                                  But either way they make little sense as you do not do anything with the item you pull from the ListBox. You need something like:

                                  ' I am making an assumption that the ListBox entries are names of the files to be processed
                                  For Each file As String In ListBox1.SelectedItems ' Extract each file name
                                  ' So pass this name to a subroutine that will:
                                  ' Open the file
                                  ' Process all the tags according to the CheckBox settings
                                  ' Save and Close the file
                                  Next

                                  Try not to write all your code inline, as it makes it so much more dificult to read and, more importantly, to debug.

                                  M 1 Reply Last reply
                                  0
                                  • L Lost User

                                    Your first two lines duplicate each other:

                                    Dim items = ListBox1.SelectedItem() // get a list of the SelectedItem(s)
                                    For Each items In ListBox1.SelectedItems // do the same, but duplicating the variable name

                                    But either way they make little sense as you do not do anything with the item you pull from the ListBox. You need something like:

                                    ' I am making an assumption that the ListBox entries are names of the files to be processed
                                    For Each file As String In ListBox1.SelectedItems ' Extract each file name
                                    ' So pass this name to a subroutine that will:
                                    ' Open the file
                                    ' Process all the tags according to the CheckBox settings
                                    ' Save and Close the file
                                    Next

                                    Try not to write all your code inline, as it makes it so much more dificult to read and, more importantly, to debug.

                                    M Offline
                                    M Offline
                                    Member Alienoiz
                                    wrote on last edited by
                                    #30

                                    aaarrggghh...im not able to make it work ...could you be a little more explicit please?

                                    L 1 Reply Last reply
                                    0
                                    • M Member Alienoiz

                                      aaarrggghh...im not able to make it work ...could you be a little more explicit please?

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #31

                                      In what sense more explicit? You know, one of the most frustrating things in these forums is when people keep saying things like, "it doesn't work". We have no way of knowing what that is supposed to mean, even when we can see your code. So I suggest you start a new question. Make sure you post the code that you are using, and explain, in proper and complete detail what is not working, and why that is so.

                                      M 1 Reply Last reply
                                      0
                                      • L Lost User

                                        In what sense more explicit? You know, one of the most frustrating things in these forums is when people keep saying things like, "it doesn't work". We have no way of knowing what that is supposed to mean, even when we can see your code. So I suggest you start a new question. Make sure you post the code that you are using, and explain, in proper and complete detail what is not working, and why that is so.

                                        M Offline
                                        M Offline
                                        Member Alienoiz
                                        wrote on last edited by
                                        #32

                                        could you correct my code?

                                        Dim items = ListBox1.SelectedItems()
                                        For Each items In ListBox1.SelectedItems()

                                                        If CheckBox1.Checked = True Then
                                                            myMp3.ID3v2Tag.Title = TextBox1.Text
                                                            myMp3.Write()
                                        

                                        End If
                                        Next

                                        Next

                                        1 Reply Last reply
                                        0
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • World
                                        • Users
                                        • Groups