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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why this code didn't work? (I take 1

Status
Not open for further replies.

misulica

Programmer
Feb 8, 2003
43
RO
Why this code didn't work? (I take it from a site):

Many developers choose General fields because they don't want to have the files separate from the table. The user shouldn't be able to break the application by accidentally deleting the image files.
In this situation, use a binary memo field instead of a General field. You can use this line to get the file into the memo field:

Append Memo Img From <File> Overwrite

where Img is the name of the binary memo field. In Visual FoxPro 6.0, use an image control to display such a .JPEG file. This requires the following code in the Refresh event of the form:

Local lcFile
* Delete the previous image, if it exists
If File(This.Image.Picture)
Erase (This.Image.Picture)
Endif
* Create a new temporary file on disk
* SYS(2023) returns the current temporary path
lcFile = SYS(2023)+&quot;\&quot;+Sys(3)+&quot;.JPG&quot;
Copy Memo myTable.Img to (m.lcFile)
This.Image.Picture = m.lcFile
 
misulica

I works for me. Do you get an error? You do not describe what is problem. &quot;Why this code didn't work&quot; is not enough. Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
OK!
I adapted the command line to my database:
Append Memo Photo From <File> Overwrite

I have a table with 8 columns:
ID ProductName Weight Dimensions Price Photo Producer Tel
1 Something 0,8 120x350 100$ memo John Doe 12

As you can see, I have records in every field of the table, except the memo field Picture who has at record no.1 only the word memo,in this cell is nothing.
Now, I have 10 records, in the cells below Picture appeared only memo,memo,... without having something inside those cells (I named it cell to make the difference between title Picture of the memo field and memo word of the memo field)

Under Photo appeared memo give by VFP, not by me, and I can't rename those memo into photo1,photo2,...photo9999 as I think it should be.
So, if I APPEND MEMO PHOTO.. I receive &quot;Command contains unrecognized phrase/keyword&quot;
 
misulica

The principal works, but I think you have a misconception of how things work. I'm not sure of your level of understanding, but seeing that you are trying to show a binary picture in a grid, I have a fairly good idea.

1. I created a table with a binary memo field.
I used:
select myTable
go bottom
append blank
2. I used this command :
Append Memo img From &quot;c:\mazda_slp.jpg&quot;
3. So now I end-up with a binary picture in a binary memo (don't forgot this is not a picture!)
4. I created a form and put a grid on it. Set the grid column count to 1.
5. I put a picture control in the column 1 of the grid a switch the column1's current control to the image1 control. Note this step is important.
6. Since to picture is only binary information, you need to translate it back to a picture as the code you are using suggests. So in the init of the grid I used:
Code:
lcFile = SYS(2023)+&quot;\&quot;+Sys(3)+&quot;.JPG&quot;
Copy Memo Img to (m.lcFile)
This.column1.Image1.Picture = m.lcFile

Steps number 5 and 6 are important. But please note that this suggestion only applies to one column grid qith one picture in the table. You would have to modify the code to accomodate more columns and more records.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thank you, i'll try your suggestion, and YES, I'm a little beginner in foxpro, so believe me it's hard, very hard.
Again, thank you
 
misulica

If its any help here is the Pseudo-code of the form I used to test your problem. Note that this code will not run, but it show the settings required.
Code:
PUBLIC oform1
oform1=NEWOBJECT(&quot;form1&quot;)
oform1.Show
RETURN
DEFINE CLASS form1 AS form
	DoCreate = .T.
	Caption = &quot;Form1&quot;
	Name = &quot;Form1&quot;
	ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 1, ;
		Height = 157, ;
		Left = 24, ;
		Panel = 1, ;
		RowHeight = 80, ;
		Top = 36, ;
		Width = 313, ;
		Name = &quot;Grid1&quot;, ;
		Column1.ControlSource = &quot;table1.img&quot;, ;
		Column1.CurrentControl = &quot;Image1&quot;, ;
		Column1.Width = 166, ;
		Column1.Name = &quot;Column1&quot;
	ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
		Caption = &quot;Header1&quot;, ;
		Name = &quot;Header1&quot;
	ADD OBJECT form1.grid1.column1.text1 AS textbox WITH ;
		BorderStyle = 0, ;
		Margin = 0, ;
		ForeColor = RGB(0,0,0), ;
		BackColor = RGB(255,255,255), ;
		Name = &quot;Text1&quot;
	ADD OBJECT form1.grid1.column1.image1 AS image WITH ;
		Height = 17, ;
		Left = 41, ;
		Top = 35, ;
		Width = 100, ;
		Name = &quot;Image1&quot;
	PROCEDURE grid1.Init
		lcFile = SYS(2023)+&quot;\&quot;+Sys(3)+&quot;.JPG&quot;
		Copy Memo Img to (m.lcFile)
		This.column1.Image1.Picture = m.lcFile
	ENDPROC
ENDDEFINE
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Halleluiah, it works.I put the photo into the memo field and bring it directly to image control (your code I wrote directly into the form's Refresh event).

But, because I wrote the code (to put the photo in the memo) in the Command Window, this photo was place at the bottom of the records.I don't know how to put it in the right position into the record no.1, and so on.
Please help me, don't be angry
 
misulica

If you need the picture in the first record instead of the last, then use:
SELECT myTable
go top
Append MEMO img FROM &quot;c:\mazda_slp.jpg&quot;

And in the init of your form:
SELECT myTable
go top
thisform.refresh()
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Understand.
But in my database I have 10 records (a record means ProductName, price, wheight,etc).When I click on Next button, another product with his characteristic appeared on the form, and so on.I need the pictures of all the products from the database (in Access they have a sample database, one of their forms presents the employees of a company.Click next and another employee with his age, ocupation... and PHOTO appeared.)
I want the same thing on my database, I have a product, let's say a chair - so a chair photo I want to put in that record, record no2 reffers to a carpet- a carpet photo will appered....
 
I assume the pictures have a different names. Its difficut to automate the procces, but you could use something like:
Code:
SELECT myTable 
go top
do while !eof()
  myPicture=GETPICT(&quot;.jpg&quot;,&quot;&quot;,table1.desc) && The desc field would be the description of the item or in your case productName, that way on the open button you'll know for which item you are loading a picture for.
Append MEMO img FROM &myPicture
  select myTable
  skip
enddo

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Isn't a simple way to add pictures to each record?
I add a photo to the first record (thanks to your code).Maybe you give me a way to add another photo to the second record, the third.. from the Command Window
 
Hurray, problem solved.I insert the photos manually (the entire database will have about 50 records) using:
select mytable
go2... and it works.Thank you, you're the 5 stars MAN, finally I can go further.

By the way, is there a way to have the image control in 3D?
I want the photo to be raised from the form (a property, something?)
 
misulica

Use a container (From the form toolbar) control, and set the SpecialEffect to raised and put your picture control in it. Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top