Create new objects

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: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Create new objects

Post by Philhold » Tue Oct 27, 2009 7:53 pm

I'm stuck at the bottom of a learning curve and each time I move up a bit I slide to the bottom.

Here's what I'm trying to do. I have a card with a field, an Option Menu and a couple of check boxes in a line. When the user has completed a line they can decide to create a new line of objects and complete those and so on.

I can group the objects on the card and have these act as a background and a button so that the user can create a new card and complete that, I could then loop through each card and do stuff with the collected data.

What would be preferable though would be to allow the user to create a new row of field, option menu etc and have this appear under the previous one. I've been playing around with create field bla, set the location of field bla to bla + x etc but have got myself in a complete old muddle.

Before I give in and go back to having one card per row is there an easy way for me to duplicate a group (row) of fields and option menus and have these appear below the previous one. Or am I taking entirely the wrong approach to this.

Thanks

Phil

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

Post by bn » Tue Oct 27, 2009 8:14 pm

Phil,
look at the clone command. You could clone a group with the field and buttons and option menu. You would eventually have to reset the controls of the clone: put empty into field, set hilite of button x to false etc. You can clone invisibly and reset the group and adjust the location.

If I understand you correctly this could be a way to do it.
regards
Bernd

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Location: Kent, UK
Contact:

Post by gyroscope » Tue Oct 27, 2009 9:02 pm

Hi Phil, Bernd is spot-on concerning the use of the clone command. As it happens, I've been using clone to get copies of groups today. Just to point out, you might get into a bit of a pickle if you don't change the name of the cloned group as well as the names of the buttons and fields within the group, as you go.

One way would be as follows (although I guess I might have made a mountain out of a molehill again and there might be an easier way :wink: :

Code: Select all

global gGroupCount
on mouseUp
   lock screen
   clone the last group
   put the short name of the last group into tGName
   put word 3 of tGName into tGroupCount
   
   put fld "group count" into gGroupCount
   put tGroupCount+1 into tGroupCount
   put gGroupCount into fld "group count"
   set the name of the last group to "Clone G "&tGroupCount
   unlock screen
end mouseUp
I've put the global value of gGroupCount into a field which should be saved in a saved stack everytime; as well as "put fld "group count" into gGroupCount somewhere in an on openStack handler.

The names of the buttons and fields can be changed in the same way, saving the info with a save stack command also.

I hope that's helpful to you.

:)

Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Post by Philhold » Tue Oct 27, 2009 10:14 pm

Many thanks Bernd and David, much appreciated.

David,

Your code works great for me and does almost exactly what I want. Actually it does exactly what I want but I can't seem to get the groups to stack as I want them.

I'll let you know how I get on.

Cheers

Phil

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Create new objects

Post by sturgis » Tue Oct 27, 2009 11:08 pm

Another option might be to have a single form, and since it sounds like you're compiling data, shove the data into a table field (or a database or array for use later or something of that nature) on the same card as the user answers each line. Then simply reset your fields and whatnot to however you want them to appear for the next entries.

If you wish your entries to be editable after they're submitted, you can check for a click in your table field, detect the line clicked, put the line values back into your field/option etc, set an edit flag with the line number so you know which to replace, and on resubmission, replace the items of that line with the new information, and unset the edit flag.

Could do this with a datagrid too of course. Setup a form for entry and use the datagrid form for display or something of that nature.

Philhold wrote:I'm stuck at the bottom of a learning curve and each time I move up a bit I slide to the bottom.

Here's what I'm trying to do. I have a card with a field, an Option Menu and a couple of check boxes in a line. When the user has completed a line they can decide to create a new line of objects and complete those and so on.

I can group the objects on the card and have these act as a background and a button so that the user can create a new card and complete that, I could then loop through each card and do stuff with the collected data.

What would be preferable though would be to allow the user to create a new row of field, option menu etc and have this appear under the previous one. I've been playing around with create field bla, set the location of field bla to bla + x etc but have got myself in a complete old muddle.

Before I give in and go back to having one card per row is there an easy way for me to duplicate a group (row) of fields and option menus and have these appear below the previous one. Or am I taking entirely the wrong approach to this.

Thanks

Phil

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Location: Kent, UK
Contact:

Post by gyroscope » Wed Oct 28, 2009 12:36 am

And I've just thought of yet another angle of attack:

Providing you have a fixed amount of groups you know you are going to deal with, you could provide all the groups on your cards and,except the first one, hide them all. You could then write a small routine to show the next group on completion of the field + buttons etc; or even simply an extra button marked Next to show the next group/ make the window larger.

:)

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Post by mwieder » Wed Oct 28, 2009 2:47 am

I'm stuck at the bottom of a learning curve and each time I move up a bit I slide to the bottom.
rotfl - that's what programming's all about...[/quote]

At the risk of starting you off on another of those curves, it seems that maybe a datagrid is what you're after here. There's a datagrid lesson in the manual that talks about setting up a datagrid form and populating it with different types of controls, then being able to add another row of them afterwards. Bear in mind that dealing with datagrids requires some serious under-the-hood moments, and I'm not at the point where it's intuitive. I'll post the url to the lesson if I can dig it up again.

Update: here you go...

http://revolution.screenstepslive.com/s ... -of-People

Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Post by Philhold » Wed Oct 28, 2009 4:41 pm

Thanks to all for your suggestions. I tried the Datagrid approach but in doing so realised that what Sturgis suggests was the easiest way to go for me. The one downside is the fact that the user can't go back to amend an entry because I empty the fields each time I add a line of data to my collection. It is all working fine now.

I must try to make time to learn about Datagrids because from what I did today I can see they will be the answer in another project.

Thanks again

Phil

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Post by sturgis » Wed Oct 28, 2009 5:12 pm

If you're looking to amend already entered data, you can go to http://revolution.screenstepslive.com/s ... s/datagrid
and read up on how to determine which line (aka record) was selected, how to get the data, how to add a row, or how to update the data. All under the "Working With Data Grids (Forms & Tables)" section.
Philhold wrote:Thanks to all for your suggestions. I tried the Datagrid approach but in doing so realised that what Sturgis suggests was the easiest way to go for me. The one downside is the fact that the user can't go back to amend an entry because I empty the fields each time I add a line of data to my collection. It is all working fine now.

I must try to make time to learn about Datagrids because from what I did today I can see they will be the answer in another project.

Thanks again

Phil

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”