- Hi and Welcome to -
++++++++++++++++++++++++++++++++
LASSO TIPS FOR NEWBIES: 3.1
++++++++++++++++++++++++++++++++
I'm your host, M i l e s.
First and foremost, a good place for you to start with Lasso is the
following 5 things:
The FIRST LASSO TIPS FOR FILEMAKER
-> http://www.listsearch.com/FileMakerProTalk.lasso?id=151351
The LAST LASSO TIPS FOR FILEMAKER
-> http://www.listsearch.com/FileMakerProTalk.lasso?id=153721
10 LASSO RESOURCES
-> http://www.listsearch.com/lassotalk.lasso?id=143018
THE LASSO RESOURCES ADDENDUM
-> http://www.listsearch.com/lassotalk.lasso?id=143417
OMNIPILOT RESOURCE LIST
-> http://www.omnipilot.com/Resources+for+Beginners.2225.lasso
http://www.omnipilot.com/Tip+of+the+Week.1768.lasso
http://www.omnipilot.com/Hosting+Providers.1744.lasso
http://www.omnipilot.com/Frequently+Asked+Questions.1791.lasso
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
THIS PORTION OF LASSO TIPS Æ’or NEWBIES IS SPONSORED BY:
P O I N T I N S P A C E H O S T I N G
http://www.pointinspace.com/
Professional Lasso / MySQL / FileMaker Hosting
Mention this ad on sign-up and receive 5% off your account!
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Secondly, Chickens DO come home to roost. Eventually. As I had
indicated in my last LTÆ’N/F/ & now MySQL, there will be a LASSO
SUMMIT!!! Yes that's right kiddies, its time to break out the
champagne and get your groove on with others of our kind, your Lasso
Brethren. Praise be to all things Lasso. The dates Feb 17 - 19th
2006, in Ft. Lauderdale, FL. By now you've seen the 'official'
announcement, so this is nothing new, but those of who haven't, go
here: http://www.lassosummit.com/ Grok to your hearts content. Word
is that I, your magicmilesness, will be hosting a roundtable or two.
Thirdly, I will conducting newbie training for Lasso, on the 2 days
before Lasso Summit. If you've enjoyed Lasso Tips for Newbies, then
the time is at hand to get it from the original Lasso Evangelist
himself...ME. Dates: Feb 16 - 17, two FULL days of Lasso Training
for the Neophyte (the unwashed masses). More details and the
official announcement later on this week, but let's keep this just
between you and I for the moment (and 10,000 of our closest
friends). Seating will be limited.
++++++++++++++++++++++++++++++++
TODAYS TIP:
T h r e e L i l T o y s
++++++++++++++++++++++++++++++++
Today's tip is actually 3 tiny tips that have been buggin me for
months that I frequently see others not taking advantage of, that you
can USE today. No if's, and's, or but's about it. So without
further adieu....on with the tips.
PART ONE: ITERATION is the KEY!
From time to time you will run across the need to pull values
out of a variable and reorder them as you see fit. OR just get the
values out and use them as you see fit. There are several ways to do
this with Lasso, however none more powerful than the ITERATE tag.
Some of you have seen this tag before and probably thought to
yourselves that it looks just a tad scary, and you know what, you'd
be right. It is. Its just downright intimidating! Coming from a
newbie standpoint, it is. However as with all things, it just needs
lil light shed on it to give it a lil clarity, so that perhaps you
won't shy away from the thing the next time you run across the need
to use it.
In its basic form an [iterate] tag is very similar to a [loop]
or [while] statement. They all do the same things, sort of. Except
that a LOOP or WHILE statement doesn't actually allow you to use
itself as the comparitor statement, or in simpler parlance, to
compare itself against itself! A loop will continue running a series
of operations to a certain number; a WHILE will continue doing the
same thing while a certain condition is true; but an ITERATE
statement, an iterate statement will go several steps further than
either and allow you to stop and examine the values that you feed it
and change it in process! And that my Lasso Brethren is where the
rubber hits the road and why this lil toy is SOOOO amazingly powerful.
Im going to do something that may make you a bit fearful, but
I'll 'splain as I go along...
// initializing an array
[var: 'a_mytest' = (array)]
//adding values to the array
[$a_mytest = (array: 'apples', 'oranges', 'pears', 'grapes')]
//for each value in the array put a value into the variable
'fruits'
[iterate: $a_mytest, (var: 'fruits')]
// display each value of $fruits on its own line and add a line
break.
I love: [$fruits]<BR>
// close iteration when completed
[/iterate]
So in essence all I did was populate a data storage unit (an
array, which is like a series of cubby holes), and tell the iterate
to take each value in the array, and display it as its own variable!
While this example doesn't show the true power of an iterate
statement it does show the promise of it...so lets take a real world
example.
Suppose you have a series of filenames in a field and each
filename is separated by a comma, and you want to take those
filenames and create links from them. How would you do this ? You
could use a LOOP statement to go through the field and then find the
values, but then you'd have to build a series of conditional
statements to actually build links to the actual files. Not really
helpful. Enter the ITERATE statement!
[var: 'a_myfiles' = (array)]
[var: 'a_myfiles' = ((field: 'user_files') -> (Split: ','))] //
converting the field contents to an array.
[iterate: $a_myfiles, (var: 'v_filename')]
<a href="[$v_filename]">[$v_filename]</a><BR>
[/iterate]
The only thing that is different here from the last code
snippett is the 2nd line.
Now let's really show the power of the iterate statement...
[var: 'a_myfiles' = (array)]
[var: 'a_myfiles' = ((field: 'user_files') -> (Split: ','))] //
converting the field contents to an array.
[iterate: $a_myfiles, (var: 'v_filename')]
[if: ($v_filename) !>> 'no']<a href="[$v_filename]">
[$v_filename]</a><BR>[/if]
[/iterate]
Same as before...only NOW Im making it conditional. And the
conditional is that if the filename DOES NOT contain the characters
'no', then display the link. This conditional checking, and the
ability to check against itself, is what separates an iterate from a
LOOP or WHILE. Because the conditional check doesn't exist, the
variable doesn't exist, the only thing that exists is the data. You
can't do this effectively with a LOOP or WHILE statement (operative
word in the sentence: effectively).
PART TWO: PIMPIN' THE '&' AND '+' OPERATORS
This is sooooo simple it should be outlawed. I actually had to
have this explained to me like I was a 5 yr old. Hopefully you won't
need that here.
a.) THE '+' sign. What is it ? Anywhere where Lasso sees a '+'
operator it takes whatever is on the left side and on the right side
and mushes them together. If its a literal (text), it will pull them
together. If its a numeric, it will add the two values together. If
its two variables, it will pull them together. It wont, however, add
two arrays together, for that you need to use: array -> merge,
however it will stick both arrays right next to one another. Which
probably won't help you much, and will more than likely confuse the
hell out of you until you discover array->merge! I digress. So
let's look at this...
[1 + 1] run that and see what you get. (hint this is really easy)
now try: [1 + ' plus one'] and see what you get.
and now ['one ' + 'plus' + ' one' + ' equals: ' + (1+1)]
the '+' is really that powerful. It can completely replace
[string_concatenate] and its completely safe for literals and
numerics. The really cool part about that last line, is that Lasso
pulled together string literals AND did a math calculation at the
same time! Is this a cool language or what ? Ok, so its silly but
you get the point. Its just another way to pull your data together.
b.) The '&' sign. What is it ? Think of it this way, the
simple way to describe what the operator does would be that it
returns an object after something has modified it. Take the
following example to read header values:
[
var: 'MYVARS' = vars->keys;
$x->sort;
$x = $x->join('<br>');
$x->uppercase;
$x;
]
Run that, and you'll get:
__CLIENT_GETPARAMS__
__CLIENT_POSTPARAMS__
__ENCODING__
__HTML_REPLY__
__HTTP_HEADER__
__INPUT_ENCODING__
__RESULT_CODE__
__RESULT_MESSAGE__
_AT_END
MYVARS
The example takes the passed header values (the right side values of
the name value pairs) and sets them all into a single variable, sorts
them (because this an array), then takes each pair of the array and
adds a '<BR>' where the was none before and then converts text into
upper case.
Ok now lets do the same thing in one line using the "&" sign:
Try this: vars->keys->sort & join('<br>')->uppercase &; '<br>';
The major difference between these two methods ? Note that the first
way is 5 separate operations, AND requires you to declare a variable
at every step of the way. Using the & sign ? Requires no variable
declaration whatsoever, and is ONE operation. Can you say SPEEEEEEEEED!
Still don't get it ? Think of an '&' sign as a super text and
variable replacement tool on steriods! That and a bag of chips, and
that my friends is just the tip of the iceberg.
PART THREE: Variable Check!
Ever want to see that your variable has been created ? Think there's
no way to do that ? This may sound silly but there are times you
actually need to check to see if a variable has been created. In
order for you to check to see if a variable has been created is to do
the following: [var_defined: 'e1']. This statement will check if the
variable e1 exists in the lasso variable map. If its NOT there, it
will return FALSE as a value. If it IS there it will return TRUE.
So how is this helpful ?
var: 'v_passedparams' = (array); //
setting variable to an array
var: 'v_passedparams' = (client_postparams); //
passing in array values from client_postparams which is a pair array
var: 'v_pp_size' = (integer: $v_passedparams->size); //
getting the size of the array
$v_passedparams->(remove: $v_pp_size); //
removing the last item from the array
iterate: $v_passedparams, var:'loopvalues'; //
setting only the values that were passed into the array
(var: ($loopvalues->name)=($loopvalues->value));
/iterate;
The script above sets an array for passedparams, then moves all the
values for client_postparams into the array, then checks the size of
the array and sets the value to an integer, then grabs that value,
and removes the very last value from the array. It then sets an
iterate statement to grab all the values from the array of parameters
into separate variable with values (fully populated). In short this
tiny lil script will allow you to grab and set a series of passed
values into actual variables and populate those variables with their
cognate values. This is what is referred to as Dynamic Variable
Creation, which can be somewhat dangerous in certain cases. There
are times when you'll want to use a method like this, and at the same
time, check to see if the variables that were passed in, actually
exist, enter the var_defined statement:
if: (var_defined: 'e1'); ...etc.../if;
The statement above checks to see if e1 was created and exists. It
does NOT check to see if e1 contains a value, we assume that e1 will
contain a value if its been passed.
THE SHORT AND SWEET: These are tiny lil tips that if used properly
can help you get to a different place in your Lasso Development work.
Happy Lassoing ~ Let us ALL double click! Praise be to Lasso.
M i l e s.
Spreadin' The Lasso Gospel!
LASSO-MYSQL CONSULTANT & EVANGELIST FOR HIRE
-don't know what 'lasso' is ? - http://www.omnipilot.com/
------------------------------------------------------------
M i l e s miles@lassoconsultant.com
ToolboxEngine - Custom CMS for everyone (415) 686 - 6164
http://www.lassoconsultant.com/ AIM/Yahoo/MSN: magikmiles
------------------------------------------------------------
Creating custom content management systems for yoga, dance,
healing arts, & now real estate starting at just $65.00 a
month, incld: domain registration, web hosting, email and
webmail, and access to TOOLBOXENGINE! A very robust tool.
------------------------------------------------------------
--
------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives:
http://www.listsearch.com/lassostudiotalk.lasso
Manage your list subscription:
http://www.listsearch.com/lassostudiotalk.lasso?manage