 |
|
 |
Saving variabel, How can I save a variabel? |
|
|
| rubeneduardo |
Apr 28 2006, 09:11 AM
|
Posts: 10
Joined: 8-March 06
Member No.: 13,923

|
Hi guys,
I am developing a Widget and the problem I have is that I want to save a variabel after closing the Widget. I've tried to do this with Textwriter without success, is it possible to save this in the XML-tag <preference>?
Thankz
|
|
|
|
|
| rubeneduardo |
Apr 28 2006, 10:12 AM
|
Posts: 10
Joined: 8-March 06
Member No.: 13,923

|
This is my code, i want to save a variabel called timeStamp. This is a variabel that is declared and used in the JavaScript file. But the problem is that it doesn't work when I close the Widget and restart.
<preference name="timeStamp"> <hidden>true</hidden> <type>text</type> </preference>
|
|
|
|
|
| Indiana |
Apr 28 2006, 10:20 AM
|

Posts: 680
Joined: 16-November 05
From: Munich, Germany
Member No.: 11,213

|
of cause you must set the preference and read it manually!
Have a N.I.C.E. day ... Indiana My Widget's: Sys Monitor 2, My Drive 2, CPU Monitor 2, Net Monitor 2, Disc Monitor 2, HDD Monitor, Sys Watch, BMW Clock, German Call by CallWorking on: SysMonitor 2 (latest version!), Sys Watch 2, LAN-Monitor, "A Game"
|
|
|
|
|
| solarfish |
Apr 28 2006, 10:55 AM
|

Posts: 69
Joined: 29-March 06
From: United Kingdom
Member No.: 14,293

|
QUOTE(rubeneduardo @ Apr 28 2006, 10:12 AM) This is my code, i want to save a variabel called timeStamp. This is a variabel that is declared and used in the JavaScript file. But the problem is that it doesn't work when I close the Widget and restart. <preference name="timeStamp"> <hidden>true</hidden> <type>text</type> </preference> in your onload code have something like CODE var timeStamp = preferences.timeStamp.value; then when you want to write the variable back to the preference before closing use CODE preferences.timeStamp.value = timeStamp;
|
|
|
|
|
| g6auc |
Apr 28 2006, 10:59 AM
|

Posts: 4,265
Joined: 1-March 04
From: West Yorkshire, UK
Member No.: 2,322

|
CODE <action trigger="onLoad"> var timeStamp = preferences.timeStamp.value; // pick up value at previous close ..... timeStamp = new Date().getTime(); // set a new timeStamp ..... </action>
<action trigger="onUnload"> preferences.timeStamp.value = timeStamp; // save timeStamp for next open </action>
<preference name="timeStamp"> <title>Time Stamp</title> <type>text</type> <hidden>true</hidden> <description>Hidden Preference to hold timeStamp variable.</description> </preference>
|
|
|
|
|
| rubeneduardo |
Apr 28 2006, 10:59 AM
|
Posts: 10
Joined: 8-March 06
Member No.: 13,923

|
Thank you guys, I already solved is by using preferences.timestamp.value in the JavaScript. Now I don't have to use a variable, instead I use the preferences to drop what I want to save!
|
|
|
|
|
| rubeneduardo |
Apr 28 2006, 11:18 AM
|
Posts: 10
Joined: 8-March 06
Member No.: 13,923

|
I still have one problem guys, (by the way I used g6auc code).
in de variabel timeStamp I put the following: timeStamp[0]: Thu, 28 Mar 2006
But preferences.timeStamp saves this as: preferences.timeStamp.value[0]: T preferences.timeStamp.value[1]: h preferences.timeStamp.value[2]: u preferences.timeStamp.value[3]: , preferences.timeStamp.value[4]: preferences.timeStamp.value[5]: 2 preferences.timeStamp.value[6]: 8 preferences.timeStamp.value[7]: preferences.timeStamp.value[8]: M preferences.timeStamp.value[9]: a preferences.timeStamp.value[10]: r preferences.timeStamp.value[11]: preferences.timeStamp.value[12]: 2 preferences.timeStamp.value[13]: 0 preferences.timeStamp.value[14]: 0 preferences.timeStamp.value[15]: 6 preferences.timeStamp.value[16]:
How can I make sure preferences.timeStamp has the same value as the variabel timeStamp?
Thanks
|
|
|
|
|
| rubeneduardo |
Apr 28 2006, 11:54 AM
|
Posts: 10
Joined: 8-March 06
Member No.: 13,923

|
XML: <action trigger="onLoad"> include("script.js"); CalcCPU(); var timeStamp = preferences.timeStamp.value; </action>
<preference name="timeStamp"> <title>Time Stamp</title> <type>text</type> <hidden>true</hidden> <description>Hidden Preference to hold timeStamp variable.</description> </preference>
Scripts.js timeStamp = getNodeContent(contentArr['item'][i], "pubDate"); preferences.timeStamp.value = timeStamp;
_____________________________________________________________________
Basicly it puts the pubDate from an item from a RSS-feed in the variabel timeStamp. timeStamp[0]: Thu, 28 Mar 2006
But when preferences.timeStamp.value = timeStamp is executed the value of preferences.timeStamp is:
preferences.timeStamp.value[0]: T preferences.timeStamp.value[1]: h preferences.timeStamp.value[2]: u preferences.timeStamp.value[3]: , preferences.timeStamp.value[4]: preferences.timeStamp.value[5]: 2 preferences.timeStamp.value[6]: 8 preferences.timeStamp.value[7]: preferences.timeStamp.value[8]: M preferences.timeStamp.value[9]: a preferences.timeStamp.value[10]: r preferences.timeStamp.value[11]: preferences.timeStamp.value[12]: 2 preferences.timeStamp.value[13]: 0 preferences.timeStamp.value[14]: 0 preferences.timeStamp.value[15]: 6 preferences.timeStamp.value[16]:
(instead of preferences.timeStamp.value[0]: Thu, 28 Mar 2006)
|
|
|
|
|
| g6auc |
Apr 28 2006, 01:19 PM
|

Posts: 4,265
Joined: 1-March 04
From: West Yorkshire, UK
Member No.: 2,322

|
QUOTE(rubeneduardo @ Apr 28 2006, 12:54 PM) CODE timeStamp = getNodeContent(contentArr['item'][i], "pubDate"); preferences.timeStamp.value = timeStamp; Basicly it puts the pubDate from an item from a RSS-feed in the variabel timeStamp. timeStamp[0]: Thu, 28 Mar 2006 But when preferences.timeStamp.value = timeStamp is executed the value of preferences.timeStamp is: preferences.timeStamp.value[0]: T preferences.timeStamp.value[1]: h ... (instead of preferences.timeStamp.value[0]: Thu, 28 Mar 2006) preferences.timeStamp.value should be a string, not an array, so you need the equivalent of CODE preferences.timeStamp.value = "Thu, 28 Mar 2006)"; Check the type of getNodeContent() - does that deliver a string? You could print(typeof getNodeContent(...)).
|
|
|
|
|
| rubeneduardo |
Apr 28 2006, 01:52 PM
|
Posts: 10
Joined: 8-March 06
Member No.: 13,923

|
getNodeContent() delivers an object. Is it possible to use typecasting to convert the object to a string?
|
|
|
|
|
| g6auc |
Apr 28 2006, 02:08 PM
|

Posts: 4,265
Joined: 1-March 04
From: West Yorkshire, UK
Member No.: 2,322

|
QUOTE(rubeneduardo @ Apr 28 2006, 02:52 PM) getNodeContent() delivers an object. Is it possible to use typecasting to convert the object to a string? No doubt, but it would help to know its definition! It could be simply an array, as that would report as object. Try: CODE timeStamp = getNodeContent(contentArr['item'][i], "pubDate").join(""); or CODE timeStamp = getNodeContent(contentArr['item'][i], "pubDate").toString();
|
|
|
|
|
| rubeneduardo |
Apr 28 2006, 02:18 PM
|
Posts: 10
Joined: 8-March 06
Member No.: 13,923

|
Very interesting, when i try to use the code you suggested i get the same problem in the variable timeStamp..
Object "timeStamp": timeStamp[0]: T timeStamp[1]: h timeStamp[2]: u timeStamp[3]: , timeStamp[4]: timeStamp[5]: 2 timeStamp[6]: 8 timeStamp[7]: timeStamp[8]: M timeStamp[9]: a timeStamp[10]: r timeStamp[11]: timeStamp[12]: 2 timeStamp[13]: 0 timeStamp[14]: 0 timeStamp[15]: 6 timeStamp[16]:
|
|
|
|
|
| rubeneduardo |
Apr 28 2006, 02:22 PM
|
Posts: 10
Joined: 8-March 06
Member No.: 13,923

|
variable timeStamp is an object but preferences.timeStamp.value is a string. I think that's the problem..
|
|
|
|
|
| g6auc |
Apr 28 2006, 02:44 PM
|

Posts: 4,265
Joined: 1-March 04
From: West Yorkshire, UK
Member No.: 2,322

|
QUOTE(rubeneduardo @ Apr 28 2006, 03:18 PM) Very interesting, when i try to use the code you suggested i get the same problem in the variable timeStamp.. Object "timeStamp": timeStamp[0]: T timeStamp[1]: h timeStamp[2]: u timeStamp[3]: , timeStamp[4]: timeStamp[5]: 2 timeStamp[6]: 8 timeStamp[7]: timeStamp[8]: M timeStamp[9]: a timeStamp[10]: r timeStamp[11]: timeStamp[12]: 2 timeStamp[13]: 0 timeStamp[14]: 0 timeStamp[15]: 6 timeStamp[16]: That's exactly what you would get if timeStamp were a string. You can index the individual characters of a string.
|
|
|
|
|
| rubeneduardo |
Apr 28 2006, 02:53 PM
|
Posts: 10
Joined: 8-March 06
Member No.: 13,923

|
Thanks, so that's the solution not the problem! Thanks for all your help!
|
|
|
|
|
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
|
 |