View Full Version : Table help
thetford
06-26-2007, 12:30 AM
I'm horrible with tables, so here goes nothing....
I need to popultae a tree object at runtime with the section names [my section] in an ini file. I'm stumped on this one.....
Mike
TJ_Tigger
06-26-2007, 08:03 AM
You can try this and adjust it to your needs. What I am doing is obtaining a list of the value names (which builds a table) and then for each item in the returned table you build the tblNodeData (another table) that will create your node on the tree, then insert that object into the tree. This only builds one level and if you want more than one level you would have to adjust it accordingly.
tbvnames = INIFile.GetValueNames(sFilename, "my section");
if tbvnames then
for i,v in tbvnames do
-- Initialize node data table
tblNodeData = {};
tblNodeData.Text = INIFile.GetValue(sFilename, "my section", v);
tblNodeData.Data = "";
tblNodeData.Expanded = true;
tblNodeData.NodeIndex = i.."";
--tblNodeData.ImageIndex = 1;
--tblNodeData.SelectedImageIndex = 2;
-- Insert the node
Tree.InsertNode("Tree1", i.."",tblNodeData);
end
end
thetford
06-26-2007, 10:48 AM
Thanks tigg ..... what am I doing wrong?
SAVED_CARDS = INIFile.GetSectionNames(_ProgramFilesFolder.."\\CCkeeper\\SAVED\\cards.ini");
tbvnames = INIFile.GetValueNames(sFilename, SAVED_CARDS);
if tbvnames then
for i,v in tbvnames do
-- Initialize node data table
tblNodeData = {};
tblNodeData.Text = INIFile.GetValue(sFilename, SAVED_CARDS, v);
tblNodeData.Data = "";
tblNodeData.Expanded = true;
tblNodeData.NodeIndex = i.."";
--tblNodeData.ImageIndex = 1;
--tblNodeData.SelectedImageIndex = 2;
-- Insert the node
Tree.InsertNode("Tree1", i.."",tblNodeData);
end
end
Told you I suck at tables!
TJ_Tigger
06-26-2007, 11:45 AM
from what it looks like is you are trying to use a table where a string should go. If you want to step through a table you need to use a for loop. Does your ini file have multiple sections and then within each section there are multiple entries? You then need to figure out how you want it to then populate into the tree. Here is another example that might work.
sFilename = "AutoPlay\\Docs\\test.ini"
SAVED_CARDS = INIFile.GetSectionNames(sFilename);
if SAVED_CARDS then --verifies that the table is good
--clear the tree contents
Tree.RemoveNode("Tree1", "0");
for ii,vv in SAVED_CARDS do --steps through each entry
-- Initialize node data table
tblNodeData = {};
tblNodeData.Text = vv;
tblNodeData.Data = vv;
tblNodeData.Expanded = true;
tblNodeData.NodeIndex = ii.."";
--tblNodeData.ImageIndex = 1;
--tblNodeData.SelectedImageIndex = 2;
-- Insert the node
Tree.InsertNode("Tree1", ii.."",tblNodeData);
tbvnames = INIFile.GetValueNames(sFilename, vv);
--vv will be replaced by each entry everytime it steps through
if tbvnames then --verifies that the table is good
--starting here we will add all the entries below the section name
for i,v in tbvnames do
-- Initialize node data table
tblNodeData = {};
tblNodeData.Text = INIFile.GetValue(sFilename, vv, v);
tblNodeData.Data = v;
tblNodeData.Expanded = true;
--this sets the node number to be under the ii value assigned above
tblNodeData.NodeIndex = ii.."."..i;
--tblNodeData.ImageIndex = 1;
--tblNodeData.SelectedImageIndex = 2;
-- Insert the node
Tree.InsertNode("Tree1", ii.."."..i,tblNodeData);
end
end
end
end
thetford
06-26-2007, 04:36 PM
ok, I'll try it. Maybe I need to change my approach? Maybe an sql database? What I'm trying to do is store multiple sections, with several values under it. The sections are populted in the tree, when the node is selected, it should display all the values in the section - via paragraph, input, etc..
thetford
06-26-2007, 04:44 PM
ok, tried it .... good coding tigg! Where can I find good beginner info RE: tables?
It's half the battle, it displays the section, and all the values under it.... hmm, I think I'll give the database a try. I need to be able to pull the values & use them.
I started with the ini because I could put all the data in one file & encrypt it, but I can do that with a database too, right?
hmmmm........
RizlaUK
06-27-2007, 12:09 PM
but I can do that with a database too, right?
yup, i would head over to tiggs site and view his video tuts if i were you, the first set of tuts focus on a small encrypted database app, thats what got me started with the sqlite plugin/encrypted database,
theres even a sample project :yes ( Again, Good Work Tigg ;) )
TJ_Tigger
06-27-2007, 12:23 PM
I started on TiggTV 11 which deals with tables but I have not had a chance to record the show.
thetford
06-28-2007, 07:22 AM
GRRAAAATE! Tigg.... I've always had so many questions about tables, looking forward to episode 11.
Rizula, I've watched episode 1, now I just need to watch it about 12 more times & I might get it! LOL
thanks for all the help guys
thetford
07-07-2007, 04:05 PM
ok - another table question.
I'm using the dialog file browse, which returns the selected file name in a table, right? How do I get the filename/path out of the tabel?
OPEN = Dialog.FileBrowse(true, "Locate File", _ProgramFilesFolder.."\\COMMS\\MESSAGES\\RECIEVED\\", "All Files (*.enc)|*.enc|", "", "enc", false, true);
Desrat
07-07-2007, 08:01 PM
code to browse for file and split the path into parts and output them to paragraph object
--Get File Location And Store In Table "tbOpen"
tbOpen = Dialog.FileBrowse(true, "Locate File", _ProgramFilesFolder.."\\COMMS\\MESSAGES\\RECIEVED\\", "All Files (*.enc)|*.enc|", "", "enc", false, true);
--We Should Only Have One Entry In The Table AS Mutilple Choice Was Disabled
--Take The First Item In tbOpen and Split The Path Into Its Relative Parts And Store In A New Table "tbSplit"
tbSplit = String.SplitPath(tbOpen[1]);
--Here Are All The Variables In The tbSplit Table Stored In Variables
--Drive
sDrive = tbSplit.Drive;
--Folder
sFolder = tbSplit.Folder;
--FileName (no extension)
sFilename = tbSplit.Filename;
--Extension
sExtension = tbSplit.Extension;
--Output The Variables In Mutiple Lines In A Paragraph Object
Paragraph.SetText("Paragraph1", "Drive = " .. sDrive .. "\nFolder = " .. sFolder .. "\nFileName = " .. sFilename .. "\nExtension = " .. sExtension);
thetford
07-07-2007, 09:01 PM
thanks desrat, good code, it works, only I'm trying to open the selected file. The file will be encrypted, i.e. somehting.enc ..... when the user selects it, it will decrypt & then display the contents of the file.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.