Gadgets vs Widgets

Coding help needed

Wednesday, December 3, 2008 by PuterDudeJim | Discussion: 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

milksama
Reply #1 Thursday, December 4, 2008 2:32 PM

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

PuterDudeJim
Reply #2 Thursday, December 4, 2008 10:04 PM

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! 

PuterDudeJim
Reply #3 Friday, December 5, 2008 5:13 PM

bump

 

ZubaZ
Reply #4 Friday, December 5, 2008 6:32 PM

Why the bump?

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

PuterDudeJim
Reply #5 Saturday, December 6, 2008 4:48 PM

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.

PuterDudeJim
Reply #6 Saturday, December 6, 2008 5:04 PM

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?

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