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 Mike Lewis 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 photos from Visual Foxpro 6? 2

Status
Not open for further replies.

Dronner

Technical User
Apr 19, 2024
15
US
Hello guys,
To give you an example of what I need, I have this database:
car_code...car_name...car_photo
...1.......Valkyrie...c:\vfp6\app\Valkyrie.jpg
...2.......Spitfire...c:\vfp6\app\Spitfire.jpg
...3.......Cyclone....c:\vfp6\app\Cyclone.jpg

The idea, basically, is that if I enter code 1, the app shows me the photo that is stored in the route that appears in the car_photo field corresponding to the "Valkyrie" and if I enter code 3, then it shows me the photo of the "Cyclone" etc.

In Visual Foxpro 6, what are the code lines necessary to go to the route specified in the "car_photo" field and show me the corresponding photo?
Thanks in advance.
 
You need an image control on a form and set its picture property to the filename.

So, if you only use code by now, the first thing to do is create a form and put an image control on it.
The code can vary a but, buzt essentially:
Code:
thisform.imagecontrolname.picture = car_photo

Chriss
 
Thanks Chriss, that's the part that I found difficult, defining an image control in a form and making it work correctly.
 
If you're having problems on that level, your question should be how do I create a form in VFP.

The starting point is creating a project. That's one of the things listed if you pick "new" from the File menu. Once you have a project a project manager window comes up and has several tabs, where you can start creating project items, like data, documents (forms and reports), classes (class libraries with classes), Code (programs) and Other files (menus, text files inclusing header files, images), plus everything is also displayed in the "All" tab.

Well, you can start with a form there, activate the "documents" tab, activate the "Forms" node, click new and you get an empty form. In the menu "View" you can activate the Form controls toolbar and from there you can put controls on the form, for a picture an image control.

If you're on that level of starting with VFP programming, it's good to have a simple goal, plus you already seem to have a dbf, fine, but there are a lot of basics to first know before diving in to a specific form. The point about picking a car code can be done by showing the list in a grid, so before you go for the image, first add your dbf into the form data environment, try to let the form display the list of cars, then the user can simply click on one, which becomes the current record and then the code from my first answer would work.

I bet you don't know the dataenvironment to begin with, so before you get to the image control you see there are a lot of levels to first go through:
1. creating a project
2. creating data (you seem to have done that without a project, which is possible, true, but unusual)
3. creating a form
4. finding out how to let a form have access to data
5. putting control on a form
6. adding code in certain places, like form init/load events, button click event.

Go to amazon perhaps, and look for a VFP book that covers VFP6. Notice it's one of the worst VFP versions in the opinion of many developers, VFP7 is worlds better and VFP9 is the latest and greatest and even those who know VFP since legacy versions will likely use that and not necessarily provide answers/code that also still works in that old VFP6 version.

I was close to recommending Garfield Hudson videos, while some of his tutorials also could work in VFP6, you surely soon hit limits of VFP6.

Chriss
 
In fact, I defined a project and immediately started working with the database, I omitted to clarify that point with the intention of going directly to my problem.

I think my difficulty is in these points that you mention:
"4. finding out how to let a form have access to data
5. putting control on a form
6. adding code in certain places, like form init/load events, button click event."

I intend to avoid (as far as possible) the use of the forms offered by FoxPro and do all the work with programming lines.

I thought that showing the photo of the car was a matter of a few lines of programming in a .prg
It is very difficult?

Thanks Chriss.
 
Dronner said:
I intend to avoid (as far as possible) the use of the forms offered by FoxPro and do all the work with programming lines.
Why? You throw away the "Visual" in Visual FoxPro. In the end you'll also create a form. And it's far simpler to design a form visually.

I already mentioned there is a toolbar for form controls, which you activate in the menu "View" once and for all future usage of VFP, if you like. You click on the control you want on a form, then click on the form, where you want the control. Once a control is on the form you can move it, resize it, etc. All that is hardly doable with code. And code will not give you the impression of the look of the form at all, unless you have a weird mind like that of a chess player that can visualize a checc position after reading the notation of moves.

You also have a lot of things in direct access that a prg form does not have at all, like the data environment, which is the intended place to open data by picking the dbfs to open at start of the form.


Chriss
 
Maybe my intention is to create something from zero, although it is true that if I use those tools I will save a lot of time. I probably need to become a little more familiar with the FoxPro tooling environment. For now I'm going to try to do it from a form.
 
from zero" is no problem. In the project manager you pick documents->forms->New button and then pick "New form", not "Form wizard". You get an empty form. It has titlebar, close button and some more details. I mean, if that is already too much, then don't target the Windows operating system. Seriously, I think you mean you don't want to inherit any code from a wizard, well, such a new form has nothing in it.

Chriss
 
Quote: "In the project manager you pick documents->forms->New button and then pick "New form", not "Form wizard"

Yes, I will do it that way. Thank you.
 
Hi Dronner,

I can empathize with your situation here based on personal experience. I was programming in Foxpro 2.x, a by-the numbers app. I was told Visual Focpro would take 6 months to learn. Well, it was far less than that before I could at least complete a simple project, with the help of forum contributers like Mike (Lewis), Chris, Tamar and others.

You might come up with a code-only solution for your particular question here. If this is your ONLY object, fine. But I would strongly reccommend in the long run to learn about forms as Chris has suggested. It's not that big a deal. I and others can help you there. And if all else fails, of course, there are several books which can help (ask Tamar).

Hope this gets you started.

Steve
 
Thanks, Steve, for seconding the recommendation.

Never heard the term "by-the-numbers app", but I can imagine something that has a DOS screen showing say at max 10 options 0-9, you press a key 0-9 and get to the next level menu. I've used something like that as a students holiday job. It can be quite effective, but only in case you have a small set of functionalities you navigate through. And I remember I had a very bad time starting with it. Others, who used that software for a long time knew the end point they wanted to navigate to by 3 to 5 digit numbers. Fine, but if you don't know there's not necessarily intuitive digit combinations where you find something.

Windows applicatations mainly work with the point and click principle when it comes to choices and using the keyboard is mainly for writing text, or code, when that is the task. Whether you're a mouse hater or not. And even when the platform is a tablet you'd point and tap, you'd not even have a keyboard other than on screen. If I think of something like an application for car salespersons, then the tablet platform is not far fetched, so it is even a mouse focused form of application, not keyboard focused.

Well, and what I think of when you say "if I enter code 1, the app shows me the photo" I think you're better off with just a scrollable HTML page of the cars available, especially if customers can look over your shoulder and see a well designed look & feel of a software, that would make a better impression on me than the typical legacy Foxpro application look.

Chriss
 
Thank you Steve for your intervention, I find the information in the "properties" window that appears when a form is created a little "cryptic", but I understand that it is the best option. For that reason I would have to understand the configuration of the form step by step to achieve the objective of viewing a photo. Just that purpose.

I'm working on a project that doesn't necessarily have to do with selling cars, that's just an example that occurred to me to make things more familiar. Any shape model serves as a template for different concepts. Just as you search for a car, you can search for an employee of a company in which case the code would be their identification document or you can search for an item in the inventory of a warehouse or the medical formula of a patient in a doctor's office, etc.
The idea is basically that I need to view a photo linked to the ID that I have entered in an alphanumeric field. We are almost talking about a "procedure", nothing more. That's why any example you can give me helps me. I am very clear that it is better to have the photos in a folder and with a name referring to their identification.

P.S.: Obviously I am going to use the forward, back, first, last buttons to scroll sequentially or I will also want to see all the photos in an icon view to randomly select one, but I will always need to view the photos, linking one record to one or more photos.

Thanks.
 
Students_with_photo_kobyjs.jpg
 
Makes me wonder. You said you wanted to create something from zer, I told you how to and now you have a screenshot of a form that's clearly done by a form wizard.

I told you how to set a picture already in my first anwswer:
Code:
thisform.imagecontrolname.picture = car_photo
You will need to find out the name of the control that currently shows this shadow portrait, and you get that by clicking on it and looking into the properties window.

Chriss
 
Chris said:
Never heard the term "by-the-numbers app"

The reason you (and everyone else) never heard of this is because I made it up. It came from my way-back brain programming in Basic where each line was numbered. If anyone (besides me) remembers that, they're showing their age.

[pc]

Steve
 
Well, I shortly programmed Basic on a programmable casio Calculator.

VC20 and later, on C64 and Apple homecomputers had the same concept.

IIRC you did't have a code editor, a prg was written into memory by starting with a line number followed by code, to be able to write something between two existing lines of code you better have gaps, so you numbered code you initially wrote with 10,20,30, etc and then could use 5, 15, later, or even 7. It was the norm, though gaps of 4 or 8 or 16 would have served the purpose better.

Well, I didn't used punch cards. And those who did would be called out with the luxury of at least having a computer and not just a slide rule or an abacus, sure.

Chriss
 
Interesting. I don't recall the calculator. I built a Heathkit H89 PC & brought it to Korea with me. There were only 2 of us with a pc in Korea in the military. Soon realized I could do NOTHING with it without an operating system. So I bought HDOS and took the Microsoft Basic course by correspondence. I didn't mail in lessons (no email, remember?), so I wasn't "certified". It retained my interest, though, using a blackjack program as the main learning tool.

Steve
 
Dronner, if you seriously want to do something from scratch, then here are instructions on getting a form done that displays a list of data (a DBF) and a picture besides that list:

1. create a new project
2. create a dbf with the data to display
3. create a new empty form as I described it, not using aform wizard

I'm not detailed about these steps as you already were at that stage, at least at step 2 and I described how to create a form without the wizard.

4. While in the form designer, the first step is to give it hands on the data: Right click the form and pick "Data environment". You're asked to pick a DBF from an "open" (open file) dialog, so pick the one DBF you created in step2.
5. The data environment will show the picked dbf as a window with the file name as title and the fields you created in step 2. Also a dialog captioned "Add table or view" is still open and you can close that, as you don't want to add a second table.
6. Drag the window visualizing the DBF table to the empty form and a grid is created there, that's already configured in all details to show the list of data you have
7. Enlarge the form by dragging the lower right form corner witht he mouse. When you hover close to the corner the mouse pointer will change to a diagonal double arrow pointing out you can resize. Similarly you can resize the grid at the edges, corners and at the black square dots in the middle of edges with the mouse. Arrange it so you have empty space for the image control to display the photos you stored into your dbf.
8. If you don't have the form controls toolbar visible in the upper section directly under the menu you can activate it by going into the menu "View"->"Form controls toolbar"
9. pick the image control...
imagecontrol_e1ak8a.jpg

that one
10. Click on the form where the image control should show. Resize and move it where you want it.
11. Right Click on the grid and pick "Code" from the context menu
12. The editor will likely show the first method (labeled "Procedure") of the grid "Activate Cell", you don't want to write code there, above the white editing area pick the dropdown button and pick the "AfterRowColChange" item. The code editor will now show a line LPARAMETERS nColIndex, you don't need that parameter, but you have to keep this line anyway, or the form will later error when that event happens. Edit it sthis way:
Code:
LPARAMETERS nColIndex
Thisform.UpdateImage()
13. Save with CTRL+S and close the editor window, you'll still be in the form designer that was behind it.
14. Go to menu "Form"->"New Method" and program the UpdateImage Method by first entering the name "UpdateIkmage" and the Add button. You could also write a description, but that name is pretty descriptive alrady. Click Close.
15. To get to that new method go back into the code editor by right clicking the form and picking Code again, like you did for the grid code.
16. In the section above the white code area, be sure you pick the Object "Form" and Procedure "updateimage", it'll be listed last, after all other methods, as userdefined method.
17. In that method write this code line
Code:
thisform.image1.Picture = Alltrim(car_photo)
18. pick "Init" from the procedure list and there also write the one line as in grid.AfterRowColChange:
Code:
Thisform.UpdateImage()
Without any parameters this time.
19. Save again with CTRL+S and then you can run the form.

The form starts whoing the first car. Click on a record and the image of that record will show.
You can tidy up a lot of things now, for example, not showing the record id or the image file name in the grid and many more things.

But in short (or long), you have a runnable form displaying an image from a list. You don't need a navigation bar, you can simply scroll and pick out a record, you don't need a search box to enter an id to go to, but you could easily let the list be sortable with clicks on the header, add filters, etc., but all thise things are next steps.

Chriss
 
Thank you very much for the full detailed procedure. You have been very kind. Everything worked correctly. I only have one question: When I made an alternate model using the "Wizard" to create a form, but applying all its other instructions, I got this error. What causes it?

Error_hk78tm.jpg
 
I didn't instruct you to write such a line of code. What form did you use?

It seems to me you again used a form created by a wizard, You were told to not do that.

This is the stpes to create an emtpy form that has nothing in it from wizards:
new_form_ng2luq.png

myself said:
In the project manager you pick documents->forms->New button and then pick "New form"
Just as depicted.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top