How would you do this?

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
ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

How would you do this?

Post by ajperks » Sat Nov 03, 2018 6:12 pm

The problem.
I have a group of fields with the address of Fld "Field " & N N being an integer from 1 to 100
The fields fill up from number 1
I need to insert data rather than overwrite, so the fields further down the list (higher numbers) need to be moved down 1 field each to create a space for the inserted data.

If 100 fields already have data, then 100 can be overwritten so 99 becomes 100...

The question.
What slick code can detect the first empty field, or 100 if all full, and then move all the fields from the insertion point, down one place (into the higher number). ??
Any ideas?

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How would you do this?

Post by Klaus » Sat Nov 03, 2018 6:14 pm

Sorry, no idea what you want to do... :D

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Re: How would you do this?

Post by ajperks » Sat Nov 03, 2018 6:23 pm

Thanks Klaus,

fld 1 full (zxc)
fld 2 full ( asd) <-- insert Field "Data" between 2 and 3
fld 3 full (ert)
fld 4 full (dfg)


Becomes

fld 1 full (zxc)
fld 2 full ( asd)
Fld 3 contains the inserted data <-- insert Field "Data" between 2 and 3
fld 4 full (ert)
fld 5 full (dfg)


Does this clarify?

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How would you do this?

Post by Klaus » Sat Nov 03, 2018 6:34 pm

Still not too clear... :-)

Do you need to really CREATE a new field and postion this new field between the existing fields?
Or do you already have all neccessary fields and "just" want to "move" the content?

Can't you use a datagrid or listfield for that?
Managing lots of fields like this meand lots of work and calculations. 8)

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How would you do this?

Post by bogs » Sat Nov 03, 2018 6:35 pm

I think I understand what he is trying to do, maybe.

100 fields, maybe empty, maybe not. If empty, put data into it, if no field is empty, move the contents of field 1 -> field 2, fld 2 -> 3, etc.

If that is the case, your going to need at least one repeat loop, and possibly 2. Psuedo code (not tested) -

Code: Select all

repeat with x = 1 to the number of fields
	#assumes your data is in a variable...
// checks if field is empty, inserts data if empty
	if field x is "" then 
		put myData into field x
	else  // no field was empty...
		add 1 to tmpNotEmpty
	end if	
end repeat
if tmpNotEmpty = 100, then all your fields have text.
You can use similar code to move the code from the last field to the first, starting your repeat loop with the 100th field and working backwards.
Image

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Re: How would you do this?

Post by ajperks » Sun Nov 04, 2018 10:59 am

This is my home brew solution.
Thank you everyone for your suggestions.

Code: Select all

 --*** Check if this field has data in it. if so, move data below it down one and save.
   
   repeat with tCounter = 99 down to ComtLoc
      if fld ("Field " &  tCounter )on card id 1169 = empty then
           else
         put fld( "Field " & tCounter) on card id 1169 into fld( "Field " &  tCounter +1) on card id 1169 
           end if
         end repeat
      put fld "Comment" into  Fld ("Field " & ComtLoc) on card id 1169

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”