Page 1 of 1

Set the y and x loc of an image in a repeat

Posted: Fri Jun 24, 2011 8:06 pm
by jesse
I am attempting to loop thru a database cursor called tRecords and create an image for
each row of data basically that are called Image1, Image2, etc... using tCounter.

However setting the loc of image is not working for some reason.
I have tried set, put, and neither seem to work. When I read about loc it says you can set the
loc of an image but I must once again be missing a little something.

I am trying to set the x loc to 90 * i (i.e. 90 * 1,90*2, etc...) and the y loc to just 355.

Code: Select all

repeat with i = 1 to the number of lines of tRecords
create image "Image" && i
set the location of Image "Image" && i to 90*i,355
end repeat
any help would be much appreciated.

Re: Set the y and x loc of an image in a repeat

Posted: Fri Jun 24, 2011 8:46 pm
by dglass
You say your images are named 'Image1', 'Image2', 'Image3', etc., but you are setting the name:

set the location of Image "Image" && i to 90*i, 355

using the && operator which is going to result in 'Image 1', 'Image 2', 'Image 3', etc.

Re: Set the y and x loc of an image in a repeat

Posted: Fri Jun 24, 2011 8:51 pm
by jesse
sorry. correction my images are image 1, image 2, etc... i forgot && created a space.


you can see the below code is what creates the image and then attempts to set the location
but i get a syntax error with the set location line so im doing something wrong im just not sure what :(

Code: Select all

create image "Image" && i
set the location of Image "Image" && i to 90*i,355

Re: Set the y and x loc of an image in a repeat

Posted: Fri Jun 24, 2011 8:57 pm
by dglass
This compiles with no error.

Code: Select all

create image "Image" && i
      put it into theNewImage
      set the location of theNewImage to 90*i, 355

Re: Set the y and x loc of an image in a repeat

Posted: Sun Jun 26, 2011 1:04 am
by jesse
thanks that works great :)

Re: Set the y and x loc of an image in a repeat

Posted: Sun Jun 26, 2011 5:34 pm
by Klaus
Jesse,

you need to put the concatenated name in parenthesis or you get this error!
...
create image ("Image" && i)
set the location of Image ("Image" && i) to 90*i,355
## Hint: save some typing and use abbreviations:
## set the LOC of IMG ...
## btn = button
## fld = field
## sb = scrollbar
## :D
...


Best

Klaus

Re: Set the y and x loc of an image in a repeat

Posted: Mon Jun 27, 2011 6:51 pm
by jesse
Thanks Klaus. It seems to have worked without the parenths. i will put the parenths for good practice though.

Re: Set the y and x loc of an image in a repeat

Posted: Mon Jun 27, 2011 6:56 pm
by Klaus
Hi jesse,

yes, ALWAYS use parenths when creating "strings" like-> image ("name of image" & aVariableWithANumber)
It seems to have worked without the parenths
The engine will throw an error when you least exspect it! (Murphys law :D )

Believe me, I use LiveCode (former Revolution/MetaCard) since 1999 and I do not recommend this without reason 8)


Best

Klaus

Re: Set the y and x loc of an image in a repeat

Posted: Tue Jun 28, 2011 1:07 am
by SparkOut
Hear hear! Klaus is absolutely right. I also ensure that a reference is evaluated in such situations as

put "some text" into theArray[(field "destinationForText")] -- using parentheses to make sure the field reference is evaluated so the right value is used.


Overkill? Maybe, but like Klaus I am not saying it just for fun. Nor to be awkward.

Re: Set the y and x loc of an image in a repeat

Posted: Tue Jun 28, 2011 10:11 pm
by jesse
will do Klaus. I always want to code properly :)

Re: Set the y and x loc of an image in a repeat

Posted: Tue Jun 28, 2011 10:53 pm
by Klaus
Good boy! :D