Page 1 of 1

If statement not working

Posted: Thu Jun 19, 2014 11:04 pm
by tyarmsteadBUSuSfT
I am using inpart this stament to check if an image exist. :

put the imagedata of img "itemPic3" into tItemPic3
answer tItemPic3
if tItemPic3 is empty then
put empty into item 16 of line tNextFileNumber of tSavedFile
else
set the folder to specialFolderPath("documents")
create folder "myimages"
put specialFolderPath("documents") &slash&"myimages"&slash into tP
set the JPEGQuality to 100
export image "itemPic3" to URL ("file:" & tP&"myimages"&tTime3&".jpg") as JPEG
put tP&"myimages"&tTime3&".jpg" into item 16 of line tNextFileNumber of tSavedFile
end if
The issue I am having is that even when the tItemPic3 is empty the execution skips the empty exception statement.
Thank you
Ty

Re: If statement not working

Posted: Fri Jun 20, 2014 12:01 am
by bn
Hi Ty,

I don't think the imageData of an image is ever empty.

I created an empty image by dragging it from the Tools palette
then named it "itemPic3"

Code: Select all

on mouseUp
   set the imageData of img "ItemPic3" to ""
   put the imagedata of img "itemPic3" into tItemPic3
   answer (tItemPic3 = "") && length (tItemPic3) && the milliseconds
end mouseUp
I don't know what condition makes your image "empty" or not empty. You could test for other values.

But maybe you explain what you do to image "ItemPic3" to make it empty or not empty.

Kind regards
Bernd

Re: If statement not working

Posted: Fri Jun 20, 2014 12:02 am
by Simon
Hi Ty,
Gosh what a workaround!

Code: Select all

put the formattedHeight of img "itemPic3" into tItemPic3
answer tItemPic3
if tItemPic3 is 0 then
In my testing it seems the imageData is never empty as long as there is a size to the image object.

Simon

Re: If statement not working

Posted: Fri Jun 20, 2014 12:13 am
by bn
Hi Simon,

"formattedHeight" is a very nifty workaround.

The ones that came to my mind would have really been awful.

Kind regards
Bernd

Re: If statement not working

Posted: Fri Jun 20, 2014 12:32 am
by Simon
Thanks Bernd,
It was that imageData size thing that triggered it.

Simon

Re: If statement not working

Posted: Fri Jun 20, 2014 12:56 am
by tyarmsteadBUSuSfT
I thought I pressed the send on this,
It appears that due to the fact that sometimes I am adding a new picture and other times I am keeping an existing picture that I need to check the filename and the image data to verify if that image is there. When it is a new image then I have and image data, but if I have a saved image on the card I have a file name. If both are empty then I can execute the correct statement and if one or the other is not empty then if makes the condition false and allowing the correct statement to excite.
Does that make since?
Ty

Re: If statement not working

Posted: Fri Jun 20, 2014 1:03 am
by Simon
Hi Ty,
Except for an imported picture, it has no filename.
Now if you don't use imported picture then all you need is the filename.
imageData never seems to be empty, if there is an empty image object it will contain imageData even if there is nothing to see.

Simon

Re: If statement not working

Posted: Fri Jun 20, 2014 1:12 am
by tyarmsteadBUSuSfT
Simon,
Great advise, I don't plan to import on this app, but will keep in mind for my other project. The point about the image data never being empty sure explains a lot.....
Thank you two for your help
Ty

Re: If statement not working

Posted: Fri Jun 20, 2014 1:18 am
by tyarmsteadBUSuSfT
Simon,
I meant to type:
if the filename of image "itemPic1" is empty and image "itemPic1" is empty then, etc.
Thanks
Ty