Using System.Gadget.Settings

Hi,

In my gadget I save a value in my VBScript, how do I re-load this saved value I have:

System.Gadget.Settings.Write "Record", dtmSystemUptimeSecs

s = System.Gadget.Settings.Read("Record")

But this doesn't seem to work

If my uptime is big interger should I use the writeString & readString methods



Answer this question

Using System.Gadget.Settings

  • pipope

    Always use readString for strings, otherwise it may return a number instead of a string which may cause type conflicts.

    eg. Using read will return the following incorrect types:
    "123" will return the number 123, not the string "123"
    "true" will return the boolean value true, not the string "true"


    Advantanges of Javascript over VB. Well, you have access to all the HTML trigged values like "event.screenX" for a start. Not to mention having access to the whole HTML structure through getElementByID etc.

    In short, Javascript is more suited to web development than VB. You'll still need VB here and there, such as presenting dialogues to users, because MS think they're bad for the user experience (shame they don't apply the same rule to their own software! )


  • Reuben

    Some parts of the 'System' APIs that the sidebar exposes will not work correctly from VBScript. These failures, in some cases, are quite difficult to debug. If you absolutely must use VBScript, then I recommend using javascript for most of your code, VBScript for the minimal parts necessary, and don't use the 'System' APIs from VBScript code.
  • Mark The Archer Evans

    I see the value in settings.ini

    System.Gadget.Settings.Write "Record", dtmSystemUptimeSecs

    time = System.Gadget.Settings.Read(Record)

    Record.innerText = "Record: " & time

    If I put this then the "Record: " text dissapears, if I comment out the time = line & the time variable then I see the text.

    Do I have to load the settings somehow I don't have a settings.html, I just though you could save values

    How big is large for write string


  • Zakamon

    Try ReadString:

    System.Gadget.Settings.Write "Record", "100"
    sTime = System.Gadget.Settings.ReadString("Record")
    Record.innerText = "Record: " & sTime

    If it still doesn't work, you've probably come across the disappearing System.* bug (bug#11 on the known bugs list).

    Also try rewriting it as Javascript with an error trap:

    try{
    System.Gadget.Settings.Write("Record", dtmSystemUptimeSecs);
    sTime = System.Gadget.Settings.ReadString("Record");
    Record.innerText = "Record: " + sTime;
    } catch(err) {Record.innerText = err}


  • heavenlycharmus

    Post the whole code, so I can have a look. This is painful!

  • Gregory English

    That doesn't seem to work I must be missing something
  • JIM.H.

    It looks okay to me, does the value get written to the settings.ini file

    If it's large, you may well need to use readString/writeString

  • Rob Hounsell

    OK, the readstring thing didn't work.

    with the JS I get [object Error]


  • NoEgo

    method names in the gadget API are lower case ('read' and 'write'). If possible, I recommend using javascript instead of vbscript in your gadget code.
  • hrubesh

    What the advantage of Java over VB

    When should I use readString over read

    Seems fixed now as well


  • Tigers21

    It's really strange what's going on thanks for your help!!

    Sub Times

    On Error Resume Next

    Set objLocator = CreateObject("WbemScripting.SWbemLocator")

    Set objWMIService = objLocator.ConnectServer(MachineName, "root\cimv2")

    Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

    For Each objOS in colOperatingSystems

    dtmBootup = objOS.LastBootUpTime

    dtmLastBootupTime = WMIDateStringToDate(dtmBootup)

    dtmSystemUptimeSecs = DateDiff("s", dtmLastBootUpTime, Now)

    Uptime.innerText = "Uptime: " & SecondsToDateString(dtmSystemUptimeSecs)

    Next

    System.Gadget.Settings.Write "Record", dtmSystemUptimeSecs

    RecordTime = System.Gadget.Settings.Read("Record")

    Record.innerText = "Record: " & RecordTime

    setTimeout "Times()", 30000

    End Sub 


  • Philipp Lamp

    That serves me right for copying the original code! Thanks for pointing that one out Bruce.

    So you're code needs to be changed to:

    System.Gadget.Settings.write "Record", dtmSystemUptimeSecs
    RecordTime = System.Gadget.Settings.read("Record")


  • Tito Jermaine

    You've got a typo and a type conflict:

    System.Gadget.Settings.Write "Record", dtmSystemUptimeSecs
    time = System.Gadget.Settings.Read("Record")
    Record.innerText = "Record: " & CStr(time)

  • Using System.Gadget.Settings