Results 1 to 3 of 3

Thread: winsock[resolved]

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2002
    Posts
    33

    winsock[resolved]

    Can anyone help me with using winsock to go to a site and get certain text like for example

    go to www.wunderground.com, put in the zip code then pull the weather info it gives you. thanks
    Last edited by SCREAMING; Mar 20th, 2003 at 11:16 PM.

  2. #2
    Junior Member
    Join Date
    Feb 2003
    Location
    Newport, NC
    Posts
    20
    What you will need:
    [list]6 Text boxes
    [list=1][*]txtLocation[*]txtTemperature[*]txtCondition[*]txtHumidity[*]txtZip[*]txtBuffer[/list=1]
    1 Command button
    [list=1][*]cmdGet[/list=1]
    1 Winsock control
    1. Wsck1[/list=1]

    VB Code:
    1. Public Sub Pause(Length As Double)
    2. Dim StartTime
    3. StartTime = Timer
    4. Do While Timer - StartTime < Length
    5. DoEvents
    6. Loop
    7. End Sub
    8. ---------------------------------------------------------------
    9. Private Sub cmdGet_Click()
    10. txtBuffer.Text = ""
    11. Wsck1.Close
    12. Wsck1.Connect "wunderground.com", 80
    13. End Sub
    14. ---------------------------------------------------------------
    15. Private Sub Wsck1_Close()
    16. Dim Str1 As String, Str2 As String, Str3 As String
    17.  
    18. On Error GoTo Weather_Error
    19. Pause 0.5
    20. Wsck1.Close
    21. Wsck1.Tag = "CLOSED"
    22. If txtBuffer.Text <> "" Then txtBuffer.Text = Mid(txtBuffer.Text, InStr(txtBuffer.Text, "<"), Len(txtBuffer.Text))
    23.  
    24. 'Location
    25. Str1 = Mid(txtBuffer.Text, InStr(txtBuffer.Text, "<title>Weather Underground: ") + 28, Len(txtBuffer.Text))
    26. Str1 = Mid(Str1, 1, InStr(Str1, " Forecast</title>") - 1)
    27. txtLocation = Str1
    28.  
    29. 'Temperature
    30. Str1 = Mid(txtBuffer.Text, InStr(txtBuffer.Text, "<tr BGCOLOR=#FFFFFF><td>Temperature</td>") + 68, Len(txtBuffer.Text))
    31. Str1 = Mid(Str1, 1, InStr(Str1, "</b>&nbsp;°F") - 1)
    32. txtTemperature = Str1 & "°"
    33.  
    34. 'Conditions
    35. Str1 = Mid(txtBuffer.Text, InStr(txtBuffer.Text, "<tr BGCOLOR=#FFFFFF><td>Conditions</td>") + 47, Len(txtBuffer.Text))
    36. Str1 = Mid(Str1, 1, InStr(Str1, "</b></td></tr>") - 1)
    37. txtCond = Str1
    38.  
    39. 'Humudity
    40. Str1 = Mid(txtBuffer.Text, InStr(txtBuffer.Text, "<tr BGCOLOR=#FFFFFF><td>Humidity</td>") + 45, Len(txtBuffer.Text))
    41. Str1 = Mid(Str1, 1, InStr(Str1, "%</b></td></tr>") - 1)
    42. txtHumidity = Str1 & "%"
    43. Exit Sub
    44.  
    45. Weather_Error:
    46. MsgBox "Weather unavailable, try again", vbInformation, "Winsock Error"
    47. End Sub
    48. ---------------------------------------------------------------
    49. Private Sub Wsck1_Connect()
    50. Wsck1.Tag = "OPEN"
    51. Wsck1.SendData "GET [url]http://www.wunderground.com/cgi-bin/findweather/getForecast?query=[/url]" & txtZip & " HTTP/1.0" + vbCrLf + "Accept: */*" + vbCrLf + "Accept: text/html" + vbCrLf + vbCrLf
    52. End Sub
    53. ---------------------------------------------------------------
    54. Private Sub Wsck1_DataArrival(ByVal bytesTotal As Long)
    55. Dim Buffer As String
    56. If Wsck1.Tag = "OPEN" Then Wsck1.GetData Buffer
    57. txtBuffer.Text = txtBuffer.Text + Buffer
    58. End Sub
    59. ---------------------------------------------------------------
    60. Private Sub Wsck1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    61. MsgBox "Weather unavailable, try again", vbInformation, "Winsock Error"
    62. End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2002
    Posts
    33

    thanks

    thanks for the help

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