Very Basic Refresher Tutorial

Discussion in 'Code Snippets and Tutorials' started by the_skip, Mar 9, 2007.

  1. the_skip

    the_skip Level IV

    Joined:
    Dec 25, 2006
    Messages:
    2,354
    Likes Received:
    1
    Location:
    Indiana
    Ok all you need is the http wrapper and the moudle
    These should be on your form
    text box called txtusername
    text box called txtpass
    httpwrapper call httpwrapper
    the wait and stuff modules
    a buton called cmdrefresh
    a lable call lblstatus
    a button called cmd refresh
    here is the code
    Code (Text):
    1.  
    2. Public Function FindString(TextToSearch As String, StartText As String, EndText As String, Optional StartPos As Long = 1)
    3. Dim sText As Long, eText As Long
    4.  
    5. sText = InStr(StartPos, TextToSearch, StartText, vbTextCompare) + Len(StartText)
    6. eText = InStr(sText, TextToSearch, EndText, vbTextCompare)
    7. If sText >= Len(StartText) And eText > sText Then
    8.     FindString = Mid$(TextToSearch, sText, eText - sText)
    9. Else
    10.     FindString = ""
    11. End If
    12. End Function
    13. dim strhtml as string
    14. private sub cmdlogin_click()
    15. strHTML = Httpwrapper.PostWrapper("http://www.neopets.com/login.phtml", "username=" & txtUsername.Text & "&password=" & txtPassword.Text & "&destination=%2Fpetcentral.phtml", "http://www.neopets.com/hi.phtml")
    16.    
    17.     'Now to check if we logged in or not!
    18.     'Check for bad password.
    19.     If InStr(1, strHTML, "badpassword") <> 0 Then
    20.         MsgBox "You entered an invalid username/password combination!" & vbNewLine & "Please try again.", vbCritical, "Login Failure"
    21.     'Check if account is frozen.
    22.     ElseIf InStr(1, strHTML, "This account has been") <> 0 Then
    23.         MsgBox "ACCOUNT FROZEN!" & vbNewLine & "Please use another.", vbCritical, "Login Failure"
    24.     'Check if we tried to login to many times.
    25.     ElseIf InStr(1, strHTML, "too many times") <> 0 Then
    26.         MsgBox "You have tried to guess the password to many times in the last hour!" & vbNewLine & "Try again later.", vbCritical, "Login Failure"
    27. cmdrefersh.enable = true
    28. 'checks login
    29. strHTML = HttpWrapper.GetWrapper("http://neopets.com/petcentral.phtml")
    30. If InStr(1, strHTML, "Active Pet") <> 0 Then
    31. cmdrefresh.Enabled = False
    32. End If
    33. Private Sub cmdrefresh_()
    34. call refresh
    35. end sub
    36. Public Sub refresh()
    37. HttpWrapper.GetWrapper("http://neopets.com/winter/index.phtml")
    38. If InStr(1, strHTML, "Something has happened") <> 0 Then
    39. msgBox "You got a random event
    40. exit sub
    41. End if
    42. call refresh
    43.  
    44.  
    This is very basic and here is the exapmle of what to put afrter httpwrapper.getwrapper/postwrapper
    Code (Text):
    1. httpwrapper.getwrapper("place to sedn data to or go to", "data to send", "refer page aka page that will direct you to page in the fist place")
    2.  
    This will only check for a random event but will not tell you what it is
    This is just a good intro to your http wrapper and you
    +rep if I helped
    If you master this pm me and I could help you make this ten times better
     
  2. ZOMG

    ZOMG Level I

    Joined:
    Feb 26, 2007
    Messages:
    122
    Likes Received:
    0
    Location:
    Hipocresy Land
    Very usefull... If i PM you, cand you add how to make an advert to this program?
    Its like when you download something from firefox, a little advert in bottom right =D


    Edit;; Maybe adding images?
    Edit 2;; You forgot the cmdlogin =D
     
  3. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    This is wrong. The get and Post functions are completely different. You should use getwrapper when you want to load a page and check something in it, like a link or a name, while you should use postWrapper when you want to send data, such as a button click or a shop wizard search. In a refresher all you need to do is load a page and check for a "Something Has Happened!" String in it. Then you can also record the random event, but it wouldn't be a "easy" refresher anymore...

    Examples of the use of GetWrapper:
    Code (Text):
    1. Wrapper1.GetWrapper("http://www.***.com/index.phtml", _ 'this is the link we want to load
    2. "http://www.***.com/petcentral.phtml") 'this is the refer link
    The refer link is used most in the Postwrapper function, because sometimes a page won't load if the refer is not the right one. An example? The login itself. If you try deleting the refer (http://www.***.com/hi.phtml), the code won't log you in anymore.
    If someone doesn't understand anything of the above, then PM me ;)
     
  4. ZOMG

    ZOMG Level I

    Joined:
    Feb 26, 2007
    Messages:
    122
    Likes Received:
    0
    Location:
    Hipocresy Land
    the wrapper1,does not it depend on the name that you choose?
     
  5. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    Yes, but it is an example...