View Full Version : help please for save file
sided
10-19-2008, 12:32 PM
Hello all, I am again ams and not very good at English and I have a question
I have an application with 2 pages entry and read with 1 menu in entry I have 4 input named "number" "name" "place" "quantity" and menu save idem in read.
Help please for added code
Thanx advance
on show page entry
number = Input.GetText("Input1");
name = Input.GetText("Input2");
place = Input.GetText("Input3");
quantity = Input.GetText("Input4");
on menu page entry
if e_ID==1 then -- Item Save on menu
--[[ script for
Save File]]--
result = Dialog.Message("Notice", "You have next Input.", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);
if result == IDNO then
Application.ExitScript();
else
Input.SetText("Input1", "");
Input.SetText("Input2", "");
Input.SetText("Input3", "");
Input.SetText("Input4", "");
end
end
on show page read
--[[ script for Read File ]]--
Number = Input.GetText("Input1"); -- Number introduced to Page Entry
Input.SetText("Input2", Name); -- Read the Name in File Saved to Page Entry
Input.SetText("Input3", Place); -- Read the Place in File Saved to Page Entry
Input.SetText("Input4", Quantity); -- Read the Quantity in File Saved to Page Entry
Centauri Soldier
10-19-2008, 12:56 PM
You could do this with many different file types but I'm using an ini file for simplicity.
--I would use this table instead of separate variables
--I'm not entirely sure why this is in the On Show event but I'll trust that you know what you're doing
tblUserData = {};
tblUserData.Number = Input.GetText("Input1");
tblUserData.Name = Input.GetText("Input2");
tblUserData.Place = Input.GetText("Input3");
tblUserData.Quantity = Input.GetText("Input4");
if tblUserData then
for index, item in tblUserData do
INIFile.SetValue("AutoPlay\\Docs\\UserData.ini", "General", index, item);
end
end
--Read Section (You could also read back to a table for convenience)
Input.SetText("Input1", INIFile.GetValue("AutoPlay\\Docs\\UserData.ini", "General", "Number"));
Input.SetText("Input2", INIFile.GetValue("AutoPlay\\Docs\\UserData.ini", "General", "Name"));
Input.SetText("Input3", INIFile.GetValue("AutoPlay\\Docs\\UserData.ini", "General", "Place"));
Input.SetText("Input4", INIFile.GetValue("AutoPlay\\Docs\\UserData.ini", "General", "Quantity"));
Something like that maybe? I'm not certain what your after here.
sided
10-19-2008, 02:49 PM
thanx for the answer, it works, but when I click on Save, dialogbox asked whether the entry is complete, if not, click the new entry. inifile but took the last entry, but must add the first inifile therefore contains 2 number, 2 Name, 2 place, 2 quantity
and on read, if the number entered on the keyboard is there then displays name, place, quantity
thanx advance for reply
Centauri Soldier
10-19-2008, 04:35 PM
Sorry, I can't understand what you're asking for.
sided
10-19-2008, 05:30 PM
Start the application in introduction to keyboard on input the number is 100, the name is ronald, the place is food, the quantity is 5 and then click menu to save and DialogBox asked whether entry finished?, whether exit application if not new entry number is 200, name is franck, place is metro, quantity is 10, click menu save etc etc if finished I have saved 1 or 2 or 3 entry etc etc.
on read
if I introduced on Input Numberto keyboard 100, it checks if the file exists and displays on Name ronald, on place food, on quantity 5
if I introduced on Input Numberto keyboard 200, it checks if the file exists and displays on name franck, on place metro, on quantity 10
etc etc
sorry if I'm wrong but explained it is difficult for me in English :o
presidente
10-19-2008, 06:18 PM
I think you want to make a database and you have problems with the code for the inifile
--Read Section (You could also read back to a table for convenience)
Input.SetText("Input1", INIFile.GetValue("AutoPlay\\Docs\\UserData.ini", "General", "Number"));
Input.SetText("Input2", INIFile.GetValue("AutoPlay\\Docs\\UserData.ini", "General", "Name"));
Input.SetText("Input3", INIFile.GetValue("AutoPlay\\Docs\\UserData.ini", "General", "Place"));
Input.SetText("Input4", INIFile.GetValue("AutoPlay\\Docs\\UserData.ini", "General", "Quantity"));
because this only stores ONE set of data, but you want to store more than one set.
If the numbers (100, 200) are somethink like customer- numbers, you can put them in a variable to declare the section of the ini-file.
if the Number is in the variable number, the Name the variable name, the Place the variable place and the Quantity the variable quantity, you put it like this:
number = Input.GetText("Input1");
name = Input.GetText("Input2");
place = Input.GetText("Input3");
quantity = Input.GetText("Input4");
INIFile.SetValue("AutoPlay\\Docs\\UserData.ini", number, "Name", name);
INIFile.SetValue("AutoPlay\\Docs\\UserData.ini", number, "Place", place);
INIFile.SetValue("AutoPlay\\Docs\\UserData.ini", number, "Quantity", quantity);
But i think itīs easier to work with the sqlite plugin.
There are a lot of examples that you can use.
Ini-files are more for storing parameters.
If you work with sets of data, they are really not the best choice.
sided
10-20-2008, 12:16 AM
thanx for reply, but wat is plugin sqlite :huh
I'm open for more suggestion, if is easy good for nexbies thanx
Centauri Soldier
10-20-2008, 10:14 AM
If that's what you're after you may also benefit from the DataBase Action Plugin...search the forums and you'll find tons of plugins.
You may consider using an xml file for your program as well.
I understand how it is to be new to AMS as I was new to AMS a while ago too. I spent hours upon hours reading the AMS help file...I highly recommend it. You're going to find many of your answers in that file.
sided
10-20-2008, 11:48 AM
ok thank you I look on plugin, but I think I come back to you thank you :yes
sided
10-21-2008, 02:40 PM
I find an example sqlite (customer v5) create by stickck.
I'm modified this code by adapted in my application, but when you start the application I get an error " On preload, line 14:First argument to SQLite.QueryToTable() must be a database handle.
Help please :huh
code by stickck
function FillCustomer_List()
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- Clear contents of all items on the page
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
ListBox.DeleteItem("Name_List", -1);
Input.SetText("Total input", "");
Input.SetText("Search", "");
Input.SetText("Customer_info", "");
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- Query table DVD_List and store all entries in table tWebsites
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
tInfo_List = SQLite.QueryToTable(db, "SELECT * FROM Info_List");
nLastError = Application.GetLastError();
if nLastError ~= SQLite.OK then
Dialog.Message("Error", SQLite.GetLastErrorString());
end
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- if there were no errors, continue, otherwise do nothing
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
if nLastError == SQLite.OK then
--traverse the table
for nRow = 1,tInfo_List.Rows do
--get the title of the current record
sName = tInfo_List.Data[nRow]["Name"];
--add the item to the listbox with text = title and data = row number (in table)
--************************************************** ******************use the RecordID INSTEAD of the Row Number
ListBox.AddItem("Name_List", tInfo_List.Data[nRow]["Name"], tInfo_List.Data[nRow]["RecordID"]);
end
end
end
FillCustomer_List();
---------------------------------------------------------------
My change is the character in red
code modified for me
Date = System.GetDate(DATE_FMT_EUROPE);
function FillCustomer_List()
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- Clear contents of all items on the page
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
ListBox.DeleteItem("Name_List", -1);
Input.SetText("Total input", "");
Input.SetText("Search", "");
--Input.SetText("Customer_info", "");
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- Query table DVD_List and store all entries in table tWebsites
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
tInfo_List = SQLite.QueryToTable(db, "SELECT * FROM Info_List");
nLastError = Application.GetLastError();
if nLastError ~= SQLite.OK then
Dialog.Message("Error", SQLite.GetLastErrorString());
end
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- if there were no errors, continue, otherwise do nothing
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
if nLastError == SQLite.OK then
--traverse the table
for nRow = 1,tInfo_List.Rows do
--get the title of the current record
sNumero = tInfo_List.Data[nRow]["Numero"];
--add the item to the listbox with text = title and data = row number (in table)
--************************************************** ******************use the RecordID INSTEAD of the Row Number
ListBox.AddItem("Name_List", tInfo_List.Data[nRow]["Numero"], tInfo_List.Data[nRow]["RecordID"]);
end
end
end
FillCustomer_List();
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.