I have made a container control named myChart.
myChart displays user’s activity in each hour as a percent of total activity over 24 hours. (displays which hours the user was most active)
myChart has 24 integer properties: hour1, hour2, … , hour24 for storing values for each hour.
The values are saved as a textfile in a subfolder inside Application Support.
The values are read at app’s open event,
And it is saved at app’s close event.
The reading works fine (confirmed by feeding a textfile I made with TextMate with random values for 24 hours to the app. the chart was loaded from the random values, and displayed correctly)
But when the app is closed, the file’s values are all saved as zero. all I get is 24 zeros.
Please help me.
Here’s the codes
Please tell me what’s wrong.
#################
code for app open event
[code] dim historyFile as folderItem
dim buffer as TextInputStream
// create a file and a folder
historyFile = SpecialFolder.ApplicationData.Child(“inc.mycompany.myapp”).Child(“myapp_history”)
// If available, reads the preferences file
if historyFile.Exists then
buffer = TextInputStream.Open(historyFile)
wMain.lBreakTime.Text = buffer.ReadLine
wMain.myChart.hour1 = Val(buffer.ReadLine)
wMain.myChart.hour2 = Val(buffer.ReadLine)
wMain.myChart.hour3 = Val(buffer.ReadLine)
wMain.myChart.hour4 = Val(buffer.ReadLine)
wMain.myChart.hour5 = Val(buffer.ReadLine)
wMain.myChart.hour6 = Val(buffer.ReadLine)
wMain.myChart.hour7 = Val(buffer.ReadLine)
wMain.myChart.hour8 = Val(buffer.ReadLine)
wMain.myChart.hour9 = Val(buffer.ReadLine)
wMain.myChart.hour10 = Val(buffer.ReadLine)
wMain.myChart.hour11 = Val(buffer.ReadLine)
wMain.myChart.hour12 = Val(buffer.ReadLine)
wMain.myChart.hour13 = Val(buffer.ReadLine)
wMain.myChart.hour14 = Val(buffer.ReadLine)
wMain.myChart.hour15 = Val(buffer.ReadLine)
wMain.myChart.hour16 = Val(buffer.ReadLine)
wMain.myChart.hour17 = Val(buffer.ReadLine)
wMain.myChart.hour18 = Val(buffer.ReadLine)
wMain.myChart.hour19 = Val(buffer.ReadLine)
wMain.myChart.hour20 = Val(buffer.ReadLine)
wMain.myChart.hour21 = Val(buffer.ReadLine)
wMain.myChart.hour22 = Val(buffer.ReadLine)
wMain.myChart.hour23 = Val(buffer.ReadLine)
wMain.myChart.hour24 = Val(buffer.ReadLine)
buffer.Close
end if[/code]
###############
code for app close event
[code] dim historyFile as folderItem
dim buffer as TextOutputStream
// create a file and a folder
historyFile = SpecialFolder.ApplicationData.Child(“inc.mycompany.myapp”).Child(“myapp_history”)
// Creates, or rewrites the preferences file
buffer = TextOutputStream.Create(historyFile)
buffer.WriteLine wMain.lBreakTime.Text
buffer.WriteLine “”
buffer.WriteLine “saved”
//buffer.WriteLine CStr(wMain.myChart.hour1)
//buffer.WriteLine CStr(wMain.myChart.hour2)
//buffer.WriteLine CStr(wMain.myChart.hour3)
//buffer.WriteLine CStr(wMain.myChart.hour4)
//buffer.WriteLine CStr(wMain.myChart.hour5)
//buffer.WriteLine CStr(wMain.myChart.hour6)
//buffer.WriteLine CStr(wMain.myChart.hour7)
//buffer.WriteLine CStr(wMain.myChart.hour8)
//buffer.WriteLine CStr(wMain.myChart.hour9)
//buffer.WriteLine CStr(wMain.myChart.hour10)
//buffer.WriteLine CStr(wMain.myChart.hour11)
//buffer.WriteLine CStr(wMain.myChart.hour12)
//buffer.WriteLine CStr(wMain.myChart.hour13)
//buffer.WriteLine CStr(wMain.myChart.hour14)
//buffer.WriteLine CStr(wMain.myChart.hour15)
//buffer.WriteLine CStr(wMain.myChart.hour16)
//buffer.WriteLine CStr(wMain.myChart.hour17)
//buffer.WriteLine CStr(wMain.myChart.hour18)
//buffer.WriteLine CStr(wMain.myChart.hour19)
//buffer.WriteLine CStr(wMain.myChart.hour20)
//buffer.WriteLine CStr(wMain.myChart.hour21)
//buffer.WriteLine CStr(wMain.myChart.hour22)
//buffer.WriteLine CStr(wMain.myChart.hour23)
//buffer.WriteLine CStr(wMain.myChart.hour24)
buffer.Close[/code]