[HELP] Parseing in vb6

Discussion in 'Programming General' started by dgameman1, Mar 26, 2011.

[HELP] Parseing in vb6
  1. Unread #1 - Mar 26, 2011 at 3:54 PM
  2. dgameman1
    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0

    dgameman1 Active Member
    Banned

    [HELP] Parseing in vb6

    I am trying to learn how to parse information.
    For my first time, I want a messagebox to be able to say
    "Example of a simple HTML page"
    (http://help.nucleus.com/example_of_a_simple_html_page.htm)

    So this is my code
    Code:
    Option Explicit
    
    Private Function GetBetween(ByVal Start As Long, Data As String, _
        StartString As String, EndString As String, _
        Optional ByVal CompareMethod As VbCompareMethod = vbBinaryCompare) As String
        
        Dim lonStart As Long, lonEnd As Long
        
        '1. Find start string.
        lonStart = InStr(1, HTML, "<h1>", vbTextCompare)
        
        If lonStart > 0 Then
            '2. Move to end of start string.
            lonStart = lonStart + Len("<h1>")
    
            '3. Find end string.
            lonEnd = InStr(lonStart, HTML, "</h1>", vbTextCompare)
            
            If lonEnd > 0 Then
                '4. Extract data between start and end strings.
                GetBetween = Mid$(HTML, lonStart, lonEnd - lonStart)
                
                'Done!
            MsgBox GetBetween
    
            End If
        End If
        
    End Function
    
    
    Now how do I make it so that it know what site to go to and how do I also make it so that when I press "Command1" it will parse that information?
     
  3. Unread #2 - Mar 26, 2011 at 7:30 PM
  4. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [HELP] Parseing in vb6

    You will need to add an Inet Control to your form and make sure it's called 'Inet1'.

    Code:
    Option Explicit
    
    private sub command1_click()
    
        dim strhtml as string
        strhtml = inet1.openurl("http://help.nucleus.com/example_of_a_simple_html_page.htm")
        msgbox getbetween(1,strhtml,<h1>,</h1>)
    
    end sub
    
    Private Function GetBetween(ByVal Start As Long, Data As String, _
        StartString As String, EndString As String, _
        Optional ByVal CompareMethod As VbCompareMethod = vbBinaryCompare) As String
        
        Dim lonStart As Long, lonEnd As Long
        
        '1. Find start string.
        lonStart = InStr(1, data, startstring, comparemethod)
        
        If lonStart > 0 Then
            '2. Move to end of start string.
            lonStart = lonStart + Len(startstring)
    
            '3. Find end string.
            lonEnd = InStr(lonStart, data, endstring, comparemethod)
            
            If lonEnd > 0 Then
                '4. Extract data between start and end strings.
                GetBetween = Mid$(data, lonStart, lonEnd - lonStart)
            End If
        End If
        
    End Function
     
  5. Unread #3 - Mar 27, 2011 at 1:44 AM
  6. dgameman1
    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0

    dgameman1 Active Member
    Banned

    [HELP] Parseing in vb6

    Ok so now this is my whole code

    Code:
    Option Explicit
    
    Private Sub command1_click()
    
        Dim strhtml As String
        strhtml = Inet1.OpenURL("http://help.nucleus.com/example_of_a_simple_html_page.htm")
        msgbox getbetween(1,strhtml,<h1>,</h1>)
    
    End Sub
    Private Function GetBetween(ByVal Start As Long, Data As String, _
        StartString As String, EndString As String, _
        Optional ByVal CompareMethod As VbCompareMethod = vbBinaryCompare) As String
        
        Dim lonStart As Long, lonEnd As Long
        
        '1. Find start string.
        lonStart = InStr(1, HTML, "<h1>", vbTextCompare)
        
        If lonStart > 0 Then
            '2. Move to end of start string.
            lonStart = lonStart + Len("<h1>")
    
            '3. Find end string.
            lonEnd = InStr(lonStart, HTML, "</h1>", vbTextCompare)
            
            If lonEnd > 0 Then
                '4. Extract data between start and end strings.
                GetBetween = Mid$(HTML, lonStart, lonEnd - lonStart)
                
    
            End If
        End If
        
    End Function
    
    Syntax error on
    Code:
    Private Sub command1_click()
    
        Dim strhtml As String
        strhtml = Inet1.OpenURL("http://help.nucleus.com/example_of_a_simple_html_page.htm")
        msgbox getbetween(1,strhtml,<h1>,</h1>)
    
    End Sub
    msgbox getbetween(1,strhtml,<h1>,</h1>) is red
     
  7. Unread #4 - Mar 27, 2011 at 5:58 AM
  8. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [HELP] Parseing in vb6

    umm, VB6 might need an equal sign (=) after msgbox? i forget....

    Code:
    msgbox = getbetween(1,strhtml,<h1>,</h1>) 
    try that.
     
  9. Unread #5 - Mar 27, 2011 at 3:10 PM
  10. dgameman1
    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0

    dgameman1 Active Member
    Banned

    [HELP] Parseing in vb6

    Rawrrr
    This is my whole code
    Code:
    Option Explicit
    
    Private Sub command1_click()
    
        Dim strhtml As String
        strhtml = Inet1.OpenURL("http://help.nucleus.com/example_of_a_simple_html_page.htm")
        msgbox = getbetween(1,strhtml,<h1>,</h1>)
    
    End Sub
    Private Function GetBetween(ByVal Start As Long, Data As String, _
        StartString As String, EndString As String, _
        Optional ByVal CompareMethod As VbCompareMethod = vbBinaryCompare) As String
        
        Dim lonStart As Long, lonEnd As Long
        
        '1. Find start string.
        lonStart = InStr(1, HTML, "<h1>", vbTextCompare)
        
        If lonStart > 0 Then
            '2. Move to end of start string.
            lonStart = lonStart + Len("<h1>")
    
            '3. Find end string.
            lonEnd = InStr(lonStart, HTML, "</h1>", vbTextCompare)
            
            If lonEnd > 0 Then
                '4. Extract data between start and end strings.
                GetBetween = Mid$(HTML, lonStart, lonEnd - lonStart)
                
    
            End If
        End If
        
    End Function
    
    Syntax error on
    Code:
    Private Sub command1_click()
    
        Dim strhtml As String
        strhtml = Inet1.OpenURL("http://help.nucleus.com/example_of_a_simple_html_page.htm")
        msgbox = getbetween(1,strhtml,<h1>,</h1>)
    
    End Sub
    msgbox = getbetween(1,strhtml,<h1>,</h1>) is red
     
  11. Unread #6 - Mar 27, 2011 at 4:04 PM
  12. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [HELP] Parseing in vb6

    uhh whoops do this:
    Code:
    msgbox = getbetween(1,strhtml,"<h1>","</h1>")
     
  13. Unread #7 - Mar 27, 2011 at 4:22 PM
  14. dgameman1
    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0

    dgameman1 Active Member
    Banned

    [HELP] Parseing in vb6

    lolwtf

    "Compile Error:
    Function call on left-hand side of assignment must return Variant or Object"

    My whole code

    Code:
    Option Explicit
    
    Private Sub command1_click()
    
        Dim strhtml As String
        strhtml = Inet1.OpenURL("http://help.nucleus.com/example_of_a_simple_html_page.htm")
        MsgBox = GetBetween(1, strhtml, "<h1>", "</h1>")
    
    End Sub
    Private Function GetBetween(ByVal Start As Long, Data As String, _
        StartString As String, EndString As String, _
        Optional ByVal CompareMethod As VbCompareMethod = vbBinaryCompare) As String
        
        Dim lonStart As Long, lonEnd As Long
        
        '1. Find start string.
        lonStart = InStr(1, HTML, "<h1>", vbTextCompare)
        
        If lonStart > 0 Then
            '2. Move to end of start string.
            lonStart = lonStart + Len("<h1>")
    
            '3. Find end string.
            lonEnd = InStr(lonStart, HTML, "</h1>", vbTextCompare)
            
            If lonEnd > 0 Then
                '4. Extract data between start and end strings.
                GetBetween = Mid$(HTML, lonStart, lonEnd - lonStart)
                
    
            End If
        End If
        
    End Function
    
    Code:
    Private Sub command1_click()
    
        Dim strhtml As String
        strhtml = Inet1.OpenURL("http://help.nucleus.com/example_of_a_simple_html_page.htm")
        MsgBox = GetBetween(1, strhtml, "<h1>", "</h1>")
    
    End Sub
    Private Sub command1_click() is yellow
     
  15. Unread #8 - Mar 27, 2011 at 9:23 PM
  16. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [HELP] Parseing in vb6

    Remove the equal sign after the msgbox.... Dude you need to at least try instead of posting your errors and expecting others to fix them
     
  17. Unread #9 - Mar 27, 2011 at 9:28 PM
  18. dgameman1
    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0

    dgameman1 Active Member
    Banned

    [HELP] Parseing in vb6

    But I don't exactly know what the error means.. so I don't know what to fix =O

    This is variable unidentified

    Code:
    [b]Private Function GetBetween(ByVal Start As Long, Data As String, _
        StartString As String, EndString As String, _
        Optional ByVal CompareMethod As VbCompareMethod = vbBinaryCompare) As String[/b]
    is highlighted =O
     
  19. Unread #10 - Mar 28, 2011 at 7:02 AM
  20. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [HELP] Parseing in vb6

    I can see the problem, i suggest you try looking for it.
    I'll give you a hit, change one of your variable names to something the system doesn't already use.
     
  21. Unread #11 - Mar 28, 2011 at 7:06 PM
  22. dgameman1
    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0

    dgameman1 Active Member
    Banned

    [HELP] Parseing in vb6

    So you're telling me that somewhere in
    Code:
    [b]Private Function GetBetween(ByVal Start As Long, Data As String, _
        StartString As String, EndString As String, _
        Optional ByVal CompareMethod As VbCompareMethod = vbBinaryCompare) As String[/b]
    is a variable that is not defined?
     
  23. Unread #12 - Mar 28, 2011 at 9:13 PM
  24. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [HELP] Parseing in vb6

    Incorrect
     
  25. Unread #13 - Mar 28, 2011 at 9:45 PM
  26. dgameman1
    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0

    dgameman1 Active Member
    Banned

    [HELP] Parseing in vb6

    Then why is that code highlighted?
     
  27. Unread #14 - Mar 29, 2011 at 5:31 AM
  28. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [HELP] Parseing in vb6

    Because you are using a variable in that "GetBetween" function that isn't defined.....

    You need to change one of the following variables:
    Start
    Data
    StartString
    EndString

    to a variable you are using in your code, that you HAVEN'T declared....
    If you can't work that out for yourself, i'm sorry but i'm not going to bother helping you...As i've already done 100% of what you were asking,..;
     
  29. Unread #15 - Mar 29, 2011 at 7:23 PM
  30. Hiatus
    Joined:
    Feb 27, 2011
    Posts:
    29
    Referrals:
    0
    Sythe Gold:
    0

    Hiatus Member

    [HELP] Parseing in vb6

    He pretty much just fixed the problem for you. Another thing, why are you using vb6? Its so old.

    /facepalm
     
  31. Unread #16 - Jun 14, 2011 at 1:54 AM
  32. _trevaSaurus
    Joined:
    Jun 14, 2011
    Posts:
    16
    Referrals:
    0
    Sythe Gold:
    0

    _trevaSaurus Newcomer

    [HELP] Parseing in vb6

    This is such A simple task.

    Parsing one item from a site:
    Code:
    dim spSplit as string
    spSplit = split(split(returnedData,"Tags Before")(Your delimeter example, 1"),"Tags After")(0)
    Parsing more then one item:
    Code:
    dim sp() as string, i as long
    sp() = split(returnedData,"Before Tags")
    for i = 0 to ubound(sp())
    sp(i) = split(sp(i),"After Tags")(0)
    
    msgbox sp(i)
    
    next i

    Use:
    Put it in your command button, make sure you name your objects.

    Should work, I didn't open vb6 to test so...
     
< Threading / Concurrency | NEEDED: Programming tutor >

Users viewing this thread
1 guest


 
 
Adblock breaks this site