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

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
jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

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

Post 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.
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392
dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

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

Post 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.
jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

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

Post 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
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392
dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

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

Post 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
jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

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

Post by jesse »

thanks that works great :)
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

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

Post 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
jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

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

Post by jesse »

Thanks Klaus. It seems to have worked without the parenths. i will put the parenths for good practice though.
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

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

Post 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
SparkOut
Posts: 2986
Joined: Sun Sep 23, 2007 4:58 pm

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

Post 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.
jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

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

Post by jesse »

will do Klaus. I always want to code properly :)
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

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

Post by Klaus »

Good boy! :D
Post Reply