Gadgets vs Widgets

Coding help needed

  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

14,495 views 6 replies
Reply #1 Top

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&amp;ValueName)
  9.     If ReadValue &lt;&gt; "" Then Exit Function
  10.     ReadValue = ""
  11. End Function
  12. Sub WriteValue(ValueName,Data)
  13.     oShell.RegWrite REG_LOCATION&amp;ValueName, Data, "REG_SZ"
  14. End Sub

Check out the dxpack here:
Memory DXPack sample


Mike

Reply #2 Top

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!  :grin:

Reply #4 Top

Why the bump?

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

Reply #5 Top

Why the bump?

Did you try the code or you need help with it?
End of quote

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. v_v

Reply #6 Top

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?