Results 1 to 12 of 12

Thread: How to extract certain data patterns from vb6 textbox input?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Talking How to extract certain data patterns from vb6 textbox input?

    Hi all .i got the following inside a textbox inside my vb6 form. I am looking for a way to ripp the song path and title from it and use them and insert them to mysql datbase. But i do not know how to ripp those part
    i be happy that an expert tell me how i can do it using vb6. The number of song path are not know in before and the parts
    that i want to write to mysql are shown in bold.Thanks


    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>

  2. #2
    Member
    Join Date
    Apr 2006
    Location
    Serbia
    Posts
    32

    Re: How to extract certain data patterns from vb6 textbox input?

    well if the format is in xml form then you can use MSXML to read it or you can try with my SimpleXMLParser, you can download it from http://planet-source-code.com/vb/scr...64975&lngWId=1
    it's made to be used with files and not with raw strings so you'll have to write the data first in a file and then to parse it with sxp
    (if you're using SimpleXMLParser):
    VB Code:
    1. Private Sub Command1_Click()
    2.   Dim Parser As New clsXMLParser
    3.   Dim Node As clsXMLNode
    4.   Dim Child As clsXMLNOde
    5.   Dim fn As Long
    6.   Dim i As Long
    7.  
    8.  Dim path As string
    9.   Dim title As String
    10.  
    11.   fn = FreeFile
    12.   Open "C:\temp.dat" For Output As #fn
    13.     Write #fn, text1.Text
    14.   Close #fn
    15.  
    16.   Call Parser.Parse("C:\temp.dat")
    17.   Call Kill("C:\temp.dat")
    18.  
    19.   Set Node = Parser.ParentNode
    20.    
    21.    For i=1 To Node.ChildrenCount
    22.       Set Child = Node.enumChild(i)
    23.       If lcase$(Child.Name) = "song" Then
    24.         path = Child.getAttribute("path")
    25.         title = Child.getAttribute("title")
    26.         'now you have song's path and title loaded into path and title variables
    27.         Debug.Print path, title
    28.       End If
    29.    Next
    30. End Sub

    regards,
    krcko

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to extract certain data patterns from vb6 textbox input?

    Thank u for u nice reply . Well actually the data in textbox can be of any format and it happens that has xml word is in it and i am just intrested in pulling the song path and title and be able to write them in mysql db.

    So i think xml is not involved much here. it is just i do not know how to find song path and title and remove the other parts! I have another text box with same data with out the word xml on it and i want to do the same thing with it.So i be happy if u show me a general way not specific to xml. In fact i am making lots of applications that deals with extracting certian patternt in data inside textbox so it would be good start for me to learn how to deal with such cases.
    I tried to run it but i got the following error shown in pics.Does this code deals will any type of data in textbox ? if yes could u tell me how to fix the erros.Thanks


    Last edited by tony007; Apr 25th, 2006 at 08:23 PM.

  4. #4
    Member
    Join Date
    Apr 2006
    Location
    Serbia
    Posts
    32

    Re: How to extract certain data patterns from vb6 textbox input?

    Well actually the data in textbox can be of any format and it happens that has xml word is in it and i am just intrested in pulling the song path and title and be able to write them in mysql db.
    are you sure you know what xml format is?
    sample:
    Code:
    <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>
    this is an xml formated string (it doesn't need to have <?xml..?> node defined it's just xml language declaration)

    So i be happy if u show me a general way not specific to xml. In fact i am making lots of applications that deals with extracting certian patternt in data inside textbox so it would be good start for me to learn how to deal with such cases.
    well that depends a lot on format of the string from which you're extracting data. if you have it in param="value" format then you search for (with instr) string "param=" and when you find it you look for the string after the = (you read char by char until you find terminating char)...


    I tried to run it but i got the following error shown in pics.Does this code deals will any type of data in textbox ? if yes could u tell me how to fix the erros.Thanks
    have you downloaded my code?
    http://planet-source-code.com/vb/scr...64975&lngWId=1
    when you download it add clsXMLParser and clsXMLNode to your project (Menu: Project->Add Class Module and browse the cls, do the same for both files)

    regards,
    krcko

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to extract certain data patterns from vb6 textbox input?

    Many thanks for u reply. I copied the 2 files to same folder as my project and i added them to my project but when i run it i get the following error:

    Code:
    Run-time error '42':
    
    Expected: <at line 1[1]
    and it is pointing to the following line:

    Call Err.Raise(errType, "XMLParser", Description)

    I be happy if u tell me how to fix it. I was thinking alll data types could be dealt with in the same way which was incorect :-)

  6. #6
    Member
    Join Date
    Apr 2006
    Location
    Serbia
    Posts
    32

    Re: How to extract certain data patterns from vb6 textbox input?

    well thats error in your xml input, if you're using this input:
    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>
    that '-' must not be there!
    so, this is correct xml:
    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>

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to extract certain data patterns from vb6 textbox input?

    Thank u for u reply .The '-' was type mistake i am running without it and get same error!! My project is stoped just i can not run this part so i be happy if show me how to fix it. is there any problem with property of my textbox or some thing ?Thanks

    enclosed is my project file as zip. I be happy if u look at it .Thanks
    Attached Files Attached Files
    Last edited by tony007; Apr 26th, 2006 at 10:59 AM.

  8. #8
    Member
    Join Date
    Apr 2006
    Location
    Serbia
    Posts
    32

    Re: How to extract certain data patterns from vb6 textbox input?

    sorry it was by bad.
    i told you to Write data to file which is wrong (cuz Write puts qoutes around string) you should Print it to file, so this is correct code:
    VB Code:
    1. Private Sub Command1_Click()
    2.   Dim Parser As New clsXMLParser
    3.   Dim Node As clsXMLNode
    4.   Dim Child As clsXMLNOde
    5.   Dim fn As Long
    6.   Dim i As Long
    7.    Dim path As string
    8.   Dim title As String
    9.  
    10.   fn = FreeFile
    11.   Open "C:\temp.dat" For Output As #fn
    12.     [b]Print[/b] #fn, text1.Text
    13.   Close #fn
    14.  
    15.   Call Parser.Parse("C:\temp.dat")
    16.   Call Kill("C:\temp.dat")
    17.  
    18.   Set Node = Parser.ParentNode
    19.    
    20.    For i=1 To Node.ChildrenCount
    21.       Set Child = Node.enumChild(i)
    22.       If lcase$(Child.Name) = "song" Then
    23.         path = Child.getAttribute("path")
    24.         title = Child.getAttribute("title")
    25.         'now you have song's path and title loaded into path and title variables
    26.         Debug.Print path, title
    27.       End If
    28.    Next
    29. End Sub

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to extract certain data patterns from vb6 textbox input?

    krckoorascic many thanks now it worked. Could u tell me how i can refrence path and song title so that i creat the mysql insert statement so i inter them to a mysql db?

    Furthermore , if i have a text file that has many blocks of music playlist info as shown above how i can read their song path and title. I be happy if u help me here.Thanks

    sample of text data:
    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>
    
    
    <?xml version="1.0" encoding="UTF-8" ?> 
     <player showDisplay="yes" showPlaylist="yes" autoStart="yes">
      <song path="http://www.mysite.com/TtdlI3l1lIl0OOO0a/singer1/album3/song3.mp3" title="song title" /> 
      <song path="http://www.mysite.com/TtdlI3l1lIl0OOO0a/singer1/album4/songname4.mp3" title="song title 2" /> 
      
      </player>
    
    
    ..........
    ........
    Last edited by tony007; Apr 26th, 2006 at 06:35 PM.

  10. #10
    Member
    Join Date
    Apr 2006
    Location
    Serbia
    Posts
    32

    Re: How to extract certain data patterns from vb6 textbox input?

    Could u tell me how i can refrence path and song title so that i creat the mysql insert statement so i inter them to a mysql db?
    never worked with mysql dbs (acctualy i rearly use databases i used access db only once, and that was long time ago ) so can't help ya there, but shouldn't the sql query be something like this:
    VB Code:
    1. query = "INSERT INTO table_name (path, title) VALUES ('" & path & "', '" & title & "')"
    ?

    and for the more block of data: well this:
    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>
    
    
    <?xml version="1.0" encoding="UTF-8" ?> 
     <player showDisplay="yes" showPlaylist="yes" autoStart="yes">
      <song path="http://www.mysite.com/TtdlI3l1lIl0OOO0a/singer1/album3/song3.mp3" title="song title" /> 
      <song path="http://www.mysite.com/TtdlI3l1lIl0OOO0a/singer1/album4/songname4.mp3" title="song title 2" /> 
      
      </player>
    is not valid xml form becouse xml document can have only one parent node (player node in your case) and only one xml definition node (which MUST be on top) which is <?xml ..?> node (my parser don't requires that node to be defined) you can have as much child nodes (and those child nodes can have their child nodes too and so on) as you want in your parent node, so this is the correct form:
    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" /> 
      <song path="http://www.mysite.com/TtdlI3l1lIl0OOO0a/singer1/album3/song3.mp3" title="song title" /> 
      <song path="http://www.mysite.com/TtdlI3l1lIl0OOO0a/singer1/album4/songname4.mp3" title="song title 2" /> 
      
      </player>

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to extract certain data patterns from vb6 textbox input?

    Thank u for u reply . could u tell me where in the loop should i place
    query = "INSERT INTO table_name (path, title) VALUES ('" & path & "', '" & title & "')"
    that it holds the corect values . Well the actual data from text box is valid xml but i had in mind to store many of them in .txt file and all at once read them and insert them in mysql !

  12. #12
    Member
    Join Date
    Apr 2006
    Location
    Serbia
    Posts
    32

    Re: How to extract certain data patterns from vb6 textbox input?

    well put it instead of the line
    VB Code:
    1. Debug.Print path, title

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