View Full Version : ListBox to File Help needed.
Jerryab
05-22-2006, 10:52 AM
Can anyone help with getting a list box to a file.
I am having problems getting a list box to a file BY PROMPTING the user for a location and file name to save it by.
I am trying to get a listbox to a file but I need to prompt the user for a path and file name to save the listbox to.
Can someone please help ?
Thanks.
Jerry...
Hi Jerry,
Hope this helps...
str_YourLB = "yourListBoxName";
str_YourTextFile = "\\AutoPlay\\Docs\\yourFile.txt"
-- Count the number of entries in the listbox
num_LBCount = ListBox.GetCount(str_YourLB);
-- Make sure that the listbox had something in it
if num_LBCount ~= -1 then
-- Create a table of all of the listbox items by steping through the listbox
-- and adding the items to a new table
tbl_LBItems = {};
for num_Counter = 1, num_LBCount, 1 do
tbl_LBItems[num_Counter] = ListBox.GetItemText(str_YourLB, num_Counter);
end
-- Write the contents of the table to a textfile overwriting any previous text
TextFile.WriteFromTable(str_YourTextFile, tbl_LBItems, false);
end
Jerryab
05-22-2006, 10:15 PM
I know how to get the listbox to a file what I an having a problem with is:
I have to prompt the user for a path and file name to save the listbox to.
I can't have it go where I want it to go, it has to be chosen by the user.
For some reason I can't get the list box to a chosen path and file name. I tried this line of code but not having much luck with it.
PathFile = Dialog.FileBrowse(false, "Save As", "C:\\", "All Files (*.*)|*.*|", "", "txt", false, false);
I tried this to get the path and file name from the user and have it used with a routine like you posted but it does not work. The routine I use does work if the path and file name is inbeded so I know that part worked.
Any suggestions ?
Jerry
yosik
05-22-2006, 10:46 PM
your PathFile is a table, so you have to use it accordingly:
PathFile = Dialog.FileBrowse(false, "Save As", "C:\\", "All Files (*.*)|*.*|", "", "txt", false, false);
str_YourTextFile = PathFile[1];
The rest is as TJS posted.
Good luck
Yossi
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.