Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding files to a list box 2

Status
Not open for further replies.

ictoo

Programmer
Sep 3, 2009
33
GB
Hello everyone.

What I’m trying to do now with my project is to associate files to a task, there will be many tasks with many files, I’ll have my task list on page 2 of a pageframe and the files will be added on page 3.

I’ve got a getfile() working and executing the file with help from the FAQ from here(that are all very helpful) but I’m not 100% sure now how to add the file extension from getfile() to a listbox then the file extensions added to that get clicked and open the file. I’ve got a database with descno that will contain the taskno to only show the files for that task and a filename where the extension will go. Now if anyone could help me/point me in the right direction with getting the files saved to this table and then showing in a listbox, Id be very appreciated.

And sorry if I haven’t given enough information, if you need more to understand my problem please ask.
 
This needs clarifying. A listbox is used to display a list (as its name suggests). But GETFILE() only returns a single file. What exactly do you want to appear in the list box? The file returned from GETFILE()? Or a list of some kind?

There are several ways to populate a listbox. If the information is in a cursor or table, you set the RowSourceType to 6, and the RowSource to the alias. If it's in an array, set RowSourceType to 5 and RowSource to the name of the array.

A more general method is to set RowSourceType to 0, then call the listbox's AddItem method, passing the text that you want to appear in the listbox. That's probably the approach you should be taking in this case, but it's difficult to give any furher help without a clearer idea of what you are trying to achieve.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I want to add multiple files to a listbox or something that will list a number of files that can then just be click on and executed, I do want the file that is returned from GETFILE yes, but I also want more that on file to be listed in there. And at some point when I get this bit working I want to look in to not showing the full path but just the file name.

I’ll be trying your suggestions now mike thanks for the quick reply.
 
Add an item to the listbox: Listbox.Additem() or Listbox.Addlistitem() - both in conjunction with no controlsource/rowsource and rowsourcetype 0.

To get just the filename of a getfile() return value:
? Justfname(getfile())

To get just the file extension:
? Justext(getfile())

To get just the path:
? Justpath(getfile())

Bye, Olaf.
 
Ictoo,

In that case, all you need to do is to loop through your list of files, calling the listbox's AddItem() for each one.

To pass just the filename, without the path, you can use JUSTFNAME(), but you would presumably still need to store the full path somewhere, assuming you want to eventually open the file.

By the way, the listbox has a special RowSourceType for displaying files: set RowSourceType to 7, and set RowSource to a wildcard file spec. However, the user interface is not very pretty (it's a hangover from DOS), but you might want to have a quick try.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Checkout the following FAQ that will describe loading listboxes. If you just need an extenstion you can use the JUSTEXT() function. There is also JUSTFNAME(), JUSTSTEM(), and more...


load listbox FAQ
Programmatically Loading & Referencing Listbox Items faq184-4322


If need launch an app based on the file type look at the applaunch method I posted a few years back:

Thread184-944857 or you can search for the word applaunch


Jim Osieczonek
Delta Business Group, LLC
 
Ok I’ve gone with using getfile then inserting the path to the file to a table, this is then displayed on a listbox now I’m not sure how to call the file to get it to run using the path of the file, I’ve got a ShellExecute that works when i give it a path, but not on the listbox when i try to click on a path.

This is confusing me a bit I’ve never done something like this and I’m trying to look something up that is anything like what I’m doing any help with his would be appreciated.
 
Ictoo,

You don't want to open the file when the user clicks on the filename in the listbox. If you did, you'd be opening files all over the place as the user scrolls the list. Better to do it when they double click.

So, you need to write code in the DblClick of the listbox. The code will pick up the Value property of the listbox. That's where you'll find the filename. Pass that to ShellExecute, and you should be fine.

That assumes you are storing the full filename and path. If you only have the short filename (without the path), ShellExecute won't know where to look for theh file. That's why I suggested you would need to store the full names in any case. Another option would be store the files in a directory on your VFP search path, and then use the FULLPATH() function to produce the full filename.

Hope that makes sense.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Hey,

I’ve got it working somewhat I’m going to be tweaking it today now to get it just right i just want to thank you all for your help, much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top