|
-
Jan 13th, 2011, 09:45 AM
#1
Thread Starter
New Member
Google Weather
Code:
Public Structure Weatherinfo
Dim Failed As Boolean
Dim errormessage As Exception
Dim location As String
Dim forcast_date As String
Dim checked_time_date As String
Dim humidity As String
Dim highf As String
Dim lowf As String
Dim highc As String
Dim lowc As String
Dim currenttempC As String
Dim currenttempF As String
Dim predicted_icon As String
Dim current_icon As String
Dim current_condition As String
Dim predicted_condition As String
Dim wind_condition As String
Dim day As String
End Structure
Public Function Grab_Weather(ByVal Location As String) As Weatherinfo
With Grab_Weather
.Failed = True
Try
Dim webclient As New Net.WebClient
Dim xml As String = webclient.DownloadString("http://www.google.com/ig/api?weather=" & Location)
xml = xml.Replace(Chr(34), "").Replace(vbNewLine, "")
If xml.Contains("<problem_cause data=/>") Then
.Failed = True
End If
.location = Mid(Mid(xml, xml.IndexOf("<city data=") + 12), 1, Mid(xml, xml.IndexOf("<city data=") + 12).IndexOf("/>"))
.forcast_date = Mid(Mid(xml, xml.IndexOf("<forecast_date data=") + 21), 1, Mid(xml, xml.IndexOf("<forecast_date data=") + 21).IndexOf("/>"))
.checked_time_date = Mid(Mid(xml, xml.IndexOf("<current_date_time data=") + 25), 1, Mid(xml, xml.IndexOf("<current_date_time data=") + 25).IndexOf("/>"))
.humidity = Mid(Mid(xml, xml.IndexOf("<humidity data=") + 16), 1, Mid(xml, xml.IndexOf("<humidity data=") + 16).IndexOf("/>"))
.highf = Mid(Mid(xml, xml.IndexOf("<high data=") + 12), 1, Mid(xml, xml.IndexOf("<high data=") + 12).IndexOf("/>"))
.lowf = Mid(Mid(xml, xml.IndexOf("<low data=") + 11), 1, Mid(xml, xml.IndexOf("<low data=") + 11).IndexOf("/>"))
.highc = Math.Round((((.highf - "32") / "9") * "5"), 0)
.lowc = Math.Round((((.lowf - "32") / "9") * "5"), 0)
.currenttempC = Mid(Mid(xml, xml.IndexOf("<temp_c data=") + 14), 1, Mid(xml, xml.IndexOf("<temp_c data=") + 14).IndexOf("/>"))
.currenttempF = Mid(Mid(xml, xml.IndexOf("<temp_f data=") + 14), 1, Mid(xml, xml.IndexOf("<temp_f data=") + 14).IndexOf("/>"))
.current_icon = Mid(Mid(xml, xml.IndexOf("<icon data=") + 12), 1, Mid(xml, xml.IndexOf("<icon data=") + 12).IndexOf("/>")) : .current_icon = "http://www.google.com" & .current_icon
.predicted_icon = Mid(xml, xml.IndexOf("<high data=")) : .predicted_icon = Mid(.predicted_icon, .predicted_icon.IndexOf("<icon data=") + 12) : .predicted_icon = Mid(.predicted_icon, 1, .predicted_icon.IndexOf("/>")) : .predicted_icon = "http://wwww.google.com" & .predicted_icon
.current_condition = Mid(Mid(xml, xml.IndexOf("<condition data=") + 17), 1, Mid(xml, xml.IndexOf("<condition data=") + 17).IndexOf("/>"))
.predicted_condition = Mid(xml, xml.IndexOf("<day_of_week data=")) : .predicted_condition = Mid(Mid(.predicted_condition, .predicted_condition.IndexOf("<condition data=") + 17), 1, Mid(.predicted_condition, .predicted_condition.IndexOf("<condition data=") + 16).IndexOf("/>") - 1)
.wind_condition = Mid(Mid(xml, xml.IndexOf("<wind_condition data=") + 22), 1, Mid(xml, xml.IndexOf("<wind_condition data=") + 22).IndexOf("/>"))
.day = Mid(Mid(xml, xml.IndexOf("<day_of_week data=") + 19), 1, Mid(xml, xml.IndexOf("<day_of_week data=") + 19).IndexOf("/>"))
MsgBox(.current_icon)
Catch ex As Exception
.Failed = True
.errormessage = ex
End Try
.Failed = False
End With
Grab_Weather = Nothing
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Grab_Weather("90078")
End Sub
Anyone know how I can display multiple "Weatherinfo" strings?
Example: msgbox(.current_icon(1) & vbcrlf & .currenticon(2)) ... and so on.
-
Jan 13th, 2011, 11:15 AM
#2
Re: Google Weather
What you need is create a form or a custom usercontrol that contains all the necessary controls (picturebox for the icon, textboxes, labels... for the data) and after you grab the weather, send the data tthis form/usercontrol to display it. A messagebox will not let you display pictures. It's for displaying text only basically. And yes, you can display multiple lines of text by the use of the newline character. It's probably easier to contruct the message first using string.format function, and then display it. For example:
Code:
Dim msg As String = String.Format("{1}{0}{2}{0}{3}", Environment.NewLine, "line 1", "line 2", "line 3")
MessageBox.Show(msg)
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jan 13th, 2011, 11:25 AM
#3
Thread Starter
New Member
Re: Google Weather
All I am parsing is the text, The rest I can add later on.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|