PDA

View Full Version : how to save variables in text file???



Jonas DK
09-22-2005, 01:39 PM
Hi can anyone help with an idea for this...

I have a project where the user can save and load a profile.
the profile is to consist of different things:
answered questions, menu settings and time the program have been used.

I can set all this in run time, I can load a file and save a file.

But how do i save all these different things in a file that i can load for next time I use the app.?

I can get the ams app to save the variables one by one in the text file, but I cant work out how to load them again so that they work...

Jonas DK

Corey
09-22-2005, 01:47 PM
hi. The easiest is probably to use a table. As for restoring the data just create an arbitrary data grid, i.e.

item #1 = First Name
item #2 = Last Name
item #3 = Font Color
item #4 = Font Face
item #5 = Start Page

And so forth. You can write the table to a text file using the TextFile.WriteFromTable action, and you can read it back in using the TextFile.ReadToTable action. Restoring values is simply a matter of walking through your data and acting on each entry accordingly. :) :yes

Jonas DK
09-22-2005, 02:12 PM
hi. The easiest is probably to use a table. As for restoring the data just create an arbitrary data grid, i.e.

item #1 = First Name
item #2 = Last Name
item #3 = Font Color
item #4 = Font Face
item #5 = Start Page

And so forth. You can write the table to a text file using the TextFile.WriteFromTable action, and you can read it back in using the TextFile.ReadToTable action. Restoring values is simply a matter of walking through your data and acting on each entry accordingly. :) :yes

Sorry Corey
but Im a bit dumb when it comes to this, I am not a programmer but I have learnt to control a lot of the functionallety in AMS but I'm afraid that it has been a very long time since I last used it, so what you are saying makes as good as no sence to me..

would it bee to much to ask to have it cut out in big shine letters, so even a preschool student could understand. I looked in the help files under tables but that is just as cryptic, the thing is if I can just see the funtionallety i can get it to make sence.. if you understand what I mean...

cheers,
Jonas DK

Corey
09-22-2005, 02:36 PM
Hi. Sorry, I don't have time this week to build it for you but I'll be happy to assist you build your own. It's not that hard once you get in there and start messing around with the code. Give it a shot and let us know whenever you come across any specific obstacles and we'll help you through them. :)

Jonas DK
09-22-2005, 02:42 PM
Hi. Sorry, I don't have time this week to build it for you but I'll be happy to assist you build your own. It's not that hard once you get in there and start messing around with the code. Give it a shot and let us know whenever you come across any specific obstacles and we'll help you through them. :)

Hi Corey
Thanks. I dident mean for you to build it for me. I just wantet some poiters on how to get going with the tables. If i see the bit in action I can figure out the rest.

I tried to set it up from one of the templates I've attached it here, in cluded the xml quiz example (witch is why I ask if you could replace the test with png's..) the text is in danish but I think you can get the idea.

Student create a profile on first start up that will remember what they have been through so they can take tests acordingly.
nice...

But I'll try fidling about with the tables and when I think I got it I'll post the code..

cheers for the help,
Jonas DK

Corey
09-22-2005, 03:10 PM
Hi, for a great introduction to Tables click on "- Tables : An Easy Explanation [8:12] (Click here to view this video now!)" on this page:
http://speedytraining.com/site/cd3.php

Jonas DK
09-23-2005, 12:24 AM
Hi, for a great introduction to Tables click on "- Tables : An Easy Explanation [8:12] (Click here to view this video now!)" on this page:
http://speedytraining.com/site/cd3.php

fantastic... that was exactly the push I needed... thanks Corey

Isent it posible to get the training videoes by email dilivery like ams?
I can only see an option to buy the cd set, but that takes ages to get to me....



Jonas DK

Corey
09-23-2005, 12:36 AM
Hi. No sorry there isn't an ESD option available for the 5.0 CDs. The new training videos will be downloadable, but it's going to be a few months until there are the same number of training videos available for 6.0 as there are for 5.0. I'll be putting them out one module at a time starting pretty soon. FWIW Most of the stuff on the 5.0 CDs is directly applicable to 6.0, especially all the stuff on scripting. :yes

Jonas DK
09-23-2005, 01:00 AM
cool
I now have this in my page on.show

Profile = {Name="John", test2="test3", test3="end"};

And on the projects on.menu I have this


....
elseif e_ID == 103 then
HomeFolder = Shell.GetFolder(SHF_MYDOCUMENTS);
strName = Dialog.Input("Navn", "Skriv dit Navn", "JaneDoe", MB_ICONINFORMATION);
strFolder = Dialog.FolderBrowse("Hvor skal din profil gemmes?", ""..HomeFolder);
TextFile.WriteFromTable(strFolder.."\\"..strName..".ele", Profile(), false);
....

But when I try to run it... when i Save i get an error telling me Im trying to call a Global Profile (table)

What did I mis?

(btw It would be nice if the forum CODE box colour coded like the PHP one does...)
Jonas DK

csd214
09-23-2005, 01:51 AM
I can only see an option to buy the cd set, but that takes ages to get to me....
“ages” might be equal to 8,640 min.

Look at this thread (http://www.indigorose.com/forums/showthread.php?t=7935) posts #22 & 24

Jonas DK
09-23-2005, 06:49 AM
“ages” might be equal to 8,640 min.

Look at this thread (http://www.indigorose.com/forums/showthread.php?t=7935) posts #22 & 24

We shall see... I just ordered the set CD's this morning (local time)

Corey
09-23-2005, 01:38 PM
Thanks for the support, I hope you find lots of value in them. :)

Jonas DK
09-23-2005, 01:53 PM
Thanks for the support, I hope you find lots of value in them. :)

well if the rest is as good as the one you showed me... I wouldent expect less...

Jonas DK
09-23-2005, 04:28 PM
So now I have created the table but I keep getting an error trying to save it to file....


elseif e_ID == 103 then
HomeFolder = Shell.GetFolder(SHF_MYDOCUMENTS);
student.name = Dialog.Input("Navn", "Skriv dit Navn", "JaneDoe", MB_ICONINFORMATION);
student.folder = Dialog.FolderBrowse("Hvor skal din profil gemmes?", ""..HomeFolder);
TextFile.WriteFromTable(student.folder.."\\"..student.name..".ele", student(), false);


something about the table not being defind right... see attached error

is it something about not defining the indevidual strings in the table?

Corey
09-23-2005, 04:51 PM
Hi. Try adding this before your code and see if it works:

student={};

:yes

Jonas DK
09-23-2005, 04:55 PM
Hi. Try adding this before your code and see if it works:

student={};

:yes

Do you mean instead of the student()?
or in general at the very top of the script?

Jonas DK
09-23-2005, 04:58 PM
I have got this at the project startup



student = {emne="", name="Ny Elev", folder=SHF_DESKTOP, date="", olddate=""};
strDate = System.GetDate(DATE_FMT_EUROPE);
strHour = System.GetTime(TIME_FMT_HOUR);
strMin = System.GetTime(TIME_FMT_MIN);
strTime = strHour..":"..strMin
strCoreDate = Dialog.Message("Notice", "Er dato og tid rigtig? Hvis ikke så tryk nej og ret det.\n\n"..strDate.." "..strTime, MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);
if strCoreDate == IDNO then
Application.Exit()
elseif strDate >= student.date then
student.olddate = student.date
student.date = strDate
end


and then this on the project menu


if e_ID == 101 then
Page.Jump("about");
elseif e_ID == 102 then
result = Dialog.Message("Åbne Fil", "Du har valgt at åbne en fil... Du er vel nok dygtig", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
elseif e_ID == 103 then
HomeFolder = Shell.GetFolder(SHF_MYDOCUMENTS);
student.name = Dialog.Input("Navn", "Skriv dit Navn", "JaneDoe", MB_ICONINFORMATION);
student.folder = Dialog.FolderBrowse("Hvor skal din profil gemmes?", ""..HomeFolder);
-- Is this where you want me to put student={} instead of the student()
TextFile.WriteFromTable(student.folder.."\\"..student.name..".ele", student(), false);
elseif e_ID == 104 then
Application.Exit();
elseif e_ID == 201 then
student.emne = "AQuestion";
elseif e_ID == 202 then
student.emne = "BQuestion";
elseif e_ID == 203 then
student.emne = "CQuestion";
elseif e_ID == 204 then
student.emne = "DQuistion";
elseif e_ID == 301 then
Page.Jump("about");
end

Corey
09-23-2005, 05:15 PM
Hi, OK ignore my last post, simply change this line in your menu code:

TextFile.WriteFromTable(student.folder.."\\"..student.name..".ele", student(), false);

To this

TextFile.WriteFromTable(student.folder.."\\"..student.name..".ele", student, false);

:) :yes

Jonas DK
09-23-2005, 06:03 PM
Hi, OK ignore my last post, simply change this line in your menu code:

TextFile.WriteFromTable(student.folder.."\\"..student.name..".ele", student(), false);

To this

TextFile.WriteFromTable(student.folder.."\\"..student.name..".ele", student, false);

:) :yes

heheeee it works

. o O (if I'm lucky I figure this problem out before the postman comes with the training cd's..)

Now the tricky part... How do I load those values back into the table?
When I try i get an on timer error.

here is the script when the laod menu item is activated:


elseif e_ID == 102 then
FileLoad = Dialog.FileBrowse(false, "Locate File", _DesktopFolder, "Elev filer (*.ele)|*.ele| Alle Filer (*.*)|*.*|", "", "ele", false, true);
student = TextFile.ReadToTable(FileLoad);


and attached is the error message I get when opening the selected file

Jonas DK
09-23-2005, 06:07 PM
Just for the fun of it... if it has any interest... (thanks to tiggers codeviewer)

here is the code..


Jonas DK

Corey
09-23-2005, 06:11 PM
Now the tricky part... How do I load those values back into the table?
When I try i get an on timer error.

here is the script when the laod menu item is activated:

As far as I can see, that error is unrelated to this code, it seems to be associated with the code found on Line 5 in your Page1 On Timer event area. :yes

Jonas DK
09-23-2005, 06:21 PM
As far as I can see, that error is unrelated to this code, it seems to be associated with the code found on Line 5 in your Page1 On Timer event area. :yes

Yes that is the same conclusion I came to....

But the wierd thing is that I dont have anything on line 5 in the Timer
and the error only comes when trying to load the file.

Corey
09-23-2005, 06:26 PM
Do you have a function within your timer? Because if you place "a call to a 5 line function with an error on line 4" within your timer, the error will show as being from yout timer on line 5 even though you only have one line there, the function call.

Other than that, I'm not too sure what it could be. The app is seeing some code in there somewhere...

Jonas DK
09-23-2005, 06:33 PM
only thing in the timer is this:



------------------------------[[ SCRIPT: Page: Page1, Event: On Timer Script ]]------------------------------
01 strTimersec = strTimersec + 1;
02 OnlineTimeMin = strTimersec/60;
03 OnlineTime = Math.Round(OnlineTimeMin, 1);
04 Paragraph.SetText("parTimer2", OnlineTime.." Minuter");
05


(code grabed with Tigger Ware)