Tuesday, May 31, 2011

Quickie Demo for fun



This is a little demo file that does something very simple. It takes a value, searches for it in list B, returns the corresponding value in list A. Handy for simple 1 or 2 word lists, where you have the ID list in the same order as the list of actual values. Sometimes you need to hunt 1 list against the other to get an ID or other value.

Just tossing this out there for fun. Maybe it's handy. It's not going to work for every situation but it's lightweight. Enjoy

Demo file

3 comments:

  1. Hi Chiyodo, thank you for sharing this demo file, I like the script comments - parameters are fun !

    I just wanted to point out a small tweak to your script which might resolve some situations. where you set $id, the let variable wordFocus uses the Position function to obtain the position of x. One thing that can happen conceivably is that x occurs in other values in the list as a part of another word, ie:

    BigPear
    SmallPear
    Pear

    If you search for x which would be Pear, it would first find it on line 1 so grab the value from position 1 in listA. A small tweak to resolve this could instead have it search for x preceeded and followed by a return character ¶, so that it is searching for x as its own full value.

    With that said, it's a very cool technique and one that I can see uses for already in some of my solutions, cheers !

    - Daniel

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Hi Daniel,

    Thanks for checking out the demo and the feedback! :)

    Sounds like a great tweak. I do believe the situation you describe is being handled in the code already. It works for 'pear', 'smallpear' and 'bigpear'.

    That logic that controls that is in the body of the LET statement in this line notice the line ends before and after the 'x' variable:


    Case (

    PatternCount ( values ; ¶ & x & ¶) = 0 ; "Null" ;
    GetValue ( $aList ; thisPosition )

    )


    Add a few buttons for your case above + a corresponding numbers in list A, it should work or it did for me. :)

    I'm sure theres places this method would break. Like if you had pear on the list more than once it will only grab the first instance. It's not doing any looping or recursion. However, in lots of cases this works well when you have trusted lists.

    Let me know if it doesn't work for you, we can throw together version II of the demo and make it better.

    I hope it is useful. BTW, I've enjoyed your blogs many times. Cheers to you.

    Best!
    Chiyoko

    ReplyDelete