Results 1 to 28 of 28

Thread: little help again (RESOLVED)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Resolved little help again (RESOLVED)

    Hi all
    I have received excellent help here and am back for a little more. I have an app that will write an xml file however it is currently writing it like this
    <?xml version="1.0"?>
    <songs>
    <song path="my_mp3s\ 05 - Swamp.mp3" artist="Michael Kamen" title="05 - Swamp.mp3"/>
    </songs>

    But I need it to be displayed like this

    <?xml version="1.0"?>
    <songs>
    <song path="my_mp3s/song.mp3"artist="" title=""/>

    </songs>

    I just need to remove the spacing nand change the slash here is the code that performs this but I'm not sure what needs changing I have played about with it but having no luck. Hop someone can help. Thanks

    VB Code:
    1. Private Sub Command2_Click()
    2. Dim f1 As Integer, xmlpath As String, songpath As String, mp3path As String, f2 As Integer, i As Integer
    3.     Dim Artist As String, SongName As String, artname As String, fname As String, MyPath As String
    4.  
    5.     Dim mytag As Boolean
    6.    mp3path = "C:\mgamerz\my_mp3s\"
    7.    xmlpath = "C:\mgamerz\ "
    8.  
    9.  
    10.      
    11.      SongName = Dir(mp3path & "\*.mp3")
    12.      fname = mp3path & SongName
    13.      
    14.             With Form4
    15.    
    16.     While Not Len(SongName) = 0
    17.        
    18. '        Artist = GetMP3Tag(fname)
    19.                 If Not i = 0 Then
    20.                     Load .Label1(i): Load .Text1(i)
    21.                     .Label1(i).Top = .Label1(i - 1).Top + 350
    22.                     .Text1(i).Top = .Text1(i - 1).Top + 350
    23.                     .Label1(i).Visible = True: .Text1(i).Visible = True
    24.                    
    25.                 End If
    26.                
    27.                 .Label1(i) = SongName
    28.                 mytag = GetMP3Tag(fname)
    29.                 .Text1(i) = RTrim(MP3Info.sArtist)
    30.                      
    31.  
    32.         SongName = Dir
    33.              fname = mp3path & SongName
    34.  
    35.         i = i + 1
    36.    
    37.     Wend
    38.                 .Height = .Text1(.Text1.Count - 1).Top + 1600
    39.                 .TAG = mp3path
    40.                 MDIForm1.Caption = "You must close this form before continuing"
    41.                 .Show
    42. '                .WindowState = 2
    43.             End With
    44.     TAG = "wait"
    45.     While TAG = "wait"
    46.     DoEvents
    47.     Wend
    48.    
    49.      
    50.    i = 1
    51.      f2 = FreeFile
    52.     Open mp3path & "mp3.txt" For Output As #f2
    53.      f1 = FreeFile
    54.      
    55.     Open xmlpath & "audiolist.xml" For Output As #f1
    56.    
    57.    
    58.     Print #f1, "<?xml version=""1.0""?>"
    59.     Print #f1, "<songs>"
    60.     SongName = Dir(mp3path & "\*.mp3")
    61.     i = 1
    62.     While Not Len(SongName) = 0
    63.        
    64.         ' if you can return the name of the artist you put the code in here
    65.  
    66.                 mytag = GetMP3Tag(mp3path & SongName)
    67.                 Artist = RTrim(MP3Info.sArtist)
    68.                  If Len(Artist) = 0 Then Artist = "UNKOWN"
    69.                  
    70.                  
    71.                   MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath) + 1)) & " " & SongName
    72.        
    73.        songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & SongName & """/> "
    74.  
    75.        
    76.         Print #f1, songpath
    77.         Print #f2, SongName
    78.         Sleep 100
    79.         SongName = Dir
    80.    
    81.     Wend
    82.  
    83.     Print #f1, "</songs>"
    84. Close
    85.  
    86. End Sub
    Last edited by robvr6; Feb 6th, 2005 at 12:42 AM. Reason: resolved

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    Here is the first part, which changes the slash.


    VB Code:
    1. pos=instr(mytag,"\")
    2. mid(mytag,8,1)="/"


    I am using this as a template.

    mytag="my_mp3s\ 05 - Swamp.mp3"

    it now looks like this:

    my_mp3s/ 05 - Swamp.mp3


    What else do you want done to it. Change it exactly. I can't tell if you want the track number removed, and the spaces, or what. Also, do you need to change the title at all?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    Hi David, thanks fo replying I bet your fed up with me lol.
    All I think it needs changing is the slash and for there to be no spaces in the title of the track because its funny because it will work if the xml is hand coded for example if I had a mp3 track named rob.mp3 and I hand coded it like this it will work
    <?xml version="1.0"?>
    <songs>
    <song path="my_mp3s/rob.mp3"artist="name" title="songname"/>

    </songs>

    So I am thinking that if there are no spaces it may work. Also where do I need to add the code you just posted.
    Thanks
    Rob

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    Click Private Messages in the upper right hand corner. You have a PM.


    Do you need the spaces removed only the first time?

  5. #5
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    202

    Re: little help again

    maybe you can also use the Replace function to change all of a certain character in a string

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    VB Code:
    1. ' if you can return the name of the artist you put the code in here
    2.  
    3.              mytag = GetMP3Tag(mp3path & SongName)
    4.              pos = InStr(mytag, "\")
    5.              Mid(mytag, pos, 1) = "/"
    6.              Do While InStr(mytag, " ")
    7.                mytag = Replace(mytag, " ", "")
    8.              Loop
    9.  
    10.              Artist = RTrim(MP3Info.sArtist)
    11.              If Len(Artist) = 0 Then Artist = "UNKOWN"
    12.                  
    13.                  
    14.              MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath) + 1)) & " " & SongName
    15.        
    16.        songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & SongName & """/> "


    This should be what you need. Let me know if it isn't!
    EDIT: You have to add Dim pos As Integer at the top
    Last edited by dglienna; Feb 5th, 2005 at 10:52 PM.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    It is just the spaces before and after the slash that I think needs removing so its just like this because I think that is why the player cannot read it

    <song path="my_mp3s/rob.mp3 "artist="name" title="songname"/>

    thanks Rob

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    my_mp3s/05-Swamp.mp3

    the song remains the same

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    do I need to declare pos as something because I get a compile error - variable not defined.
    Cheers
    Rob

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    Mid(mytag, 8, 1) = type mismatch error.

    ignore the previous post.
    Rob

  11. #11
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    oops. it worked as I stepped through it. You can delete the pos lines.

    VB Code:
    1. ' mytag = "my_mp3s\ 05 - Swamp.mp3"
    2. ' pos = InStr(mytag, "\")
    3. 'Debug.Print pos
    4.  
    5. mytag = Replace(mytag, "\", "/")
    6. Do While InStr(mytag, " ")
    7.   mytag = Replace(mytag, " ", "")
    8. Loop


    my_mp3s/05-Swamp.mp3

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    <?xml version="1.0"?>
    <songs>
    <song path="my_mp3s\ The Streets - Weak Become Heroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
    </songs> Im still gettin it like this

    Heres the code I think Ive changed everything right If poss would you check
    thanks Rob

    VB Code:
    1. Private Sub Command2_Click()
    2. Dim f1 As Integer, xmlpath As String, songpath As String, mp3path As String, f2 As Integer, i As Integer, pos As Integer
    3.     Dim Artist As String, SongName As String, artname As String, fname As String, MyPath As String
    4.  
    5.     Dim mytag As Boolean
    6.    mp3path = "C:\mgamerz\my_mp3s\"
    7.    xmlpath = "C:\mgamerz\ "
    8.  
    9.  
    10.      
    11.      SongName = Dir(mp3path & "\*.mp3")
    12.      fname = mp3path & SongName
    13.      
    14.             With Form4
    15.    
    16.     While Not Len(SongName) = 0
    17.        
    18. '        Artist = GetMP3Tag(fname)
    19.                 If Not i = 0 Then
    20.                     Load .Label1(i): Load .Text1(i)
    21.                     .Label1(i).Top = .Label1(i - 1).Top + 350
    22.                     .Text1(i).Top = .Text1(i - 1).Top + 350
    23.                     .Label1(i).Visible = True: .Text1(i).Visible = True
    24.                    
    25.                 End If
    26.                
    27.                 .Label1(i) = SongName
    28.                 mytag = GetMP3Tag(fname)
    29.                 .Text1(i) = RTrim(MP3Info.sArtist)
    30.                      
    31.  
    32.         SongName = Dir
    33.              fname = mp3path & SongName
    34.  
    35.         i = i + 1
    36.    
    37.     Wend
    38.                 .Height = .Text1(.Text1.Count - 1).Top + 1600
    39.                 .TAG = mp3path
    40.                 MDIForm1.Caption = "You must close this form before continuing"
    41.                 .Show
    42. '                .WindowState = 2
    43.             End With
    44.     TAG = "wait"
    45.     While TAG = "wait"
    46.     DoEvents
    47.     Wend
    48.    
    49.      
    50.    i = 1
    51.      f2 = FreeFile
    52.     Open mp3path & "mp3.txt" For Output As #f2
    53.      f1 = FreeFile
    54.      
    55.     Open xmlpath & "audiolist.xml" For Output As #f1
    56.    
    57.    
    58.     Print #f1, "<?xml version=""1.0""?>"
    59.     Print #f1, "<songs>"
    60.     SongName = Dir(mp3path & "\*.mp3")
    61.     i = 1
    62.     While Not Len(SongName) = 0
    63.        
    64.         ' if you can return the name of the artist you put the code in here
    65.  
    66.                 mytag = GetMP3Tag(mp3path & SongName)
    67.              'pos = InStr(mytag, "\")
    68.              
    69.              mytag = Replace(mytag, "\", "/")
    70.              
    71.  
    72.              Do While InStr(mytag, " ")
    73.                mytag = Replace(mytag, " ", "")
    74.              Loop
    75.  
    76.              Artist = RTrim(MP3Info.sArtist)
    77.              If Len(Artist) = 0 Then Artist = "UNKOWN"
    78.                  
    79.                  
    80.              MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath) + 1)) & " " & SongName
    81.        
    82.        songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & SongName & """/> "
    83.  
    84.        
    85.         Print #f1, songpath
    86.         Print #f2, SongName
    87.         Sleep 100
    88.         SongName = Dir
    89.    
    90.     Wend
    91.  
    92.     Print #f1, "</songs>"
    93. Close
    94.  
    95. End Sub

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    that's right. the only thing that i would suggest would be to line everything up properly to make it easier to read and maintain. put everything 2,4,6, or 8 spaces from the left. it makes things easier to read.

    I think that is what you need. Hope you are satisfied

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    my xml is still coming out like this though <?xml version="1.0"?>
    <songs>
    <song path="my_mp3s\ The Streets - Weak Become Heroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
    </songs>

    instead of this

    <?xml version="1.0"?>
    <songs>
    <song path="my_mp3s/song.mp3"artist="" title=""/>

    </songs>

    sorry to mither
    rob

  15. #15
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    Hmm. I guess we don't need mypath anymore.

    change this:

    songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & SongName & """/> "

    to


    songpath = "<song path=""" & MyTag & """ artist=""" & Artist & """ title=""" & SongName & """/> "

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    I did that but I got this
    <?xml version="1.0"?>
    <songs>
    <song path="False" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
    </songs>


    Rob

  17. #17
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    or else, move the lines to below mypath, and change slightly.

    VB Code:
    1. Artist = RTrim(MP3Info.sArtist)
    2.              If Len(Artist) = 0 Then Artist = "UNKOWN"
    3.                  
    4.                  
    5.              MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath) + 1)) & " " & SongName
    6.        
    7.              myPath = Replace(myPath, "\", "/")
    8.              
    9.  
    10.              Do While InStr(myPath, " ")
    11.                myPath = Replace(myPath, " ", "")
    12.              Loop
    13.  
    14.        songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & SongName & """/> "

    I forgot that the path was wrong. I didn't have the program tonight.

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    Thanks I think that has sorted it out finally. Can I ask advice again tomorrow when the person who is developing the flash tests it?

    Thanks again
    Rib

  19. #19
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Resolved Re: little help again

    Sure. I'll be around some of the time. Superbowl tomorrow, so I may be going out to watch it. If not, I'll be online.
    Last edited by dglienna; Feb 5th, 2005 at 11:40 PM.

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    Sorry just one quick question, How can i leave the spaces in the title of the track <song path="my_mp3s/The Streets - Weak Become Heroes.mp3".

    its just the space after the slash that needs removing. Otherwise its working brilliant you know instead of this

    <song path="my_mp3s/TheStreets-WeakBecomeHeroes.mp3"

  21. #21
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    Try to change this:

    VB Code:
    1. Do While InStr(myPath, " ")
    2.   myPath = Replace(myPath, " ", "")
    3. Loop

    to this:

    VB Code:
    1. ' Do While InStr(myPath, " ")
    2.   myPath = Replace(myPath, " ", "")
    3. ' Loop

    it will just replace on space.

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    it still does the same because all it needs is the name of the mp3 file to be the same as the original but before when it had spaces it left one after the slash which meant it didnt read the file correctly

  23. #23
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    if you take out the do loop, it only removes one space. what is wrong? I am missing something.

  24. #24

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    it is coming out like this
    <?xml version="1.0"?>
    <songs>
    <song path="my_mp3s/TheStreets-WeakBecomeHeroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
    </songs>

    but I need it to come out like this

    <?xml version="1.0"?>
    <songs>
    <song path="my_mp3s/The Streets - Weak Become Heroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
    </songs>

  25. #25
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    ok, just delete the lines, instead of commenting them out.

    Try to change this:


    VB Code:
    1. Do While InStr(myPath, " ")
    2.   myPath = Replace(myPath, " ", "")
    3. Loop

    to this:

    VB Code:
    1. myPath = Replace(myPath, " ", "")

    if that doesn't work, post the code again...
    oops. I just found something interesting.

    VB Code:
    1. myPath = Replace(myPath, " ", "",1,1)

    the first number is the Start, and the second is Count.

    this will ALWAYS remove one space from the string. hope that is good enough
    Last edited by dglienna; Feb 6th, 2005 at 12:30 AM.

  26. #26

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: little help again

    still comin out like this
    <song path="my_mp3s/TheStreets-WeakBecomeHeroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
    </songs>

    instead of this'
    <song path="my_mp3s/The Streets - Weak Become Heroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
    </songs>

  27. #27
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: little help again

    I've edited my post. include ,1,1 for start and count (number of replaces)

    i was told incorrect information. I thought the do loop was needed to keep removing spaces until the end, when only one would have removed them all.

    we both learned something tonight.
    Last edited by dglienna; Feb 6th, 2005 at 12:34 AM.

  28. #28

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Resolved Re: little help again (RESOLVED)

    Brilliant - Thanks very much indeed for all the help!!
    Rob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width