If statement not working

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

If statement not working

Post by tyarmsteadBUSuSfT » Thu Jun 19, 2014 11:04 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: If statement not working

Post by bn » Fri Jun 20, 2014 12:01 am

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: If statement not working

Post by Simon » Fri Jun 20, 2014 12:02 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: If statement not working

Post by bn » Fri Jun 20, 2014 12:13 am

Hi Simon,

"formattedHeight" is a very nifty workaround.

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

Kind regards
Bernd

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: If statement not working

Post by Simon » Fri Jun 20, 2014 12:32 am

Thanks Bernd,
It was that imageData size thing that triggered it.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: If statement not working

Post by tyarmsteadBUSuSfT » Fri Jun 20, 2014 12:56 am

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: If statement not working

Post by Simon » Fri Jun 20, 2014 1:03 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: If statement not working

Post by tyarmsteadBUSuSfT » Fri Jun 20, 2014 1:12 am

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

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: If statement not working

Post by tyarmsteadBUSuSfT » Fri Jun 20, 2014 1:18 am

Simon,
I meant to type:
if the filename of image "itemPic1" is empty and image "itemPic1" is empty then, etc.
Thanks
Ty

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”