is this possible??

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

smash
Posts: 99
Joined: Tue Aug 19, 2008 5:18 am

Post by smash » Fri Aug 07, 2009 9:27 am

Hi guys,
it is quiet obvious that i can not understand the user guide or the dictionary (they make my head spin) and i am really trying, REALLY hard to understand them. i have read and re-read those many many times, and i come out worse than when i went in.
i have a card that is like a ENTRY FORM.
a field where a persons name is entered, and a button, that transfers it to a table.
now as the names are entered, they just pop in down the column.
so when someone enters twice,("bob1" and "bob2") they go into the table underneith each other. what i am trying to do, is when the bob has been entered a second time, is NOT TO go directly underneith, but to skip 7 rows in that column.
so when the next name is entered, it will go directly under "bob1" but 6 rows before "bob2"
klause lineoffset was the only thing i could find in the dictionary that had any reference to controlling rows.
god i so suck at this.

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Post by shadowslash » Fri Aug 07, 2009 12:14 pm

If I know it right, lineOffSet would return 0 if you try to look for a line with other duplicates. An example would be if you search "bob" in a container that has multiple lines containing "bob". Instead of returning the line number of the first result it could find, lineOffSet returns 0. Try using the find command instead.
Parañaque, Philippines
Image
Image

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Aug 07, 2009 12:24 pm

It is very simple, Smash. If you simply refuse to even try what I advice you to do, then you will never manage to get it done. I have given the most clear directions you can possibly expect anyone to post on this forum. So, try it, tell me how far you got with my example, and then we'll talk again.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

smash
Posts: 99
Joined: Tue Aug 19, 2008 5:18 am

Post by smash » Fri Aug 07, 2009 1:27 pm

hi mark, i am sorry you feel that i did not do what you have asked, as i did this
Set the script of field "Search" to:

Code:
on keyUp
put fld "Data" into myList
filter myList (with the text of me & "*")
put myList into fld "Results"
end keyUp


Put the following data into field "Data":

Aaron
Bernard
Chloe
Chris
Cindy
Dart Vader

Now type a C in field "Search". You will see that the results field now contains:

Chloe
Chris
Cindy

Type an h after the C and you will see that the Results field contains

Chloe
Chris

It works!

Best,

Mark
but this is not what i was trying to achieve.
i am trying to explain (obvioulsy badly) that i am quiet aware that i am putting person the in twice, i would just like to put him 7 rows down in the column INSTEAD of directly underneith.
is this possible?
cheers

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Aug 07, 2009 3:39 pm

Smash,

If you do what I wrote, you will see that all Bob Smiths will be found. That's what you're asking, right? All you wrote was something like "I want to find Bob Smith". If this is not what you want, please elaborate.

Putting a particular name on row 7 is easy:

Code: Select all

put "Bob Smith" into line 7 of field "Data"
Again, if that's not what you want, explain.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

smash
Posts: 99
Joined: Tue Aug 19, 2008 5:18 am

Post by smash » Sat Aug 08, 2009 12:22 am

hi mark,
If you do what I wrote, you will see that all Bob Smiths will be found. That's what you're asking, right? All you wrote was something like "I want to find Bob Smith". If this is not what you want, please elaborate.
sorry mark, this is "sort of what" i am trying to achieve.
Putting a particular name on row 7 is easy:
Code:
put "Bob Smith" into line 7 of field "Data"

Again, if that's not what you want, explain.
this is "sort of what" i am trying to achieve

ok, i will try to explain again.

i have a card, that resembles an entry form
a field, that i put the "RidersName" into, and a field i put the "HorsesName" into.
i have six buttons that represent different "levels".
when i click one of the "levels" buttons it sends the "ridersname" and the "horsesname" to a certain "level" (a table on another card in the stack)
this is my script for the "levels" button



on mouseUp
set the opaque of me to false

local theCardName
put "Entries" into theCardName
put the label of me after theCardName

if (field "HorsesName" is not empty) and (field "RidersName" is not empty) then
add 1 to field "BridleNumber"
put field "BridleNumber" & tab & field "HorsesName" & tab & field "RidersName" & return after field "Entries" of card "Entries5"

else
answer "You have not completed the entry details correctly"

end if

end mouseUp

now each time i put an "entrants" name and horse in, and press the Level button, you then clear the fields and put the next entrant in.
the next entrant may be the same "rider" but on a different "horse" so when i press the "levels" button, this rider and different horse go directly under each other in the table, so it looks like this
joe blow.... blacky
joe blow....snowy
this is what i dont want to happen.
i would like write a script, that if a "ridersname" allready exists in that table to go either 7 rows/lines up or down (which ever is available) the table.
now if this is possible, the lines/rows inbetween joe blow being entered twice, need to be available to other entrants.
i hope this explains it better mark.
thank you for taking the time to help me
cheers

Klaus
Posts: 14190
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Sat Aug 08, 2009 3:15 pm

Hi smash,

I will give it another try, but you will see that the logic nocessary here are not trivial.
I created a script that will do most of what you wnat, at least as I understood it.

Plese read the scripts and my comments and I will sure give you some more hints later,
but may need more info as you will notice after reading the sripts.
It is NOT tested, but should work ;)
Copy and paste it into the Rev script editor for better reading!

And here we go, it is a BIT lenghty, but hopefully this will help you:

Code: Select all

on mouseUp
  set the opaque of me to false
  
  local theCardName
  put "Entries" into theCardName
  put the label of me after theCardName
  
  ## It is always a good idea to put field contents into variables,
  ## since the accesstime of variables is MUCH faster than for fields!
  ## May not be important in small scripts like this one, but anyway :-)
  put fld "HorsesName" into tHorsie
  put fld "RidersName" into tRider
  
  if tHorsie = empty OR tRider = empty then
    answer "Please enter all informations!"
    exit mouseup
  end if
  ## Done!
  ## Avoiding "else" whereever possible makes scripts much more readable!
  
  ## All infos are present we can continue:
  ## 1. Prepare the complete new entry line for later use, whereever we need to insert it
  put field "BridleNumber" & tab & tHorsie & tab & tRider into tEntry
  
  ## First we need some more info like the NUMBER of the entries already made,
  ## since if we want to shuffle 7 lines up or down we need to know if we have enough
  ## lines to do so, know what I mean?
  
  ## Store field into variable!
  put field "Entries" of card "Entries5" into tTable
  put the num of lines of tTable into numoftablelines
  
  ## 2. Check if tRider is already in your table
  ## I created a function that will return all duplicte entries from a field
  ## or empty if no doublettes were found
  ## We pass the riders name and the field where this should be looked for
  put fDoublettes(tRider,tTable) into tDoublettes
  put the num of lines of tDoublettes into tDoublettes_numoflines
  
  ## No double entry so far:
  if tDoublettes = empty then
    put tEntry & CR after field "Entries" of card "Entries5"
    
    ## Done for this time, so time to say good-bye:
    exit mouseup
  end if
  
  ## Entry found!
  ## Now we need to check WHERE to insert the new entry!
  ## Only one doublete:
  if tDoublettes_numoflines = 1 then
    set itemdel to TAB
    
    ## We fetch the line number of that entry:
    put item 2 of tDoublettes into tLine_number
    
    ## Are there enough lines to skip 7 lines?
    if (tLine_number + 7) <= numoftablelines then
      put tEntry & CR after line (tLine_number + 7) of field "Entries" of card "Entries5"
    else
      
      ## I do not know what you would do in this case????
      ## I wou.ld simply put the entry after the other entries:
      put tEntry & CR after field "Entries" of card "Entries5"
    end if
    
    ## Done for this time, so time to say good-bye:
    exit mouseup
  end if
  
  ## OJK, now there are more than 1 doublettes in the table, but I leave the rest up to you.
  ## As you see, the logis for this is not too trivial!
  
  ## Good luck :-)
end mouseUp


function fDoublettes tWhat,tWhere
  
  ## Go through all line and check. if found collct and return these lines AND the numbers of the lines!!!!!
## repeat for each is insanely fast, but we have no counter there like in "repeat with i = x to y", 
## so we make our own which is still much faster than "repeat with..."!
  put 0 into tLine
  repeat fore each line i in tWhere

## Increment "custom" counter
    add 1 to tLine
    put empty into retvalue
    
    ## Is tWhat in tWhere?
    if i contains tWhat then
      
      ## Yes, then collect the line and its number
      put i & TAB & tLine & CR after retvalue
    end if
  end repeat
  
  ## Get rid of trailing CR
  delete char -1 of retvalue
  return retvalue
end fDoublettes
Best

Klaus

smash
Posts: 99
Joined: Tue Aug 19, 2008 5:18 am

Post by smash » Sat Aug 08, 2009 10:53 pm

WOW!!!!!!!!!! KLAUS
this has certainly given me hope !!!!
ok i am off to understand this new script.
this has given me heaps to learn
THANK YOU
will let you know how i go
THANK YOU AGAIN KLAUS

Klaus
Posts: 14190
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Sat Aug 08, 2009 11:23 pm

Hi smash, sorry, little error in the function, here the corrected one:

Code: Select all

function fDoublettes tWhat,tWhere 

  ## Go through all line and check. if found collct and return these lines AND the numbers of the lines!!!!! 
## repeat for each is insanely fast, but we have no counter there like in "repeat with i = x to y", 
## so we make our own which is still much faster than "repeat with..."! 
  put empty into retvalue 
  put 0 into tLine 
  repeat fore each line i in tWhere 

## Increment "custom" counter 
    add 1 to tLine 
    
    ## Is tWhat in tWhere? 
    if i contains tWhat then 
      
      ## Yes, then collect the line and its number 
      put i & TAB & tLine & CR after retvalue 
    end if 
  end repeat 
  
  ## Get rid of trailing CR 
  delete char -1 of retvalue 
  return retvalue 
end fDoublettes

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

Post by mwieder » Sun Aug 09, 2009 6:21 am

...and of course that should be

repeat for each...

instead of

repeat fore each...

smash
Posts: 99
Joined: Tue Aug 19, 2008 5:18 am

Post by smash » Sun Aug 09, 2009 8:35 am

hi klaus,
thank you so much for all the trouble you went to to, this is quiet complicated for me ( but it is great, as i had no idea you could do so much)
now i have been playing and researching all i can, but i am having difficulty on finding any info on controlling the table lines.
so i have been a bit stumped on this bit

ERROR
if (tLine_number + 7) <= numoftablelines then


button "Button": execution error at line 58 (Operators +: error in left operand), char 7

what or where do i find info on this ??
what does this mean?
thank you klaus (my singing idol) :D

Klaus
Posts: 14190
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Sun Aug 09, 2009 12:08 pm

Hi smash,

obviously "tLine_number" is not a number that Rev can compute...?

You can:
1. Send me the stack (or a stripped down version) so I can take a look :)
2. Debug the script by yourself, or at least put in some "answer " dialogs to see the value fo the variable in question, know what I mean?

Add a dialog e.g. here:

Code: Select all

...
 ## We fetch the line number of that entry: 
    put item 2 of tDoublettes into tLine_number 

   #############################
   ANSWER tLine_Number
   ## Then check what you see in the dialog!
   ## This will give us a first hint, maybe ;-)
   ## Don't forget to remove these lines later!
   #############################
    
    ## Are there enough lines to skip 7 lines? 
    if (tLine_number + 7) <= numoftablelines then 
      put tEntry & CR after line (tLine_number + 7) of field "Entries" of card "Entries5" 
    else
...
Best

Klaus

Post Reply