PDA

View Full Version : List box questions


Roboblue
08-08-2005, 04:27 PM
Is there a way to limit the number of rows the list box will except? Like 6 from a user input object?
When pulling the info (text/data fields) out of the list box, is there a way to get it all at once instead of having to read each line number at a time (2 times actually as the text and data fields come out seperately).

Corey
08-08-2005, 04:38 PM
Hi. You can easily use actions to limit the contents of a listbox. Getting your data into a table and then using a "for" loop (check help file) to move through the data is easier than evaluating it manually one piece at a time. :yes

Roboblue
08-08-2005, 06:12 PM
easy enough to limit list box entries, just needed to think.
getting the info out of the box and into a table little harder.
can some one give me a quick example?
Here is apz. I have everything else finished, but need to put list box entries (3) into a table.

Roboblue
08-08-2005, 06:25 PM
here is apz without needing popup plugin

Derek
08-08-2005, 07:03 PM
Hi

You can use ListBox.GetCount to control the number of items. Something like this will work.
Of course you may want to add an IF to check that the input object does actually contain text.

num_items = ListBox.GetCount("ListBox1");
if num_items < 6 then
sInput_Text = Input.GetText("Input1");
ListBox.AddItem("ListBox1", sInput_Text);
else
Dialog.Message("Notice", "You can not have more than six items.");
end

Derek
08-08-2005, 07:24 PM
oops! - i forgot the table bit.

I threw this together, so there may be a shorter way, but this will work

-- get the number of items in listbox
num_items = ListBox.GetCount("ListBox1");

counting = 1 -- set the first index number
min = 1; -- The number to start at
max = num_items; -- The number to stop at .. in this case, whatever the listbox holds (6?)
for count = min, max do
-- get the item text .. use 'counting' as number 1
sItem_Text = ListBox.GetItemText("ListBox1", counting);
-- insert the text into table at position 'counting' .. which = 1
Table.Insert(my_table, counting, sItem_Text);
-- increase 'counting' by 1 so it becomes 2, 3, 4 etc as we loop thru this
counting = counting+1
end

Roboblue
08-08-2005, 07:36 PM
Thanx Derek
I am going to work on this now.

Derek
08-08-2005, 07:55 PM
You're welcome :yes

Roboblue
08-08-2005, 08:06 PM
Derek
I am getting a "argument 1 must be table type" for the insert table line 14

-- get the number of items in listbox
num_items = ListBox.GetCount("Link_lst");

counting = 1 -- set the first index number
min = 1; -- The number to start at
max = num_items; -- The number to stop at .. in this case, whatever the listbox holds
for count = min, max do
-- get the item text .. use 'counting' as number 1
sItem_Text = ListBox.GetItemText("Link_lst", counting);
---check what's in sItem_Text
result = Dialog.Message("Notice", sItem_Text, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

-- insert the text into table at position 'counting' .. which = 1
Table.Insert(my_table, counting, sItem_Text);
-- increase 'counting' by 1 so it becomes 2, 3, 4 etc as we loop thru this
counting = counting+1
end
TextFile.WriteFromTable("AutoPlay\\Docs\\links.txt", my_table, true);
File.Open("AutoPlay\\Docs\\links.txt", "", SW_SHOWNORMAL);

Also, this is just getting the list box item text. also want the data. The purpose is to populate a table to feed the popup menu plugin, user entered url links. In this code, I will end up with 2 tables that will have to be dumped into variables for the popup menu.

Roboblue
08-08-2005, 08:09 PM
here is apz with the above code to show object reference.
check the table list button actions

Derek
08-08-2005, 08:25 PM
Hi Roboblue

Line 14 refers to table "my_table" which needs to exist in order to insert items into it [computers can be real fussy at times!].
You'll need to create "my_table" before you run the script to insert the items.

As for the item.data - you should be able to use similar script to what you already have for item.text. Just change it to suit your needs :)

Worm
08-08-2005, 08:25 PM
add this line in before your for statement Robo


--create the table
my_table = {}
for count = min, max do

Worm
08-08-2005, 09:54 PM
Here's a hack on Derek's code...
Replace the code in your Table List button with this


-- get the number of items in listbox
num_items = ListBox.GetCount("Link_lst");

min = 1; -- The number to start at
max = num_items; -- The number to stop at .. in this case, whatever the listbox holds (6?)
my_table={}
for count = min, max do
-- get the item text .. use 'counting' as number 1
sItem_Text = ListBox.GetItemText("Link_lst", count);
sItem_Data = ListBox.GetItemData("Link_lst", count);
---check what's in sItem_Text
result = Dialog.Message("Notice", "List Text: "..sItem_Text.."\r\nList Data: "..sItem_Data, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

-- insert the text into table at position 'counting' .. which = 1
my_table[count]= {Name=sItem_Text, Link=sItem_Data};
end

tblPopUp = {}
for count = 1, Table.Count(my_table) do
tblPopUp[count] = {text=my_table[count].Name, type=0,checked=false,enabled=true}
end

sSelected = PopupMenu.Show(tblPopUp, 0, 0, PopupMenu.HALIGN_LEFT,PopupMenu.VALIGN_TOP);
for count = 1, Table.Count(my_table) do
if my_table[count].Name == sSelected then
File.OpenURL(my_table[count].Link, SW_SHOWNORMAL)
count = Table.Count(my_table)
end
end

Roboblue
08-08-2005, 10:27 PM
I forgot about having to create the table first.
I was just working on using a table to populate the popup menu and wasn't even close with that. I am so rusty, and considering that I have never been greatly versed or experienced as a programmer anyway, I was struggling.

Roboblue
08-10-2005, 08:00 PM
I decided since I have the sqlite plugin that I would use a db instead of a table so I could use the popup menu on any page and project.
Can some one PLEASE tell me why the delete button will not work. I thought I knew a little about sqlite.

Worm
08-10-2005, 09:44 PM
This seems to make'er go...


SQLite.Query(dbD, "DELETE FROM User WHERE Title = \""..sTitled.."\"");

Intrigued
08-10-2005, 09:58 PM
And (the actual function is Worm's idea with the guts coded a tad differently by me) here is a function that does such (Worm gets credit, as he was the one that shared it with us a ways back! :yes)

function Enclose(s)
s = "'"..s.."'"
return s
end

tSelected = ListBox.GetSelected("Link_lst");
if tSelected then
sTitled = ListBox.GetItemText("Link_lst", tSelected[1]);
--Delete the entry from the database
SQLite.Query(dbD, "DELETE FROM User WHERE Title = "..Enclose(sTitle));
nLastError = Application.GetLastError();
if nLastError ~= SQLite.OK then
Dialog.Message("Error: " .. nLastError, SQLite.GetLastErrorString());
end
end
FillLink_lst()

Roboblue
08-10-2005, 10:02 PM
Thanx guys.

Intrigued
08-10-2005, 10:06 PM
*Points at Worm*

That fella really took a lot of time when I was new to AMS to helpl me out via Email. I know he is really busy now.. but back then he had a bit more time and took it to help jump start me down the SQLite database road.

*gang signs to Worm*

Nutt'in but love!

:D

Roboblue
08-11-2005, 02:27 PM
*Points at Worm*

That fella really took a lot of time when I was new to AMS to helpl me out via Email. I know he is really busy now.. but back then he had a bit more time and took it to help jump start me down the SQLite database road.

*gang signs to Worm*

Nutt'in but love!

:D

WORM has helped a lot of us and I greatly appreciate his help, as well as all the other guys that take their time to help the un-blessed.
I always feel like I need to pay back some how, but KUDOS are all I can offer.

Roboblue
08-12-2005, 06:26 PM
I am trying to get the popup menu (Links button) to get the data from a table filled from the database. I am trying to make a function to be used globally in a project.
I cant get the popup to work.
I think, again, it's the sqlite code that I am not getting correct.
Could someone please tell me why the Links button isn't working?

Worm
08-12-2005, 10:56 PM
Give this a whirl


function FillPopup()
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- Query table User and store all entries in table tUser
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
tUser = SQLite.QueryToTable(dbD,"SELECT * FROM User");
nLastError = Application.GetLastError();
if nLastError ~= SQLite.OK then
Dialog.Message("Error", SQLite.GetLastErrorString());
end

--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- if there were no errors, continue, otherwise do nothing
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
tblPopUp = {}
if nLastError == SQLite.OK then
--traverse the table
for nRow = 1,tUser.Rows do
--get the title of the current record
tblPopUp[nRow] = {text=tUser.Data[nRow].Title, type=0,checked=false,enabled=true}
end
end
end



FillPopup();
sSelected = PopupMenu.Show(tblPopUp, 0, 0, PopupMenu.HALIGN_LEFT,PopupMenu.VALIGN_TOP);
for count = 1, Table.Count(tUser) do
if tUser.Data[count].Title == sSelected then
File.OpenURL(tUser.Data[count].Address, SW_SHOWNORMAL)
count = Table.Count(tUser)
end
end

Roboblue
08-13-2005, 01:00 AM
Give this a whirl


function FillPopup()
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- Query table User and store all entries in table tUser
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
tUser = SQLite.QueryToTable(dbD,"SELECT * FROM User");
nLastError = Application.GetLastError();
if nLastError ~= SQLite.OK then
Dialog.Message("Error", SQLite.GetLastErrorString());
end

--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- if there were no errors, continue, otherwise do nothing
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
tblPopUp = {}
if nLastError == SQLite.OK then
--traverse the table
for nRow = 1,tUser.Rows do
--get the title of the current record
tblPopUp[nRow] = {text=tUser.Data[nRow].Title, type=0,checked=false,enabled=true}
end
end
end



FillPopup();
sSelected = PopupMenu.Show(tblPopUp, 0, 0, PopupMenu.HALIGN_LEFT,PopupMenu.VALIGN_TOP);
for count = 1, Table.Count(tUser) do
if tUser.Data[count].Title == sSelected then
File.OpenURL(tUser.Data[count].Address, SW_SHOWNORMAL)
count = Table.Count(tUser)
end
end



I am getting an error that says "line 29 attempt to index field ? (a nil value)
after I clear the popup. the links work, but it leaves the error.
this is the line
if tUser.Data[count].Title == sSelected then
I can't see why it would be nil. It's already indexed.

Roboblue
08-13-2005, 01:15 AM
I think this is part of the above.
When I add a 4th link, I don't get the error and all 4 work from the popup
When I add a 5th, no error, but the 5th one will not work from the popup.
Same with a 6th (my link limit in the project).
Doesn't sqlite always use a 0 record for the index? So if there is 3 records (rows) when a count of records is made, it returns 4.
Could this be the problem.

Worm
08-13-2005, 07:43 AM
Oops, sorry missed a problem in that last For loop. This one works here for me...


function FillPopup()
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- Query table User and store all entries in table tUser
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
tUser = SQLite.QueryToTable(dbD,"SELECT * FROM User");
nLastError = Application.GetLastError();
if nLastError ~= SQLite.OK then
Dialog.Message("Error", SQLite.GetLastErrorString());
end

--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- if there were no errors, continue, otherwise do nothing
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
tblPopUp = {}
if nLastError == SQLite.OK then
--traverse the table
for nRow = 1,tUser.Rows do
--get the title of the current record
tblPopUp[nRow] = {text=tUser.Data[nRow].Title, type=0,checked=false,enabled=true}
end
end
end



FillPopup();
sSelected = PopupMenu.Show(tblPopUp, 0, 0, PopupMenu.HALIGN_LEFT,PopupMenu.VALIGN_TOP);
for count = 1, tUser.Rows do
if tUser.Data[count].Title == sSelected then
File.OpenURL(tUser.Data[count].Address, SW_SHOWNORMAL)
count = Table.Count(tUser)
end
end

Roboblue
08-13-2005, 01:29 PM
WHOAA
No more error, but when I click on a link in the popup, it goes crazy. An endless amount of web pages open and I had to reset the box to get it to quit :eek:
It's in a infinite loop.

Roboblue
08-13-2005, 03:31 PM
WHOAA
No more error, but when I click on a link in the popup, it goes crazy. An endless amount of web pages open and I had to reset the box to get it to quit :eek:
It's in a infinite loop.

it's only when clicking on the last link in thepopup.

Worm
08-14-2005, 12:57 PM
:)


function FillPopup()
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- Query table User and store all entries in table tUser
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
tUser = SQLite.QueryToTable(dbD,"SELECT * FROM User");
nLastError = Application.GetLastError();
if nLastError ~= SQLite.OK then
Dialog.Message("Error", SQLite.GetLastErrorString());
end

--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
-- if there were no errors, continue, otherwise do nothing
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
tblPopUp = {}
if nLastError == SQLite.OK then
--traverse the table
for nRow = 1,tUser.Rows do
--get the title of the current record
tblPopUp[nRow] = {text=tUser.Data[nRow].Title, type=0,checked=false,enabled=true}
end
end
end



FillPopup();
sSelected = PopupMenu.Show(tblPopUp, 0, 0, PopupMenu.HALIGN_LEFT,PopupMenu.VALIGN_TOP);
for count = 1, tUser.Rows do
if tUser.Data[count].Title == sSelected then
File.OpenURL(tUser.Data[count].Address, SW_SHOWNORMAL)
count = tUser.Rows
end
end

Roboblue
08-14-2005, 03:24 PM
That did it
Since it was a community effort to build this, I am going to put it in the example section for everyone.
Thanx guys

Corey
08-14-2005, 03:33 PM
it was a community effort to build this

:yes :yes :yes :yes :yes :yes :yes :yes :yes :yes

Roboblue
08-14-2005, 09:35 PM
here is the right one
the above one didn't check for internet connection.

Intrigued
08-14-2005, 11:35 PM
I like it!

Note: I have DLS (aka. High-Speed Internet service) and noticed that a dialog (Dialog.Message) popped up stating no Internet connection was detected.

And my connection is working.

Just a heads up.

:yes

Roboblue
08-15-2005, 01:13 AM
I like it!

Note: I have DLS (aka. High-Speed Internet service) and noticed that a dialog (Dialog.Message) popped up stating no Internet connection was detected.

And my connection is working.

Just a heads up.

:yes

Did you get the last apz I uploaded? I thought I had fixed that.
try this one.