Results 1 to 9 of 9

Thread: Try and Spot The Error! I can't :(

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2004
    Location
    Computer
    Posts
    56

    Try and Spot The Error! I can't :(

    What this does is it goes through the array "items" and if in the current element contains what is contained in the variable item, then it parses it down. Now it worked earlier when Item was a variable, but rather a set value, but now it doesn't. Can you spot the error?


    VB Code:
    1. Private Function GetItems(Item As String)
    2. Dim items() As String
    3. Dim H As Integer
    4.  
    5. MsgBox Item
    6. Item = Parse(HTML, "' onClick=""", "(you can still haggle to push the price lower!)') ) { return false; }""", True)
    7. items() = Split(Item, vbCrLf)
    8. For H = 0 To UBound(items)
    9.  MsgBox items(H)
    10.  If InStr(1, items(H), Item, vbTextCompare) Then
    11.   URL = Between(items(H), "this.href='", "'; if ( !confirm('Are you sure you wish to purchase")
    12.   MsgBox URL
    13.   Exit Function
    14.  End If
    15. Next H
    16. End Function

    Many thanks!
    ~!~Computer Nerd~!~

  2. #2
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Chesterfield, Mi
    Posts
    259

    Re: Try and Spot The Error! I can't :(

    someone likes neopets...

    You do realize some of your single quotes should be double.... your commenting out your own code.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Try and Spot The Error! I can't :(

    Quote Originally Posted by mstic
    You do realize some of your single quotes should be double.... your commenting out your own code.
    Not the case, since the aproprostrophes are inside double quote marks. Symbols within string literals are not processed.

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2004
    Location
    Computer
    Posts
    56

    Re: Try and Spot The Error! I can't :(

    Meh. It's taught me a lot making programs for neopets. And it just appears that they are comments because of the board, javascript uses single quotes.
    ~!~Computer Nerd~!~

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

    Re: Try and Spot The Error! I can't :(

    Is this VB? What is the PARSE function?

  6. #6
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Chesterfield, Mi
    Posts
    259

    Re: Try and Spot The Error! I can't :(

    He wrote the parse somewhere else in his code.
    His problem is in the line:
    If InStr(1, items(H), Item, vbTextCompare) Then

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

    Re: Try and Spot The Error! I can't :(

    Quote Originally Posted by mstic
    He wrote the parse somewhere else in his code.
    His problem is in the line:
    If InStr(1, items(H), Item, vbTextCompare) Then
    Item is the full document. It cannot be the string2
    String2 should be something that you want to find in each of the split lines.

    InStr([start, ]string1, string2[, compare])

    The InStr function syntax has thesearguments:

    Part Description
    start Optional.Numeric expression that sets the starting position for each search. If omitted, search begins at the first character position. If start containsNull, an error occurs. The start argument is required if compare is specified.
    string1 Required.String expression being searched.
    string2 Required. String expression sought.
    compare Optional. Specifies the type ofstring comparison. If compare is Null, an error occurs. If compare is omitted, the Option Compare setting determines the type of comparison.

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2004
    Location
    Computer
    Posts
    56

    Re: Try and Spot The Error! I can't :(

    The parse function is:
    VB Code:
    1. Public Function Parse(Source As String, Starting As String, Ending As String, Multi As Boolean) As String
    2. Dim strData As String
    3. strData = Source
    4.  
    5. Dim iStart As Long
    6. Dim iEnd As Long
    7. Dim sTemp As String
    8. Dim sText() As String
    9.  
    10. Length = Len(Starting)
    11. If Length = 0 Then
    12. MsgBox "Error: No String found", vbCritical, "Error"
    13. Exit Function
    14. End If
    15.  
    16.  
    17. If Multi = True Then
    18.  
    19. iStart = 1
    20. Do Until InStr(iStart, strData, Starting, vbTextCompare) = 0
    21. iStart = InStr(iStart, strData, Starting, vbTextCompare) + Length
    22. iEnd = InStr(iStart, strData, Ending, vbTextCompare)
    23. sTemp = sTemp & Mid$(strData, iStart, iEnd - iStart) & vbCrLf
    24. Loop
    25.  
    26. sTemp = Left$(sTemp, Len(sTemp) - 2)
    27. sText = Split(sTemp, vbCrLf)
    28. Parse = sTemp
    29. Exit Function
    30.  
    31. ElseIf Multi = False Then
    32.  
    33. iStart = InStr(1, strData, Starting, vbTextCompare) + Length
    34. iEnd = InStr(iStart, strData, Ending, vbTextCompare)
    35. strText = Mid$(strData, iStart, iEnd - iStart)
    36.  
    37. If strText = vbNullString Then
    38. MsgBox "Error: No string found", vbCritical, "Error"
    39. Exit Function
    40. End If
    41.  
    42. Parse = strText
    43.  
    44. End If
    45. End Function
    ~!~Computer Nerd~!~

  9. #9
    Frenzied Member Devion's Avatar
    Join Date
    Sep 2000
    Location
    The Netherlands
    Posts
    1,049

    Re: Try and Spot The Error! I can't :(

    Aint u missing something here?

    !confirm('Are you sure you wish to purchase") <-- shouldn't that be '") instead of ") ?

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