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!

How To Display JPEG Images (Photos) On a VFP 9 Form 1

Status
Not open for further replies.

proscoop

Programmer
Feb 6, 2002
16
JM
Hi Everyone,

I have been having a really difficult time making the transition from FoxPro 2.6 DOS to Visual FoxPro. It seems so difficult for me to understand classes, foundations, events, methods, procedures, containers etc. However, I am committed this year to learn to program in Visual FoxPro 9 as my legacy Inventory, Point-Of-Sale, Accounting bundled software that I wrote in FoxPro 2.6 DOS some seventeen years ago (even though still working and being used extensively) is encountering a lot of difficulties and having to use many work arounds.

One particular part of the software I wrote was a real-time ordering system for salespersons who travel with a laptop to use. A screen would come up with the item number, description, price etc. and most importantly a PICTURE (PHOTO). You could click on Prev | Next | Find | Top | Bottom to scroll through the entire table displaying one item and its associated photo at a time. The bottom quarter of the screen would have a browse grid where the items could be added to the customers order while viewing the picture and relevant data. The database table has a CHARACTER field that dennotes the location of the JPEG file and if there was a photo present, an external Image Viewer was called to display the picture.

I exported the same table to Visual FoxPro 9 and tried using the Form Wizard to create a simple form (at first) that would mimic what I coded in DOS. Somehow, I just can't get the PHOTO to be displayed at all. I tried using a IMAGE control on the form but have no clue how to call the photo as I tried putting the FIELD NAME from the table as the PICTUREVAL data. That didn't work. Tried replacing it with a OLE Bound Object and putting the FIELD NAME as the ControlSource but that did NOT work either.

I can imagine how funny this question must be to many of you but as I said before I am having great difficulties learning VFP 9. Would you be kind enough when responding to tell me specifically where to put FIELD NAME or variable or whatever is needed to get this to work. Do I need to write some code in the INIT or GotFocus Events?? As I said before, the actual PHOTOS are NOT embedded in the table. The table ONLY contains a field that references the location of the JPEG file. I just need to figure out how to let the VFP 9 form know how to use this information from the field to display the photo. Any help would be greatly appreciated. I guess if I can get that part to work, then the next step would be to place the grid on the form to take the actual order.

P.S. I tried searching the previous posts and FAQ sections already and just can't seem to find how to do it.

Greatly appreciate whatever help or advice you have to offer.

Sincerely,

ProScoop
 
Hi,
I use the image control picture property
In the "next" button i put
THISFORM.image1.picture =pic where pic is associated jpg filename
When using a grid i put similar code in the interactivechange event
wjwjr

This old world keeps spinning round - It's a wonder tall trees ain't layin' down
 
Thanks much for the speedy reply and advice White605,

I tried what you had suggested above but I am NOT sure if I am doing it correctly. I MODIFIED the FORM, Selected the ButtonSet1: cmdNext then went on the Methods Tab, choose Click and pasted the code in the Code Window for the Click event (THISFORM.image1.picture =inventory.photo where inventory is the Table and Photo is the field that stores the location of the JPEG file on my harddrive). When I save the Form and run it, the very first item does NOT come up with a PHOTO/Picture of the Inventory Item. However, when I click the Next button at the bottom of the window, the following item does bring up a PHOTO/Picture but when you press the NEXT button again, NOTHING happens. It does NOT skip to the next record. If you press the Bottom Record Button it moves to the last record but does NOT bring up that PHOTO/Picture. Am I doing this thing correctly. I thought I had to go on the Image1 Property then Data Tab and put something in the PictureVal section. When I tried pasting your command in that section, nothing happens. The Form runs but every inventory item brings up a blank Image Section (crossed out due to missing photo - does NOT display the JPEG photo). Can you guide me SPECIFICALLY what to do?

Thanks,

ProScoop
 
ProScoop,

Mr White has basically given you the right answer. I think the problem lies in the default behaviour of the wizard buttons.

I suggest that, for a quick fix, you set the Picture property in the form's Refresh event. This isn't ideal, because in general it's good practice to keep the Refresh as lean as possible, but it won't do any harm in this case.

To summarise:

- Place an Image control on the form. Change its Name property to, say, imgPhoto.

- In the form's Refresh, retrieve the name of the image file from your table (it will be in the current record). The file should either be in the VFP default directory or the search path, or the file name should be qualified with the path.

- Still in the Refresh, execute THISFORM.imgPhoto.Picture = xxxxx where xxxx is the name of the image file.

I would add that I think the real problem here is that you're using the form wizard. It's tempting to use the supplied wizards as a way of avoiding having to start from scratch, but the wizards in general, and the form wizard in particular, are not really all that usable. They are OK if you are happy to do things exactly the way the wizards do, but they are very difficult to modify or enhance.

In the longer term, you might do better by ignoring the wizards and trying to build a basic data-entry form from scratch. Ideally, you will make it into a class, then subclass it to build all your other similar forms.

VFP can be quite daunting at first, but don't be discouraged. I'm sure you'll master it before long.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thank you ever so much Mr. Mike Lewis and Mr. White. I feel so accomplished and ecstatic now. The form is moving a bit slowly when changing from item to item but I am most grateful. This is exactly what I wanted it to do. This thing has been beating me for the longest time. As I mentioned previously, I am NOT at all comfortable with creating, coding and designing in Visual FoxPro. Things were a lot simpler for me in the old DOS days. Mr. Lewis, your tweaking suggestion worked perfectly now in conjuction with Mr. White's previous post. Now that the top part of the form is working, I know the next challenge will be to created a linked GRID where the actual quantities ordered can be entered and a running tally/total of the order produced on screen.

Much appreciation once again.

Sincerely,

Chris (ProScoop, Kingston, Jamaica)
 
I strongly recommend that you go to and order the book "The Fundamentals." It's a getting started with VFP book and is very much aimed at those who are coming from FP2.x.

Tamar
 
Dear Ms. Tamar Granor,

Thank you for your advice. I really would like to be able to properly design, code and create complete functional project (forms, reports, programs, menus, classes etc.) with Visual FoxPro 9. I searched the site you recommended and found a book written by Whil Hetzen entitled, "Fundamentals: Building Visual Studio Applications on a Visual FoxPro 6.0 Foundation" ISBN: 0-96550-935-4. Just want to make sure (absolutely) that this is the book to which you referred. Your reply would be greatly appreciated.

Thanks,

Chris (ProScoop)
 
As Dan said, yes, that's the book to start with. Even though it was written for VFP 6, it still applies in VFP 9. You may want to look around at that site and see what other books you'll find helpful, too.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top