Quote:
| Originally Posted by ehsanking
data inside my texbox:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
- <player showDisplay="yes" showPlaylist="yes" autoStart="yes">
<song path="http://www.mysite.com/TtdlI3l1lIl0OOO0a/singer1/album1/song1.mp3" title="song title" />
<song path="http://www.mysite.com/TtdlI3l1lIl0OOO0a/singer1/album1/songname2.mp3" title="song title 2" />
</player>
|
Hi,
The following code demonstrates how you can do this, it assumes that you have a command button on your form (Command1) and that, although you may have lots of songs in the string they are always in the same format, i.e. song path first:
Code:
Dim pos As Integer
Dim string1 As String
Dim string2 As String
Dim songtitlearray() As String
Dim songpatharray() As String
Dim counter As Integer
Private Sub Command1_Click()
counter = 0
ReDim songpatharray(1)
ReDim songtitlearray(1)
string1 = Text1.Text
If InStr(1, string1, "song path=") Then
While InStr(1, string1, "song path=")
string2 = ""
pos = InStr(1, string1, "song path=")
string1 = Mid$(string1, pos + 11)
string2 = Left$(string1, InStr(1, string1, "title") - 3)
If counter > 1 Then
ReDim Preserve songtitlearray(counter)
ReDim Preserve songpatharray(counter)
End If
songtitlearray(counter) = string2
string1 = Mid$(string1, InStr(1, string1, "title") + 7)
string2 = Left$(string1, InStr(1, string1, "/") - 3)
string1 = Mid$(string1, InStr(1, string1, "/"))
songpatharray(counter) = string2
counter = counter + 1
Wend
End If
End Sub
This works by reading the information from your textbox (un-imaginatively called Text1 in my example!!!) and storing it in a variable called string1. The program will loop while string1 still contains the string "song path=", meaning that there is still data to extract. On each iteration, the program moves through the string extracting just the bits between the double quotes, string1 is cut down each time ensuring that the program does not go into a continuous loop!!
When the program has finished, the results should be held in two arrays: songtitlearray and songpatharray, with the subscripts starting from zero.
You can loop through them, I have quickly output the info. to control arrays of labels but you could easily write the info. out to your database within the loop:
Code:
For counter = 0 To UBound(songtitlearray)
Label1(counter) = songpatharray(counter)
Label2(counter) = songtitlearray(counter)
Next
Sorry about the late reply, I hadn't seen this post until now, apologies if you have already found the solution!!
Regards,
Bob