Adblock breaks this site

[HELP] Parseing in vb6

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

  1. dgameman1

    dgameman1 Active Member
    Banned

    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0
    [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?
     
  2. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    [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
     
  3. dgameman1

    dgameman1 Active Member
    Banned

    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0
    [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
     
  4. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    [HELP] Parseing in vb6

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

    Code:
    msgbox = getbetween(1,strhtml,<h1>,</h1>) 
    try that.
     
  5. dgameman1

    dgameman1 Active Member
    Banned

    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0
    [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
     
  6. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    [HELP] Parseing in vb6

    uhh whoops do this:
    Code:
    msgbox = getbetween(1,strhtml,"<h1>","</h1>")
     
  7. dgameman1

    dgameman1 Active Member
    Banned

    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0
    [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
     
  8. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    [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
     
  9. dgameman1

    dgameman1 Active Member
    Banned

    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0
    [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
     
  10. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    [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.
     
  11. dgameman1

    dgameman1 Active Member
    Banned

    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0
    [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?
     
  12. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    [HELP] Parseing in vb6

    Incorrect
     
  13. dgameman1

    dgameman1 Active Member
    Banned

    Joined:
    May 25, 2006
    Posts:
    122
    Referrals:
    0
    Sythe Gold:
    0
    [HELP] Parseing in vb6

    Then why is that code highlighted?
     
  14. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    [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,..;
     
  15. Hiatus

    Hiatus Member

    Joined:
    Feb 27, 2011
    Posts:
    29
    Referrals:
    0
    Sythe Gold:
    0
    [HELP] Parseing in vb6

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

    /facepalm
     
  16. _trevaSaurus

    _trevaSaurus Newcomer

    Joined:
    Jun 14, 2011
    Posts:
    16
    Referrals:
    0
    Sythe Gold:
    0
    [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 >


 
 
Adblock breaks this site