So I have this script based on Martin's weather gadget. When you click onthe temperature it should change between Fahrenheit and Celcius. The odd thing is after it goes from Fahrenheit to celcius, when you click it again the Fahrenheit temperature and condition changes. I am not sure what is causing it. Can anyone help me? This is a very odd issue.
Code for weather
Code: vbscript
- Dim location
- Dim tempunit
- Dim summary(5)
- Dim summarymessage
- Sub Object_OnScriptEnter
- summarymessage=""'(mouse over images to show summary)"
- Dim filestring, filesys, filetxt
- filestring = DesktopX.ExecutableDirectory & "weather.ini"
-
- Set filesys = CreateObject("Scripting.FileSystemObject")
-
- If filesys.FileExists(filestring) Then
- firstrun = False
- Else
- firstrun = True
- End If
-
- If firstrun = True Then
- Set WshNetwork = CreateObject("WScript.Network")
- UserName = WshNetwork.UserName
- Set UserName = Nothing
- Set WshNetwork = Nothing
- location = "06514"
- tempunit = "s"
-
- Else
- Set filetxt = filesys.OpenTextFile(filestring)
- location = filetxt.ReadLine
- tempunit = filetxt.ReadLine
- filetxt.Close
- End If
-
- Set filestring = Nothing
- Set filesys = Nothing
- Set filetxt = Nothing
- Set firstrun = Nothing
- Object.SetTimer 6001, 600000
- Object_OnTimer6001
- End Sub
-
- Sub Object_OnScriptExit
- Dim filestring, filesys, filetxt, getname, path
- filestring = DesktopX.ExecutableDirectory & "weather.ini"
- Set filesys = CreateObject("Scripting.FileSystemObject")
- Set filetxt = filesys.CreateTextFile(filestring, True)
- path = filesys.GetAbsolutePathName(filestring)
- getname = filesys.GetFileName(path)
- filetxt.Write(location & vbNewLine & tempunit)
- filetxt.Close
-
- Set filestring = Nothing
- Set filesys = Nothing
- Set filetxt = Nothing
- Set path = Nothing
- Set getname = Nothing
- End Sub
-
- Sub Object_OnTimer6001
- If System.InternetConnected Then
- On Error Resume Next
- ' Create a web object
- Set http = CreateObject("Microsoft.XmlHttp")
- ' Retrieve data
- Randomize
- str_RANDOM_URL = "&rnd=" & rnd()
- If tempunit = "m" Then
- str_UNITS = "&unit=m"
- Else
- str_UNITS = "&unit=s"
- End If
- http.Open "GET", "http://xoap.weather.com/weather/local/" & location & "?cc=*&dayf=5" & str_UNITS & str_RANDOM_URL, False
- http.send ""
- ' Store data in a string
- weatherdata = http.responseText
-
- If weatherdata <> "" Then
- ' As the feed is XML it is nicely structured, and it makes sense to use a simple function to extract data father than string manipulation
- ' Set the location using the xmlstrupper function (see below) to get the city and state
- weathertemp = xmlstripper("<dnam>", weatherdata)
- If weathertemp = "" Then
- Msgbox "This doesn't appear to be a valid zip code." & vbNewLine & vbNewLine & "Please try again.", vbExclamation + vbOKOnly, "Zip error ..."
- x = InputBox("Please enter the zip code that you would like to display the weather for:", "Select zip code ...", "06514")
- location = x
- Object_OnTimer6001
- Exit Sub
- Else
- If IsNumeric(location) Then weathertemp = Left(weathertemp, InStr(weathertemp, "(")-2)
- 'This is splitting the location into 2 lines
- tempstring = weathertemp
- firstpart = Left(tempstring, InStr(tempstring,",")-1)
- secondpart = Right(tempstring, Len(tempstring) - InStr(tempstring,",") - 1)
-
- DesktopX.ScriptObject("Weather City").Object.Text = firstpart & ", " & secondpart
-
- 'Country Abbreviations ISO 3166 Jan 7 2007
- Select Case secondpart
- Case "Afghanistan" secondpart = "AFG"
- Case "Albania" secondpart = "ALB"
- Case "Algeria" secondpart = "DZA"
- Case "American Samoa" secondpart = "ASM"
- Case "Andorra" secondpart = "AND"
- Case "Angola" secondpart = "AGO"
- Case "Anguilla" secondpart = "AIA"
- Case "Antarctica" secondpart = "ATA"
- Case "Antigua And Barbuda" secondpart = "ATG"
- Case "Argentina" secondpart = "ARG"
- Case "Armenia" secondpart = "ARM"
- Case "Aruba" secondpart = "ABW"
- Case "Australia" secondpart = "AUS"
- Case "Austria" secondpart = "AUT"
- Case "Azerbaijan" secondpart = "AZE"
- Case "The Bahamas" secondpart = "BHS"
- Case "Bahrain" secondpart = "BHR"
- Case "Bangladesh" secondpart = "BGD"
- Case "Barbados" secondpart = "BRB"
- Case "Belarus" secondpart = "BLR"
- Case "Belgium" secondpart = "BEL"
- Case "Belize" secondpart = "BLZ"
- Case "Benin" secondpart = "BEN"
- Case "Bermuda" secondpart = "BMU"
- Case "Bhutan" secondpart = "BTN"
- Case "Bolivia" secondpart = "BOL"
- Case "Bosnia And Herzegovina" secondpart = "BIH"
- Case "Botswana" secondpart = "BWA"
- Case "Bouvet Island" secondpart = "BVT"
- Case "Brazil" secondpart = "BRA"
- Case "British Indian Ocean Territory (Chagos Archipelago)" secondpart = "IOT"
- Case "British Virgin Islands" secondpart = "VGB"
- Case "Brunei" secondpart = "BRN"
- Case "Bulgaria" secondpart = "BGR"
- Case "Burkina Faso" secondpart = "BFA"
- Case "Burundi" secondpart = "BDI"
- Case "Cambodia" secondpart = "KHM"
- Case "Cameroon" secondpart = "CMR"
- Case "Canada" secondpart = "CAN"
- Case "Cape Verde" secondpart = "CPV"
- Case "Cayman Islands" secondpart = "CYM"
- Case "Central African Republic" secondpart = "CAF"
- Case "Chad" secondpart = "TCD"
- Case "Chile" secondpart = "CHL"
- Case "China" secondpart = "CHN"
- Case "Christmas Island" secondpart = "CXR"
- Case "Cocos (Keeling) Islands" secondpart = "CCK"
- Case "Colombia" secondpart = "COL"
- Case "Comoros" secondpart = "COM"
- Case "Democratic Republic of The Congo" secondpart = "COD"
- Case "Republic of The Congo" secondpart = "COG"
- Case "Cook Islands" secondpart = "COK"
- Case "Costa Rica" secondpart = "CRI"
- Case "Cote D' Ivoire" secondpart = "CIV"
- Case "Cuba" secondpart = "CUB"
- Case "Cyprus" secondpart = "CYP"
- Case "Czech Republic" secondpart = "CZE"
- Case "Denmark" secondpart = "DNK"
- Case "Djibouti" secondpart = "DJI"
- Case "Dominicaf" secondpart = "DMA"
- Case "Dominican Republic" secondpart = "DOM"
- Case "Ecuador" secondpart = "ECU"
- Case "Egypt" secondpart = "EGY"
- Case "El Salvador" secondpart = "SLV"
- Case "Equatorial Guinea" secondpart = "GNQ"
- Case "Eritrea" secondpart = "ERI"
- Case "Estonia" secondpart = "EST"
- Case "Ethiopia" secondpart = "ETH"
- Case "Faeroe Islands" secondpart = "FRO"
- Case "Falkland Islands" secondpart = "FLK"
- Case "Fiji" secondpart = "FJI"
- Case "Finland" secondpart = "FIN"
- Case "France" secondpart = "FRA"
- Case "French Guiana" secondpart = "GUF"
- Case "French Polynesia" secondpart = "PYF"
- Case "French Southern Territories" secondpart = "ATF"
- Case "Gabon" secondpart = "GAB"
- Case "The Gambia" secondpart = "GMB"
- Case "Georgia" secondpart = "GEO"
- Case "Germany" secondpart = "DEU"
- Case "Ghana" secondpart = "GHA"
- Case "Gibraltar" secondpart = "GIB"
- Case "Greece" secondpart = "GRC"
- Case "Greenland" secondpart = "GRL"
- Case "Grenada" secondpart = "GRD"
- Case "Guadeloupe" secondpart = "GLP"
- Case "Guam" secondpart = "GUM"
- Case "Guatemala" secondpart = "GTM"
- Case "Guinea" secondpart = "GIN"
- Case "Guinea-bissau" secondpart = "GNB"
- Case "Guyana" secondpart = "GUY"
- Case "Haiti" secondpart = "HTI"
- Case "Heard And McDonald Islands" secondpart = "HMD"
- Case "Vatican City" secondpart = "VAT"
- Case "Honduras" secondpart = "HND"
- Case "Hong Kong" secondpart = "HKG"
- Case "Croatia" secondpart = "HRV"
- Case "Hungary" secondpart = "HUN"
- Case "Iceland" secondpart = "ISL"
- Case "India" secondpart = "IND"
- Case "Indonesia" secondpart = "IDN"
- Case "Iran" secondpart = "IRN"
- Case "Iraq" secondpart = "IRQ"
- Case "Ireland" secondpart = "IRL"
- Case "Israel" secondpart = "ISR"
- Case "Italy" secondpart = "ITA"
- Case "Jamaica" secondpart = "JAM"
- Case "Japan" secondpart = "JPN"
- Case "Jordan" secondpart = "JOR"
- Case "Kazakhstan" secondpart = "KAZ"
- Case "Kenya" secondpart = "KEN"
- Case "Kiribati" secondpart = "KIR"
- Case "North Korea" secondpart = "PRK"
- Case "South Korea" secondpart = "KOR"
- Case "Kuwait" secondpart = "KWT"
- Case "Kyrgyzstan" secondpart = "KGZ"
- Case "Laos" secondpart = "LAO"
- Case "Latvia" secondpart = "LVA"
- Case "Lebanon" secondpart = "LBN"
- Case "Lesotho" secondpart = "LSO"
- Case "Liberia" secondpart = "LBR"
- Case "Libya" secondpart = "LBY"
- Case "Liechtenstein" secondpart = "LIE"
- Case "Lithuania" secondpart = "LTU"
- Case "Luxembourg" secondpart = "LUX"
- Case "Macao" secondpart = "MAC"
- Case "Former Yugoslav Rep. of Macedonia" secondpart = "MKD"
- Case "Madagascar" secondpart = "MDG"
- Case "Malawi" secondpart = "MWI"
- Case "Malaysia" secondpart = "MYS"
- Case "Maldives" secondpart = "MDV"
- Case "Mali" secondpart = "MLI"
- Case "Malta" secondpart = "MLT"
- Case "Marshall Islands" secondpart = "MHL"
- Case "Martinique" secondpart = "MTQ"
- Case "Mauritania" secondpart = "MRT"
- Case "Mauritius" secondpart = "MUS"
- Case "Mayotte" secondpart = "MYT"
- Case "Mexico" secondpart = "MEX"
- Case "Federated States Of Micronesia" secondpart = "FSM"
- Case "Moldova" secondpart = "MDA"
- Case "Monaco" secondpart = "MCO"
- Case "Mongolia" secondpart = "MNG"
- Case "Montserrat" secondpart = "MSR"
- Case "Morocco" secondpart = "MAR"
- Case "Mozambique" secondpart = "MOZ"
- Case "Burma" secondpart = "MMR"
- Case "Namibia" secondpart = "NAM"
- Case "Nauru" secondpart = "NRU"
- Case "Nepal" secondpart = "NPL"
- Case "Netherlands Antilles" secondpart = "ANT"
- Case "Netherlands" secondpart = "NLD"
- Case "New Caledonia" secondpart = "NCL"
- Case "New Zealand" secondpart = "NZL"
- Case "Nicaragua" secondpart = "NIC"
- Case "Niger" secondpart = "NER"
- Case "Nigeria" secondpart = "NGA"
- Case "Niue, Republic of" secondpart = "NIU"
- Case "Norfolk Island" secondpart = "NFK"
- Case "Northern Mariana Islands" secondpart = "MNP"
- Case "Norway" secondpart = "NOR"
- Case "Oman" secondpart = "OMN"
- Case "Pakistan" secondpart = "PAK"
- Case "Palau" secondpart = "PLW"
- Case "West Bank" secondpart = "PSE"
- Case "Panama" secondpart = "PAN"
- Case "Papua New Guinea" secondpart = "PNG"
- Case "Paraguay" secondpart = "PRY"
- Case "Peru" secondpart = "PER"
- Case "Philippines" secondpart = "PHL"
- Case "Pitcairn Island" secondpart = "PCN"
- Case "Poland" secondpart = "POL"
- Case "Portugal" secondpart = "PRT"
- Case "Puerto Rico" secondpart = "PRI"
- Case "Qatar" secondpart = "QAT"
- Case "Reunion" secondpart = "REU"
- Case "Romania" secondpart = "ROU"
- Case "Russia" secondpart = "RUS"
- Case "Rwanda" secondpart = "RWA"
- Case "St. Helena" secondpart = "SHN"
- Case "St. Kitts And Nevis" secondpart = "KNA"
- Case "Saint Lucia" secondpart = "LCA"
- Case "St. Pierre And Miquelon" secondpart = "SPM"
- Case "St. Vincent And the Grenadines" secondpart = "VCT"
- Case "Samoa" secondpart = "WSM"
- Case "San Marino" secondpart = "SMR"
- Case "Sao Tome and Principe" secondpart = "STP"
- Case "Saudi Arabia" secondpart = "SAU"
- Case "Senegal" secondpart = "SEN"
- Case "Serbia And Montenegro" secondpart = "SCG"
- Case "Seychelles" secondpart = "SYC"
- Case "Sierra Leone" secondpart = "SLE"
- Case "Singapore" secondpart = "SGP"
- Case "Slovakia" secondpart = "SVK"
- Case "Slovenia" secondpart = "SVN"
- Case "Solomon Islands" secondpart = "SLB"
- Case "Somalia" secondpart = "SOM"
- Case "South Africa" secondpart = "ZAF"
- Case "South Georgia And the South Sandwich Islands" secondpart = "SGS"
- Case "Spain" secondpart = "ESP"
- Case "Sri Lanka" secondpart = "LKA"
- Case "Sudan" secondpart = "SDN"
- Case "Suriname" secondpart = "SUR"
- Case "Svalbard & Jan Mayen Islands" secondpart = "SJM"
- Case "Swaziland" secondpart = "SWZ"
- Case "Sweden" secondpart = "SWE"
- Case "Switzerland" secondpart = "CHE"
- Case "Syria" secondpart = "SYR"
- Case "Taiwan" secondpart = "TWN"
- Case "Tajikistan" secondpart = "TJK"
- Case "United Republic of Tanzania" secondpart = "TZA"
- Case "Thailand" secondpart = "THA"
- Case "Timor-Leste, Democratic Republic of" secondpart = "TLS"
- Case "Togo" secondpart = "TGO"
- Case "Tokelau (Tokelau Islands)" secondpart = "TKL"
- Case "Tonga" secondpart = "TON"
- Case "Trinidad and Tobago" secondpart = "TTO"
- Case "Tunisia" secondpart = "TUN"
- Case "Turkey" secondpart = "TUR"
- Case "Turkmenistan" secondpart = "TKM"
- Case "Turks And Caicos Islands" secondpart = "TCA"
- Case "Tuvalu (was part of Gilbert & Ellice Islands)" secondpart = "TUV"
- Case "US Virgin Islands" secondpart = "VIR"
- Case "Uganda" secondpart = "UGA"
- Case "Ukraine" secondpart = "UKR"
- Case "United Arab Emirates" secondpart = "ARE"
- Case "United Kingdom" secondpart = "GBR"
- Case "United States Minor Outlying Islands" secondpart = "UMI"
- Case "United States" secondpart = "USA"
- Case "Uruguay" secondpart = "URY"
- Case "Uzbekistan" secondpart = "UZB"
- Case "Vanuatu" secondpart = "VUT"
- Case "Venezuela" secondpart = "VEN"
- Case "Vietnam" secondpart = "VNM"
- Case "Wallis And Futuna Islands" secondpart = "WLF"
- Case "Western Sahara" secondpart = "ESH"
- Case "Yemen" secondpart = "YEM"
- Case "Yugoslavia" secondpart = "YUG"
- Case "Zambia" secondpart = "ZMB"
- Case "Zimbabwe" secondpart = "ZWE"
-
- End Select
- Set tempstring = Nothing
- Set firstpart = Nothing
- Set secondpart = Nothing
- End If
- ' The data doesn't have degrees symbols in it, so rip out the data, insert the symbols, then store it
- If str_UNITS = "&unit=s" Then
- weathertemp = xmlstripper("<tmp>", weatherdata) & Chr(176)' & "F"
- Else
- weathertemp = xmlstripper("<tmp>", weatherdata) & Chr(176)' & "C"
- End If
- Object.PersistStorage("Fahrenheit") = weathertemp
- DesktopX.ScriptObject("Weather Temp").Object.Text = Object.PersistStorage("Fahrenheit")
- ' Strip out all the other info
- conditions = xmlstripper("<cc>", weatherdata)
- conditions = xmlstripper("<t>", conditions)
- desktopx.Object("Weather Conditions").text = conditions
-
- conditions = xmlstripper("<icon>", weatherdata)
- Object.PersistStorage("Conditions") = conditions
- If IsNumeric(conditions) Then
- Object.State = conditions
- Else
- Object.State = "NA"
- End If
- End If
-
- ' Clear variables for clean code
- Set http = nothing
- Set weatherdata = Nothing
- Set weathertemp = Nothing
- Set forecastdatastart = Nothing
- Set forecastdataend = Nothing
- End If
- End Sub
-
-
- Function xmlstripper(param, string)
- datastart = InStr(string, param) + Len(param)
- datalength = Instr(string, "</" & Right(param, Len(param) - 1)) - datastart
- xmlstripper = Mid(string, datastart, datalength)
- End Function
Code on Temperature Object
Code: vbscript
- Function Object_OnLButtonUp(x,y,dragged)
- If dragged = False Then
- If DesktopX.ScriptObject("Weather Icon").tempunit = "m" Then
- DesktopX.ScriptObject("Weather Icon").tempunit = "s"
- Else
- DesktopX.ScriptObject("Weather Icon").tempunit = "m"
- End If
- DesktopX.ScriptObject("Weather Icon").Object_OnTimer6001
- End If
- End Function
Any help would be great.