Crash on converting string to byte
-
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
-
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
Just dumping all your code and expecting someone to fix it is quite rude. We have no idea where the error occurs. So please edit the question, remove all the code that is not relevant to the problem, mark the point where the error occurs, and include the complete text of the error message.
-
Just dumping all your code and expecting someone to fix it is quite rude. We have no idea where the error occurs. So please edit the question, remove all the code that is not relevant to the problem, mark the point where the error occurs, and include the complete text of the error message.
Hi..sorry..i posted all the code cause i do not know what is happenning at all... anyway...thanks and i can resume yes... when i try to save the tags:
Dim bytTrack As Byte
Dim bytGenre As Bytethe error returns it cannot convert String to Byte..but this is only happenning in new files..if i use a pretagged file all seems good. im using this method:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If ListBox1.Text = "" Then
Dim r8 As DialogResult = MessageBox.Show(Me, "No File Selected!",
"Select Files", MessageBoxButtons.OK)Else Dim objMP3V1 As New MP3ID3v1(FolderBrowserDialog1.SelectedPath & "\\" & ListBox1.SelectedItem) If CheckBox1.Checked = True Then objMP3V1.Frame(MP3ID3v1.FrameTypes.Title) = TextBox1.Text objMP3V1.Update() End If If CheckBox2.Checked = True Then objMP3V1.Frame(MP3ID3v1.FrameTypes.Artist) = TextBox2.Text objMP3V1.Update() End If If CheckBox3.Checked = True Then objMP3V1.Frame(MP3ID3v1.FrameTypes.Album) = TextBox3.Text objMP3V1.Update() End If If CheckBox4.Checked = True Then objMP3V1.Frame(MP3ID3v1.FrameTypes.Year) = TextBox4.Text objMP3V1.Update() End If If CheckBox5.Checked = True Then objMP3V1.Frame(MP3ID3v1.FrameTypes.Track) = TextBox5.Text 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 objMP3V1.Frame(MP3ID3v1.FrameTypes.Genre) = ComboBox1.SelectedValue objMP3V1.Update() End If Dim r9 As DialogResult = MessageBox.Show(Me, "Operation Complete!", "Tagged Files!", MessageBoxButtons.OK) End If End Sub
-
Hi..sorry..i posted all the code cause i do not know what is happenning at all... anyway...thanks and i can resume yes... when i try to save the tags:
Dim bytTrack As Byte
Dim bytGenre As Bytethe error returns it cannot convert String to Byte..but this is only happenning in new files..if i use a pretagged file all seems good. im using this method:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If ListBox1.Text = "" Then
Dim r8 As DialogResult = MessageBox.Show(Me, "No File Selected!",
"Select Files", MessageBoxButtons.OK)Else Dim objMP3V1 As New MP3ID3v1(FolderBrowserDialog1.SelectedPath & "\\" & ListBox1.SelectedItem) If CheckBox1.Checked = True Then objMP3V1.Frame(MP3ID3v1.FrameTypes.Title) = TextBox1.Text objMP3V1.Update() End If If CheckBox2.Checked = True Then objMP3V1.Frame(MP3ID3v1.FrameTypes.Artist) = TextBox2.Text objMP3V1.Update() End If If CheckBox3.Checked = True Then objMP3V1.Frame(MP3ID3v1.FrameTypes.Album) = TextBox3.Text objMP3V1.Update() End If If CheckBox4.Checked = True Then objMP3V1.Frame(MP3ID3v1.FrameTypes.Year) = TextBox4.Text objMP3V1.Update() End If If CheckBox5.Checked = True Then objMP3V1.Frame(MP3ID3v1.FrameTypes.Track) = TextBox5.Text 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 objMP3V1.Frame(MP3ID3v1.FrameTypes.Genre) = ComboBox1.SelectedValue objMP3V1.Update() End If Dim r9 As DialogResult = MessageBox.Show(Me, "Operation Complete!", "Tagged Files!", MessageBoxButtons.OK) End If End Sub
You are trying to store the text strings into both those fields which are (presumably) byte types. So you need to convert the strings into their correct value types first. As someone who claims not to be a programmer, that is a lot of code that you have written.
-
You are trying to store the text strings into both those fields which are (presumably) byte types. So you need to convert the strings into their correct value types first. As someone who claims not to be a programmer, that is a lot of code that you have written.
:) Thanks...i use a lot of snippets too....so how do i convert them properly?..i already tried some methods but i could not do it! anyway..the code is functionning for pre-tagged files...i just cannot write the properties into new files :(
-
:) Thanks...i use a lot of snippets too....so how do i convert them properly?..i already tried some methods but i could not do it! anyway..the code is functionning for pre-tagged files...i just cannot write the properties into new files :(
-
:) Thanks...i use a lot of snippets too....so how do i convert them properly?..i already tried some methods but i could not do it! anyway..the code is functionning for pre-tagged files...i just cannot write the properties into new files :(
Unless you know "why" you want to convert a string to "byte" (which makes little sense in your present context) even knowing "how", will only get you a little bit further. And maybe "deeper" in the wrong direction.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
I don't know how you convert them because I am not clear on what type the target is. So you need to check the definition of those fields and use an appropriate method of the Convert Class (System) | Microsoft Learn[^].
well..they are just the Track ID and Genre ID in an mp3 file...can i change the main code and switch them to string?...this is why i posted the full code on the start!!!
-
well..they are just the Track ID and Genre ID in an mp3 file...can i change the main code and switch them to string?...this is why i posted the full code on the start!!!
I don't know the answer. You first need to know what actual type they are in the file: Byte, String, Int32, Int64, Bool etc. You then need to set a matching type in your code. Then when you get the user's selection, you may or may not need to convert what the user chooses into the appropriate type. But all that detail should have been decided before you put all this code together. And I am afraid there is far too much for anyone other than you, to know where to do this.
-
I don't know the answer. You first need to know what actual type they are in the file: Byte, String, Int32, Int64, Bool etc. You then need to set a matching type in your code. Then when you get the user's selection, you may or may not need to convert what the user chooses into the appropriate type. But all that detail should have been decided before you put all this code together. And I am afraid there is far too much for anyone other than you, to know where to do this.
i think i can do the conversion here:
Dim strTag As New String(" ", 3)
Dim strTitle As New String(" ", 30)
Dim strArtist As New String(" ", 30)
Dim strAlbum As New String(" ", 30)
Dim strYear As New String(" ", 4)
Dim strComment As New String(" ", 28)
Dim bytDummy As Byte
Dim bytTrack As Byte
Dim bytGenre As Bytesetting the "as byte" to "new string" but i do not know about the numbers here??!!!
-
I don't know the answer. You first need to know what actual type they are in the file: Byte, String, Int32, Int64, Bool etc. You then need to set a matching type in your code. Then when you get the user's selection, you may or may not need to convert what the user chooses into the appropriate type. But all that detail should have been decided before you put all this code together. And I am afraid there is far too much for anyone other than you, to know where to do this.
i think is Int32 :)
-
i think i can do the conversion here:
Dim strTag As New String(" ", 3)
Dim strTitle As New String(" ", 30)
Dim strArtist As New String(" ", 30)
Dim strAlbum As New String(" ", 30)
Dim strYear As New String(" ", 4)
Dim strComment As New String(" ", 28)
Dim bytDummy As Byte
Dim bytTrack As Byte
Dim bytGenre As Bytesetting the "as byte" to "new string" but i do not know about the numbers here??!!!
-
i think is Int32 :)
-
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
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.
-
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
-
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
-
Member Alienoiz wrote:
i tried this but no luck:
Why are you trying to store 32 bit integer values in 8 bit byte fields?
well..,like i say..im no coder...i just read snippets and try by error!
-
Member Alienoiz wrote:
i tried this but no luck:
Why are you trying to store 32 bit integer values in 8 bit byte fields?
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 :(((
-
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 :(((
-
Sorry, I really have no idea what that code is trying to do, so I cannnt say whether it is correct or not.
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