Repeats, creating multiple field boxes to mimic grid -SOLVED

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
AndyP
Posts: 524
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Repeats, creating multiple field boxes to mimic grid -SOLVED

Post by AndyP » Wed Sep 03, 2008 5:26 pm

Hi, New to the Revolution trying to get my head around the syntax, I normaly program web sites with PHP.

I'm trying to mimic a grid by creating multiple rows of field boxes.
The number of rows will be determined by the number of rows in a database.

So far I have this: (testing with preset values from a button action)


on mouseUp

put 100 into xpos
put 100 into ypos
put 1 into dbdfieldscountstart
put 4 into dbfieldscountend
put 5 into dbrowscount


repeat with dbrows = 1 to dbrowscount

repeat with dbfields = dbdfieldscountstart to dbfieldscountend
create field dbfields
set the location of card field dbfields to xpos,ypos
set the width of card field dbfields to 50
set the height of card field dbfields to 20
add 50 to xpos
end repeat

put 100 into xpos
add 30 to ypos
put dbfieldscountend into dbfieldscountstart
put 8 into dbfieldscountend
end repeat


end mouseUp


This creates the rows but removes each row during the next repeat which I do not understand?

Also the initial created field box remians in situ?

You may be asking 'why dosn't he use the field table?' - I want to easily specify backround colours of individual fields dependent on content. Looking through the docs and searching the forums this does not seem possible....apart from this it's also a good exercise for me.

Any help will be much appreciated.

Andy
Last edited by AndyP on Thu Sep 11, 2008 5:05 pm, edited 1 time in total.

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Wed Sep 03, 2008 8:32 pm

I've done similar things before, like when I made a color palette program that needed 256 squares for 256 colors. Here's basically what I did:

Code: Select all

on mouseUp
  put 10 into varRows
  put 10 into varCols
  put 1 into varNameCounter
  put 40 into varPosTop
  put 30 into varPosLft
  lock screen
  repeat varCols times
    repeat varRows times
      put "dbfields" & varNameCounter into varName
      create field varName
      set the width of field varName to 50
      set the height of field varName to 20
      set the left of field varName to varPosLft
      set the top of field varName to varPosTop
      put varPosTop + 20 into varPosTop
      put varNameCounter + 1 into varNameCounter
    end repeat
    put 40 into varPosTop
    put varPosLft + 50 into varPosLft
  end repeat
  unlock screen
end mouseUp
There might be better ways to do this, but this is just how I did something like this before.

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Wed Sep 03, 2008 8:34 pm

You could also go so far as to remove the 3d borders and make a single line border around each, then also make your grid a group, so that if it gets too big, you can size the group, and your fields in it are scrollable.

AndyP
Posts: 524
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Great . Thanks

Post by AndyP » Wed Sep 03, 2008 9:16 pm

Hi Garrett

Thanks, that really helps.

Very impressed with the response to my first call for help.

Andy

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Repeats....

Post by bjb007 » Fri Sep 05, 2008 8:02 am

AndyP

Don't get into the situation I had experimenting
with something similar. I was cloning a small
graphic and trying various methods - and using
different names for them.

If you don't have a way to delete the generated
fields they pile up and when you get to 2,000 or
so (very easy to do) the Inspector will give an error
of "Too many objects to display".

Very disconcerting (and time-wasting) to say the least.

I had to knock out a script (party guessing the
various names I'd given them ) and run it
repeatedly in a loop until I reduced them to a
number which didn't upset the Inspector.
Life is just a bowl of cherries.

AndyP
Posts: 524
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Post by AndyP » Fri Sep 05, 2008 1:27 pm

Thanks bjb007

Is there a way to delete all the field objects prior to creating the next batch?

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Repeats

Post by bjb007 » Fri Sep 05, 2008 2:28 pm

If you name them something0001, something0002 etc
the you can do

repeat with i = 1 to 1000
if exists(field ("something"&i)) then
delete field ("something" & i)
end if
end repeat

(just from memory)

I had multiple copies with the same names (Rev
doesn't seem to mind) so I had to put all the
above in another loop (1 - 99) to get rid of them
all.

Even if your app doesn't need a "Reset" button you
could put one on just for getting rid of the rubbish and
remove it when you've got it sorted.

There's also a plug-in which can handle up
to 10,000 objects. It was mentioned in one
of the responses to my query on this subjet.

Just had a look - it's called RevNavigator from
www.inspiredlogic.com/navigator.
Life is just a bowl of cherries.

AndyP
Posts: 524
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Post by AndyP » Mon Sep 08, 2008 2:17 pm

Thanks bjb007

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”