PDA

View Full Version : I need help with an easy way to display files to download



SteevieNiteHeat
02-27-2010, 03:45 PM
Hi all, a new project in the making, but has been halted after trying a few ways, to no avail.

Basically I need to display around 70 files to download, each download will be displayed with a title, and then the hidden data will be the download URL.

An example I have tried is a listbox with the program title as the item text, and the URL in the Item Data part, but I have no way of loading this on show (either from registry, text file or ini file)

An example:

Item Text Item Data

Program 1 http://www.myprog1.exe
Program 2 http://www.myprog2.exe
etc...

What I have managed to do is use this code:
ListBox.DeleteItem("ListBox1", -1);
tbl_folders = TextFile.ReadToTable(_DesktopFolder.."\\progs list.txt");
for count = 1, Table.Count(tbl_folders) do
result = ListBox.AddItem("ListBox1", tbl_folders[count], "");
end
but in the listbox it just shows the url text, but I would like a way to store both the Item Text AND the Item Data so when it loads the page, it is all filled in, I am pulling my hair out here as I have a few apps & have made that are downloaders and listbox apps, but I cannot incorporate them into 1.

I have tried writing to the registry, an ini file AND a text file, but none do what I want, is there any way to do what I need?

I have also tried using a tree, but I have never been able to figure them out so have avoided them at all cost!

Centauri Soldier
02-27-2010, 04:10 PM
Please don't double post.

SteevieNiteHeat
02-27-2010, 05:13 PM
I am sorry, I compiled the thread, and after clicking on submit, it timed out, took over 180 seconds to try and complete, then I clicked submit again and it said I could only do 1 opst per 5 mins, so I went back to the topics but couldnt see it so I created another 1, sorry again :(

Scriptonite
02-28-2010, 11:45 AM
Ive been getting time out errors as well, usually followed by the server 400 error. I though it was my machine but maybe it's not. Anyway, give this a shot:



ListBox.DeleteItem("ListBox1", -1);
tbl_folders = TextFile.ReadToTable(_DesktopFolder.."\\progs list.txt");
for count = 1, Table.Count(tbl_folders) do
result = String.SplitPath(tbl_folders[count]);
ListBox.AddItem("ListBox1",result.Filename , tbl_folders[count]);
end

SteevieNiteHeat
02-28-2010, 02:22 PM
Ive been getting time out errors as well, usually followed by the server 400 error. I though it was my machine but maybe it's not. Anyway, give this a shot:



ListBox.DeleteItem("ListBox1", -1);
tbl_folders = TextFile.ReadToTable(_DesktopFolder.."\\progs list.txt");
for count = 1, Table.Count(tbl_folders) do
result = String.SplitPath(tbl_folders[count]);
ListBox.AddItem("ListBox1",result.Filename , tbl_folders[count]);
end



Thanks Scriptonite, this method is quite good, but the problem still exists that I need a way to show in the text (of listbox, combo box or whatever else) is say for example:

WinZip, but with the data(download url) hidden.

I did think of a way of manually typing the data in and then at runtime it would populate the listbox, but the problem with that is I would have to update the whole program each time I wanted to add something new...


On second thoughts, this will do for now thank you so much Scriptonite, I will go with this :-)

SteevieNiteHeat
02-28-2010, 03:01 PM
Right, after going with Scriptonite's suggestion, I now need 1 more bit of help...

I want to have 2 buttons, 1 to download all the listed programs, the other button to just download the selected proram.

Now if it was a comboBox, I can do the get selected, and it will work, but with Listbox it will not, so I guess what I am asking is, how when I select an item in a listBox, can I use it to get the selected text?

Scriptonite
02-28-2010, 08:17 PM
This function should work. This is not tested.



AllApps = ListBox.GetCount("ListBox1");

for count =1, AllApps do

URL = ListBox.GetItemData("ListBox1", count);
appName = String.SplitPath(URL)
HTTP.Download(URL, "AutoPlay\\Docs\\"..appName.Filename..appName.Extension, MODE_BINARY, 20, 80, nil, nil, nil);


end

SteevieNiteHeat
03-01-2010, 04:51 AM
This function should work. This is not tested.



AllApps = ListBox.GetCount("ListBox1");

for count =1, AllApps do

URL = ListBox.GetItemData("ListBox1", count);
appName = String.SplitPath(URL)
HTTP.Download(URL, "AutoPlay\\Docs\\"..appName.Filename..appName.Extension, MODE_BINARY, 20, 80, nil, nil, nil);


end



Thanks for your efforts mate, but that code dont work :(

I do have a app I made a while ago called Portable Downloader, I have tried to mix and match the code, but I just cant figure it out!

I will attatch the portable downloader app incase its usefull for anybody, there is a single downloader bit, the download url then gets stored into a listbox, there is a page for a multi-downloader, and also a batch downloader, might be of use to somebody!

RizlaUK
03-01-2010, 05:29 AM
so I guess what I am asking is, how when I select an item in a listBox, can I use it to get the selected text?

try this:

-- single selection
local tSel = ListBox.GetSelected("ListBox1");
if tSel then
local sName = ListBox.GetItemText("ListBox1",tSel{1]);
local sURL = ListBox.GetItemData("ListBox1",tSel{1]);

-- dowmnload your file


else
-- no selection

end


or this:


-- multi selection
local tSel = ListBox.GetSelected("ListBox1");
if tSel then

-- loop all selected
for nIndex, nItem, tSel do
local sName = ListBox.GetItemText("ListBox1",nItem);
local sURL = ListBox.GetItemData("ListBox1",nItem);

-- dowmnload your file

end
else
-- no selection

end

SteevieNiteHeat
03-01-2010, 09:54 AM
Sorry guys, none of your suggestions are working for me so I'm gonna attatch the new project I'm working on so you have a better idea, and this is for Windows Updates.

RizlaUK
03-01-2010, 11:48 AM
yeah, i wish i could just copy n paste code into a project and have it magical work too!

edit your code!, change the variable names etc

Scriptonite
03-01-2010, 01:03 PM
Well, I sifted through your code. You have to read through the code and change things like variable names. You can't copy an paste different peoples code and expect it to work. I've been picking at this a couple minutes at a through the morning and did not have the extra time to go back through and comment the code. I made the necessary changes to make it work, please take the time to go through it and see what changes were made. I think you could have easily found the issues if you had read through the code, there were variables that were not defined anywhere before they were called. Best of luck.

SteevieNiteHeat
03-01-2010, 06:12 PM
RizlaUK: I DID mess around and change the code till i got soo fed up with trying to figure things out, I tried to copy the code from my previous downloader into the new 1 and change things, but nothing!


@Scriptonite: I have just got in and will check that out and comment in due course:) thanks loads :yes

SteevieNiteHeat
03-01-2010, 06:42 PM
Well, I sifted through your code. You have to read through the code and change things like variable names. You can't copy an paste different peoples code and expect it to work. I've been picking at this a couple minutes at a through the morning and did not have the extra time to go back through and comment the code. I made the necessary changes to make it work, please take the time to go through it and see what changes were made. I think you could have easily found the issues if you had read through the code, there were variables that were not defined anywhere before they were called. Best of luck.

Thanks so much, this is exactly what I needed, have a pint on me :):lol