PDA

View Full Version : getting items into a list box


Mango
01-31-2007, 04:46 AM
Hi guys

I wonder if any of you can help with this problem.
I wish to import a list of directories from an external drive (F:) into a list box, allowing a user then to choose the one they require. As these are specific directories they all have an underscore in them.
So far I have been able to get the directories to show as a list in a dialogue.message, but am stuck getting them into a listbox.
My script so far is:-

-- Set the drive to search
drive = "F:\\";
-- Set the folder to search for
folder = "*_*";
-- Search the specified drive for folders inlcuding an "_"

search_results = Folder.Find(drive, folder, false, FindCallBack);

--Check to see if an error occurred during the search. If it did, display the error message.error = Application.GetLastError();

if error ~= 0 then
Dialog.Message("Error",_tblErrorMessages[error]);
else
-- If no directories were found, inform the user if (search_results == nil) then
Dialog.Message("Attention", " No Compatible directories found.", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
Application.Exit(0);
else
-- If folders were found, display a dialog containing a list of their locations.

message = "Folders have been found as detailed below \r\nPlease select the one you require\r\n";
for index, path in search_results do
message = String.Concat(message, path.."\r\n");
MessDelete = Dialog.Message("Attention", message, MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
end

What I now need to do is replace the red message with a listbox

Any ideas guys

Thanks

longedge
01-31-2007, 09:55 AM
Assuming you've got a list box on your page then -

drive = "C:\\";
folder = "*";

search_results = Folder.Find(drive, folder, false, Nil);

if (search_results) then
for index, path in search_results do
split_path = String.SplitPath(search_results[index]);
folder_name=split_path.Filename
result = ListBox.AddItem("ListBox1", folder_name, search_results[index]);
end
end

should work OK.

Mango
01-31-2007, 11:28 AM
Thanks Longedge

It works a treat - I've just upgraded from version 4 after having bought a licenced 5 over a year ago, but decided at last to take the plunge and try and get my head round some of these scripts in 5. My current project is quite involved, and I needed to use features that V4 couldn't do.

Hopefully with perseverance and some help from you veterans (please don't take that as age related) I'll master it !

Many thanks again:) :)