Weird Weather Issue

Thursday, February 26, 2009 by JukEboXAuDiO | Discussion: DesktopX

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
  1. Dim location
  2. Dim tempunit
  3. Dim summary(5)
  4. Dim summarymessage
  5. Sub Object_OnScriptEnter
  6. summarymessage=""'(mouse over images to show summary)"
  7. Dim filestring, filesys, filetxt
  8. filestring = DesktopX.ExecutableDirectory & "weather.ini"
  9.  
  10. Set filesys = CreateObject("Scripting.FileSystemObject")
  11.  
  12. If filesys.FileExists(filestring) Then
  13. firstrun = False
  14. Else
  15. firstrun = True
  16. End If
  17.  
  18. If firstrun = True Then
  19. Set WshNetwork = CreateObject("WScript.Network")
  20. UserName = WshNetwork.UserName
  21. Set UserName = Nothing
  22. Set WshNetwork = Nothing
  23. location = "06514"
  24. tempunit = "s"
  25.  
  26. Else
  27. Set filetxt = filesys.OpenTextFile(filestring)
  28. location = filetxt.ReadLine
  29. tempunit = filetxt.ReadLine
  30. filetxt.Close
  31. End If
  32.  
  33. Set filestring = Nothing
  34. Set filesys = Nothing
  35. Set filetxt = Nothing
  36. Set firstrun = Nothing
  37. Object.SetTimer 6001, 600000
  38. Object_OnTimer6001
  39. End Sub
  40.  
  41. Sub Object_OnScriptExit
  42. Dim filestring, filesys, filetxt, getname, path
  43. filestring = DesktopX.ExecutableDirectory & "weather.ini"
  44. Set filesys = CreateObject("Scripting.FileSystemObject")
  45. Set filetxt = filesys.CreateTextFile(filestring, True)
  46. path = filesys.GetAbsolutePathName(filestring)
  47. getname = filesys.GetFileName(path)
  48. filetxt.Write(location & vbNewLine & tempunit)
  49. filetxt.Close
  50.  
  51. Set filestring = Nothing
  52. Set filesys = Nothing
  53. Set filetxt = Nothing
  54. Set path = Nothing
  55. Set getname = Nothing
  56. End Sub
  57.  
  58. Sub Object_OnTimer6001
  59. If System.InternetConnected Then
  60. On Error Resume Next
  61. ' Create a web object
  62. Set http = CreateObject("Microsoft.XmlHttp")
  63. ' Retrieve data
  64. Randomize
  65. str_RANDOM_URL = "&rnd=" & rnd()
  66. If tempunit = "m" Then
  67. str_UNITS = "&unit=m"
  68. Else
  69. str_UNITS = "&unit=s"
  70.    End If
  71. http.Open "GET", "http://xoap.weather.com/weather/local/" & location & "?cc=*&dayf=5" & str_UNITS & str_RANDOM_URL, False
  72. http.send ""
  73. ' Store data in a string
  74. weatherdata = http.responseText
  75. If weatherdata <> "" Then
  76. ' 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
  77. ' Set the location using the xmlstrupper function (see below) to get the city and state
  78. weathertemp = xmlstripper("<dnam>", weatherdata)
  79. If weathertemp = "" Then
  80. Msgbox "This doesn't appear to be a valid zip code." & vbNewLine & vbNewLine & "Please try again.", vbExclamation + vbOKOnly, "Zip error ..."
  81. x = InputBox("Please enter the zip code that you would like to display the weather for:", "Select zip code ...", "06514")
  82. location = x
  83. Object_OnTimer6001
  84. Exit Sub
  85. Else
  86. If IsNumeric(location) Then weathertemp = Left(weathertemp, InStr(weathertemp, "(")-2)
  87. 'This is splitting the location into 2 lines
  88. tempstring = weathertemp
  89. firstpart = Left(tempstring, InStr(tempstring,",")-1)
  90. secondpart = Right(tempstring, Len(tempstring) - InStr(tempstring,",") - 1)
  91. DesktopX.ScriptObject("Weather City").Object.Text = firstpart & ", " & secondpart
  92. 'Country Abbreviations ISO 3166 Jan 7 2007
  93. Select Case secondpart
  94. Case "Afghanistan" secondpart = "AFG"
  95. Case "Albania" secondpart = "ALB"
  96. Case "Algeria" secondpart = "DZA"
  97. Case "American Samoa" secondpart = "ASM"
  98. Case "Andorra" secondpart = "AND"
  99. Case "Angola" secondpart = "AGO"
  100. Case "Anguilla" secondpart = "AIA"
  101. Case "Antarctica" secondpart = "ATA"
  102. Case "Antigua And Barbuda" secondpart = "ATG"
  103. Case "Argentina" secondpart = "ARG"
  104. Case "Armenia" secondpart = "ARM"
  105. Case "Aruba" secondpart = "ABW"
  106. Case "Australia" secondpart = "AUS"
  107. Case "Austria" secondpart = "AUT"
  108. Case "Azerbaijan" secondpart = "AZE"
  109. Case "The Bahamas" secondpart = "BHS"
  110. Case "Bahrain" secondpart = "BHR"
  111. Case "Bangladesh" secondpart = "BGD"
  112. Case "Barbados" secondpart = "BRB"
  113. Case "Belarus" secondpart = "BLR"
  114. Case "Belgium" secondpart = "BEL"
  115. Case "Belize" secondpart = "BLZ"
  116. Case "Benin" secondpart = "BEN"
  117. Case "Bermuda" secondpart = "BMU"
  118. Case "Bhutan" secondpart = "BTN"
  119. Case "Bolivia" secondpart = "BOL"
  120. Case "Bosnia And Herzegovina" secondpart = "BIH"
  121. Case "Botswana" secondpart = "BWA"
  122. Case "Bouvet Island" secondpart = "BVT"
  123. Case "Brazil" secondpart = "BRA"
  124. Case "British Indian Ocean Territory (Chagos Archipelago)" secondpart = "IOT"
  125. Case "British Virgin Islands" secondpart = "VGB"
  126. Case "Brunei" secondpart = "BRN"
  127. Case "Bulgaria" secondpart = "BGR"
  128. Case "Burkina Faso" secondpart = "BFA"
  129. Case "Burundi" secondpart = "BDI"
  130. Case "Cambodia" secondpart = "KHM"
  131. Case "Cameroon" secondpart = "CMR"
  132. Case "Canada" secondpart = "CAN"
  133. Case "Cape Verde" secondpart = "CPV"
  134. Case "Cayman Islands" secondpart = "CYM"
  135. Case "Central African Republic" secondpart = "CAF"
  136. Case "Chad" secondpart = "TCD"
  137. Case "Chile" secondpart = "CHL"
  138. Case "China" secondpart = "CHN"
  139. Case "Christmas Island" secondpart = "CXR"
  140. Case "Cocos (Keeling) Islands" secondpart = "CCK"
  141. Case "Colombia" secondpart = "COL"
  142. Case "Comoros" secondpart = "COM"
  143. Case "Democratic Republic of The Congo" secondpart = "COD"
  144. Case "Republic of The Congo" secondpart = "COG"
  145. Case "Cook Islands" secondpart = "COK"
  146. Case "Costa Rica" secondpart = "CRI"
  147. Case "Cote D' Ivoire" secondpart = "CIV"
  148. Case "Cuba" secondpart = "CUB"
  149. Case "Cyprus" secondpart = "CYP"
  150. Case "Czech Republic" secondpart = "CZE"
  151. Case "Denmark" secondpart = "DNK"
  152. Case "Djibouti" secondpart = "DJI"
  153. Case "Dominicaf" secondpart = "DMA"
  154. Case "Dominican Republic" secondpart = "DOM"
  155. Case "Ecuador" secondpart = "ECU"
  156. Case "Egypt" secondpart = "EGY"
  157. Case "El Salvador" secondpart = "SLV"
  158. Case "Equatorial Guinea" secondpart = "GNQ"
  159. Case "Eritrea" secondpart = "ERI"
  160. Case "Estonia" secondpart = "EST"
  161. Case "Ethiopia" secondpart = "ETH"
  162. Case "Faeroe Islands" secondpart = "FRO"
  163. Case "Falkland Islands" secondpart = "FLK"
  164. Case "Fiji" secondpart = "FJI"
  165. Case "Finland" secondpart = "FIN"
  166. Case "France" secondpart = "FRA"
  167. Case "French Guiana" secondpart = "GUF"
  168. Case "French Polynesia" secondpart = "PYF"
  169. Case "French Southern Territories" secondpart = "ATF"
  170. Case "Gabon" secondpart = "GAB"
  171. Case "The Gambia" secondpart = "GMB"
  172. Case "Georgia" secondpart = "GEO"
  173. Case "Germany" secondpart = "DEU"
  174. Case "Ghana" secondpart = "GHA"
  175. Case "Gibraltar" secondpart = "GIB"
  176. Case "Greece" secondpart = "GRC"
  177. Case "Greenland" secondpart = "GRL"
  178. Case "Grenada" secondpart = "GRD"
  179. Case "Guadeloupe" secondpart = "GLP"
  180. Case "Guam" secondpart = "GUM"
  181. Case "Guatemala" secondpart = "GTM"
  182. Case "Guinea" secondpart = "GIN"
  183. Case "Guinea-bissau" secondpart = "GNB"
  184. Case "Guyana" secondpart = "GUY"
  185. Case "Haiti" secondpart = "HTI"
  186. Case "Heard And McDonald Islands" secondpart = "HMD"
  187. Case "Vatican City" secondpart = "VAT"
  188. Case "Honduras" secondpart = "HND"
  189. Case "Hong Kong" secondpart = "HKG"
  190. Case "Croatia" secondpart = "HRV"
  191. Case "Hungary" secondpart = "HUN"
  192. Case "Iceland" secondpart = "ISL"
  193. Case "India" secondpart = "IND"
  194. Case "Indonesia" secondpart = "IDN"
  195. Case "Iran" secondpart = "IRN"
  196. Case "Iraq" secondpart = "IRQ"
  197. Case "Ireland" secondpart = "IRL"
  198. Case "Israel" secondpart = "ISR"
  199. Case "Italy" secondpart = "ITA"
  200. Case "Jamaica" secondpart = "JAM"
  201. Case "Japan" secondpart = "JPN"
  202. Case "Jordan" secondpart = "JOR"
  203. Case "Kazakhstan" secondpart = "KAZ"
  204. Case "Kenya" secondpart = "KEN"
  205. Case "Kiribati" secondpart = "KIR"
  206. Case "North Korea" secondpart = "PRK"
  207. Case "South Korea" secondpart = "KOR"
  208. Case "Kuwait" secondpart = "KWT"
  209. Case "Kyrgyzstan" secondpart = "KGZ"
  210. Case "Laos" secondpart = "LAO"
  211. Case "Latvia" secondpart = "LVA"
  212. Case "Lebanon" secondpart = "LBN"
  213. Case "Lesotho" secondpart = "LSO"
  214. Case "Liberia" secondpart = "LBR"
  215. Case "Libya" secondpart = "LBY"
  216. Case "Liechtenstein" secondpart = "LIE"
  217. Case "Lithuania" secondpart = "LTU"
  218. Case "Luxembourg" secondpart = "LUX"
  219. Case "Macao" secondpart = "MAC"
  220. Case "Former Yugoslav Rep. of Macedonia" secondpart = "MKD"
  221. Case "Madagascar" secondpart = "MDG"
  222. Case "Malawi" secondpart = "MWI"
  223. Case "Malaysia" secondpart = "MYS"
  224. Case "Maldives" secondpart = "MDV"
  225. Case "Mali" secondpart = "MLI"
  226. Case "Malta" secondpart = "MLT"
  227. Case "Marshall Islands" secondpart = "MHL"
  228. Case "Martinique" secondpart = "MTQ"
  229. Case "Mauritania" secondpart = "MRT"
  230. Case "Mauritius" secondpart = "MUS"
  231. Case "Mayotte" secondpart = "MYT"
  232. Case "Mexico" secondpart = "MEX"
  233. Case "Federated States Of Micronesia" secondpart = "FSM"
  234. Case "Moldova" secondpart = "MDA"
  235. Case "Monaco" secondpart = "MCO"
  236. Case "Mongolia" secondpart = "MNG"
  237. Case "Montserrat" secondpart = "MSR"
  238. Case "Morocco" secondpart = "MAR"
  239. Case "Mozambique" secondpart = "MOZ"
  240. Case "Burma" secondpart = "MMR"
  241. Case "Namibia" secondpart = "NAM"
  242. Case "Nauru" secondpart = "NRU"
  243. Case "Nepal" secondpart = "NPL"
  244. Case "Netherlands Antilles" secondpart = "ANT"
  245. Case "Netherlands" secondpart = "NLD"
  246. Case "New Caledonia" secondpart = "NCL"
  247. Case "New Zealand" secondpart = "NZL"
  248. Case "Nicaragua" secondpart = "NIC"
  249. Case "Niger" secondpart = "NER"
  250. Case "Nigeria" secondpart = "NGA"
  251. Case "Niue, Republic of" secondpart = "NIU"
  252. Case "Norfolk Island" secondpart = "NFK"
  253. Case "Northern Mariana Islands" secondpart = "MNP"
  254. Case "Norway" secondpart = "NOR"
  255. Case "Oman" secondpart = "OMN"
  256. Case "Pakistan" secondpart = "PAK"
  257. Case "Palau" secondpart = "PLW"
  258. Case "West Bank" secondpart = "PSE"
  259. Case "Panama" secondpart = "PAN"
  260. Case "Papua New Guinea" secondpart = "PNG"
  261. Case "Paraguay" secondpart = "PRY"
  262. Case "Peru" secondpart = "PER"
  263. Case "Philippines" secondpart = "PHL"
  264. Case "Pitcairn Island" secondpart = "PCN"
  265. Case "Poland" secondpart = "POL"
  266. Case "Portugal" secondpart = "PRT"
  267. Case "Puerto Rico" secondpart = "PRI"
  268. Case "Qatar" secondpart = "QAT"
  269. Case "Reunion" secondpart = "REU"
  270. Case "Romania" secondpart = "ROU"
  271. Case "Russia" secondpart = "RUS"
  272. Case "Rwanda" secondpart = "RWA"
  273. Case "St. Helena" secondpart = "SHN"
  274. Case "St. Kitts And Nevis" secondpart = "KNA"
  275. Case "Saint Lucia" secondpart = "LCA"
  276. Case "St. Pierre And Miquelon" secondpart = "SPM"
  277. Case "St. Vincent And the Grenadines" secondpart = "VCT"
  278. Case "Samoa" secondpart = "WSM"
  279. Case "San Marino" secondpart = "SMR"
  280. Case "Sao Tome and Principe" secondpart = "STP"
  281. Case "Saudi Arabia" secondpart = "SAU"
  282. Case "Senegal" secondpart = "SEN"
  283. Case "Serbia And Montenegro" secondpart = "SCG"
  284. Case "Seychelles" secondpart = "SYC"
  285. Case "Sierra Leone" secondpart = "SLE"
  286. Case "Singapore" secondpart = "SGP"
  287. Case "Slovakia" secondpart = "SVK"
  288. Case "Slovenia" secondpart = "SVN"
  289. Case "Solomon Islands" secondpart = "SLB"
  290. Case "Somalia" secondpart = "SOM"
  291. Case "South Africa" secondpart = "ZAF"
  292. Case "South Georgia And the South Sandwich Islands" secondpart = "SGS"
  293. Case "Spain" secondpart = "ESP"
  294. Case "Sri Lanka" secondpart = "LKA"
  295. Case "Sudan" secondpart = "SDN"
  296. Case "Suriname" secondpart = "SUR"
  297. Case "Svalbard & Jan Mayen Islands" secondpart = "SJM"
  298. Case "Swaziland" secondpart = "SWZ"
  299. Case "Sweden" secondpart = "SWE"
  300. Case "Switzerland" secondpart = "CHE"
  301. Case "Syria" secondpart = "SYR"
  302. Case "Taiwan" secondpart = "TWN"
  303. Case "Tajikistan" secondpart = "TJK"
  304. Case "United Republic of Tanzania" secondpart = "TZA"
  305. Case "Thailand" secondpart = "THA"
  306. Case "Timor-Leste, Democratic Republic of" secondpart = "TLS"
  307. Case "Togo" secondpart = "TGO"
  308. Case "Tokelau (Tokelau Islands)" secondpart = "TKL"
  309. Case "Tonga" secondpart = "TON"
  310. Case "Trinidad and Tobago" secondpart = "TTO"
  311. Case "Tunisia" secondpart = "TUN"
  312. Case "Turkey" secondpart = "TUR"
  313. Case "Turkmenistan" secondpart = "TKM"
  314. Case "Turks And Caicos Islands" secondpart = "TCA"
  315. Case "Tuvalu (was part of Gilbert & Ellice Islands)" secondpart = "TUV"
  316. Case "US Virgin Islands" secondpart = "VIR"
  317. Case "Uganda" secondpart = "UGA"
  318. Case "Ukraine" secondpart = "UKR"
  319. Case "United Arab Emirates" secondpart = "ARE"
  320. Case "United Kingdom" secondpart = "GBR"
  321. Case "United States Minor Outlying Islands" secondpart = "UMI"
  322. Case "United States" secondpart = "USA"
  323. Case "Uruguay" secondpart = "URY"
  324. Case "Uzbekistan" secondpart = "UZB"
  325. Case "Vanuatu" secondpart = "VUT"
  326. Case "Venezuela" secondpart = "VEN"
  327. Case "Vietnam" secondpart = "VNM"
  328. Case "Wallis And Futuna Islands" secondpart = "WLF"
  329. Case "Western Sahara" secondpart = "ESH"
  330. Case "Yemen" secondpart = "YEM"
  331. Case "Yugoslavia" secondpart = "YUG"
  332. Case "Zambia" secondpart = "ZMB"
  333. Case "Zimbabwe" secondpart = "ZWE"
  334.  
  335. End Select
  336. Set tempstring = Nothing
  337. Set firstpart = Nothing
  338. Set secondpart = Nothing
  339. End If
  340. ' The data doesn't have degrees symbols in it, so rip out the data, insert the symbols, then store it
  341. If str_UNITS = "&unit=s" Then
  342. weathertemp = xmlstripper("<tmp>", weatherdata) & Chr(176)' & "F"
  343. Else
  344. weathertemp = xmlstripper("<tmp>", weatherdata) & Chr(176)' & "C"
  345. End If
  346. Object.PersistStorage("Fahrenheit") = weathertemp
  347. DesktopX.ScriptObject("Weather Temp").Object.Text = Object.PersistStorage("Fahrenheit")
  348. ' Strip out all the other info
  349. conditions = xmlstripper("<cc>", weatherdata)
  350. conditions = xmlstripper("<t>", conditions)
  351. desktopx.Object("Weather Conditions").text = conditions
  352. conditions = xmlstripper("<icon>", weatherdata)
  353. Object.PersistStorage("Conditions") = conditions
  354. If IsNumeric(conditions) Then
  355. Object.State = conditions
  356. Else
  357. Object.State = "NA"
  358. End If
  359. End If
  360. ' Clear variables for clean code
  361. Set http = nothing
  362. Set weatherdata = Nothing
  363. Set weathertemp = Nothing
  364. Set forecastdatastart = Nothing
  365. Set forecastdataend = Nothing
  366. End If
  367. End Sub
  368.  
  369.  
  370. Function xmlstripper(param, string)
  371. datastart = InStr(string, param) + Len(param)
  372. datalength = Instr(string, "</" & Right(param, Len(param) - 1)) - datastart
  373. xmlstripper = Mid(string, datastart, datalength)
  374. End Function

 

Code on Temperature Object

Code: vbscript
  1. Function Object_OnLButtonUp(x,y,dragged)
  2. If dragged = False Then
  3. If DesktopX.ScriptObject("Weather Icon").tempunit = "m" Then
  4. DesktopX.ScriptObject("Weather Icon").tempunit = "s"
  5. Else
  6. DesktopX.ScriptObject("Weather Icon").tempunit = "m"
  7. End If
  8. DesktopX.ScriptObject("Weather Icon").Object_OnTimer6001
  9. End If
  10. End Function

 

Any help would be great.

bilbo1930
Reply #1 Thursday, February 26, 2009 1:29 PM

pm or  mail to  _martin_

RedBuzzard
Reply #2 Thursday, February 26, 2009 5:59 PM

All my weather widgets have been doing the same thing for 2 days. I have to switch locations back and forth before it stabalizes to what the actual weather is.

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01