Talisman skins and wallpapers
Coding help needed
Published on December 3, 2008 By PuterDudeJim In OS Customization

  Hey there Guys and Gals!  I recently uploaded a set of  gadgets that were malfunctioning. The weather gadget would keep reverting to my location, instead of staying on the user's location. I believe it is because the gadget being that, a gadget rather than a widget, sees my location as default. I hope I am being clear. They work correctly as widgets, somehow, my location seems to become FINAL, for lack of a better term, when I export it as a gadget. When the user puts in his/her info, all is well. It reverts to Greeneville,Tn. upon restarting of the gadget, or rebooting the computer. Long story short, I am looking for anyone who knows script who can help me with this. I would like to send out some gadgets so that they could be used by people who don't have DesktopX.  Any help would be greatly appreciated.  The script I used is by Martin. My widgets can be found at http://chubbyhusband.wincustomize.com   Please send any information that might help. I will post the script below.

Sub Object_OnStateChange(state)
 If state = "Command executed" Then

  x = DesktopX.ScriptObject("weather_image").Object.PersistStorage("zipcode")
   If IsNumeric(x) = False Then x = Object.Text
   x = InputBox("Please enter the zip code or location that you would like to display the weather for:" & vbNewLine & "e.g. 48152 or York,England", "Select location ...", x)
    If IsNumeric(x) = False Then
     Set http = CreateObject("Microsoft.XmlHttp")
     Randomize
     str_RANDOM_URL="&rnd=" & rnd()
     http.Open "GET", "http://xoap.weather.com/search/search?where=" & x, False
     http.send ""
     ' Store data in a string
     weatherdata = http.responseText
      If InStr(weatherdata, "loc id") > 0 Then
       weatherdata = Right(weatherdata, Len(weatherdata) - InStr(weatherdata, "loc id") - 7)
       weatherdata = Left(weatherdata, InStr(weatherdata, "type") - 3)
       x = weatherdata
      End If
    End If
    If x <> "" Then
     DesktopX.ScriptObject("weather_image").Object.PersistStorage("zipcode") = x
     DesktopX.ScriptObject("weather_image").Object.PersistStorage("zipcode2") = "20659"
     DesktopX.ScriptObject("zip2").Object.text = DesktopX.ScriptObject("weather_image").Object.PersistStorage("zipcode2")
     DesktopX.ScriptObject("weather_image").Object_OnTimer6001
     
    End If
  If Msgbox("Would you like to add a second Zone?", vbYesNo,"Second Zone Input") = vbYes Then
    y = DesktopX.ScriptObject("weather_image").Object.PersistStorage("zipcode2")
   If IsNumeric(x) = False Then y = Object.Text
   y = InputBox("Please enter a Second zip code or location that you would like to display the weather for:" & vbNewLine & "e.g. 48152 or York,England", "Select location ...", y)
    If IsNumeric(y) = False Then
     Set http = CreateObject("Microsoft.XmlHttp")
     Randomize
     str_RANDOM_URL="&rnd=" & rnd()
     http.Open "GET", "http://xoap.weather.com/search/search?where=" & y, False
     http.send ""
     ' Store data in a string
     weatherdata = http.responseText
      If InStr(weatherdata, "loc id") > 0 Then
       weatherdata = Right(weatherdata, Len(weatherdata) - InStr(weatherdata, "loc id") - 7)
       weatherdata = Left(weatherdata, InStr(weatherdata, "type") - 3)
       y = weatherdata
      End If
    End If
    If y <> "" Then
     DesktopX.ScriptObject("weather_image").Object.PersistStorage("zipcode2") = y
     DesktopX.ScriptObject("zip2").Object.text = DesktopX.ScriptObject("weather_image").Object.PersistStorage("zipcode2")
     DesktopX.ScriptObject("weather_image").Object_OnTimer6001
     
    End If
    
  End If   
 End If
 

  End Sub


Comments
on Dec 04, 2008

I think there is some kind of problem related to storing information and having it persist through closing/reopening a gadget. My personal method for saving data when writing gadgets is to simply save to/read from the registry.

For example:

Code: vbscript
  1. Const REG_LOCATION = "HKCU\Software\milksama\TestGadget\"
  2. Dim oShell
  3. Sub Object_OnScriptEnter
  4.     Set oShell = CreateObject("WScript.shell")
  5. End Sub
  6. Function ReadValue(ValueName)
  7.     On Error Resume Next
  8.     ReadValue = oShell.RegRead(REG_LOCATION&ValueName)
  9.     If ReadValue <> "" Then Exit Function
  10.     ReadValue = ""
  11. End Function
  12. Sub WriteValue(ValueName,Data)
  13.     oShell.RegWrite REG_LOCATION&ValueName, Data, "REG_SZ"
  14. End Sub

Check out the dxpack here:
Memory DXPack sample


Mike

on Dec 04, 2008

Thanx Mike, I will study this and see if I can get enough sense from it to suit my needs. I am no coder, usually have to borrow code from others. Thanx! 

on Dec 05, 2008

bump

 

on Dec 05, 2008

Why the bump?

Did you try the code or you need help with it?

on Dec 06, 2008

Why the bump?

Did you try the code or you need help with it?

I guess I was looking for more help. This code would need to be altered and I don't know how to alter it. I wish I was good at this coding stuff, but I am not there yet.  I guess I don't know how to use it.

on Dec 06, 2008

Can I just change the info on line 1 to my info and have it work? Would anyone I shared it with have to do the same?