Re: Hard code or portable code

2004-03-11 Thread hershrev
Very good explanation .
Thanks , hershrev
On Thursday, March 11, 2004, at 01:31 AM, J. Landman Gay wrote:
On Wednesday, March 10, 2004, at 04:09 PM, hershrev wrote:
Can I please have a little understanding on the parameter part of 
functions what does it do or add?
The following is kind of long, so apologies in advance. I wrote it for 
someone else a long time ago. The person I was writing to said he 
never used custom functions because he didn't know what they were. He 
asked me to explain.

***

If Revolution does not have a built-in function to do something you 
want, you can write your own function to do it instead. Suppose we 
want to add two numbers together and get a total. (This is a very 
simple example, and really you would not need to do this because MC 
can add two numbers easily inside a script. But it makes a good 
example.) So we can write a function called addNumbers like this:

function addNumbers num1,num2
  put num1 + num2 into theTotal
  return theTotal
end addNumbers
The parameters num1 and num2 are like baskets that hold whatever 
values the original handler sends to the function. In this case, they 
each will contain a number. The special word return tells Revolution 
to send the variable theTotal back to the handler that asked for the 
information. So, this function takes two numbers that are passed to it 
in the parameters, adds them together, and sends back a total. Now we 
can write a handler that uses this function this way:

on myHandler
 put 16 into theFirstNumber
 put 4 into theSecondNumber
 put addNumbers(theFirstNumber,theSecondNumber) into myTotal
end myHandler
This handler will send 16 and 4 to our custom function 
addNumbers. The addNumbers function will catch these two numbers in 
its parameters num1 and num2, then add them together, and send 
back 20. The script myHandler will receive that 20 and put it into 
the variable myTotal. So myTotal now equals 20.

When you use a function in a handler, you must provide a place for its 
results to go -- a variable usually, or sometimes a field. For 
example, this will not work:

  addNumbers(theFirstNumber,theSecondNumber)

because there is no place for the returned information to go. A 
handler that uses a function must provide a place to store the 
information that the function sends back. This is true of built-in Rev 
functions too. For example, this will not work:

  the date

because there is no place for the date to be stored. You must provide 
a place:

  put the date into myDate

A handler that uses a custom function must follow the same rule. It 
must provide a place for the returned information to be stored:

  put addNumbers(theFirstNumber,theSecondNumber) into myTotal

Functions can be as short or as long as you want, and sometimes can be 
very complicated. But the basics are always the same: a handler asks a 
function to do some work and often sends some parameters to the 
function to tell it what to use for that work. The function does the 
work and returns the finished calculation to the original handler. The 
handler can use the finished calculation any way it wants, just as if 
it were any other variable.

--
Jacqueline Landman Gay | [EMAIL PROTECTED]
HyperActive Software   | http://www.hyperactivesw.com
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-10 Thread hershrev
Can I please have a little understanding on the parameter part of 
functions what does it do or add?

e.g.  function latestField param1, param2
Thanks in advanced ,
hershrev
On Thursday, March 4, 2004, at 01:51 PM, hershrev wrote:
Yes , All hats up for you.


function latestFields
  local myVar
  repeat with i=1 to (the number of flds)
put fld i after myVar
  end repeat
  return myVar
end latestFields
an reuse the function and call if from various other places.

HTH,
Brian
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-10 Thread Dar Scott
On Wednesday, March 10, 2004, at 04:09 PM, hershrev wrote:

Can I please have a little understanding on the parameter part of 
functions what does it do or add?
Parameters are variables local to the function.

When the function is used, the values specified with the use are put 
into the variables.

An example (untested):

function double x
  return x*2
end double
on mouseUp
  put 1 into x
  put 2 into y
  put double(3) + double(x) + double(y+1)
end mouseUp
==
14
You can have more than one parameter.  In use, they are separated by 
commas.  This is not the same as the comma operator (usually).

There are reference parameters, but that is more advanced.

Dar Scott

___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-10 Thread hershrev
On Wednesday, March 10, 2004, at 06:45 PM, Dar Scott wrote:

On Wednesday, March 10, 2004, at 04:09 PM, hershrev wrote:

Can I please have a little understanding on the parameter part of 
functions what does it do or add?
Parameters are variables local to the function.

When the function is used, the values specified with the use are put 
into the variables.

An example (untested):

function double x
  return x*2
end double
on mouseUp
  put 1 into x
  put 2 into y
  put double(3) + double(x) + double(y+1)
end mouseUp
What should the result be on this ?
==
14
You can have more than one parameter.  In use, they are separated by 
commas.  This is not the same as the comma operator (usually).

There are reference parameters, but that is more advanced.

Dar Scott

___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-10 Thread Dar Scott
On Wednesday, March 10, 2004, at 05:30 PM, hershrev wrote:

function double x
  return x*2
end double
on mouseUp
  put 1 into x
  put 2 into y
  put double(3) + double(x) + double(y+1)
end mouseUp
What should the result be on this ?
==
14
14

(Sorry about the cute notation.)

The double(3) would evaluate to 6.

The double(x) would take the local x in mouseUp (mouseUp can't see the 
one in double) and have that doubled.  That would evaluate to 2.

The double(y+1) would evaluate to the same as double(2+1) or double(3) 
or 6.

And 6 + 2 + 6 evaluates to 14.

Dar Scott

___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-10 Thread J. Landman Gay
On Wednesday, March 10, 2004, at 04:09 PM, hershrev wrote:
Can I please have a little understanding on the parameter part of 
functions what does it do or add?
The following is kind of long, so apologies in advance. I wrote it for 
someone else a long time ago. The person I was writing to said he never 
used custom functions because he didn't know what they were. He asked me 
to explain.

***

If Revolution does not have a built-in function to do something you 
want, you can write your own function to do it instead. Suppose we want 
to add two numbers together and get a total. (This is a very simple 
example, and really you would not need to do this because MC can add two 
numbers easily inside a script. But it makes a good example.) So we can 
write a function called addNumbers like this:

function addNumbers num1,num2
  put num1 + num2 into theTotal
  return theTotal
end addNumbers
The parameters num1 and num2 are like baskets that hold whatever 
values the original handler sends to the function. In this case, they 
each will contain a number. The special word return tells Revolution 
to send the variable theTotal back to the handler that asked for the 
information. So, this function takes two numbers that are passed to it 
in the parameters, adds them together, and sends back a total. Now we 
can write a handler that uses this function this way:

on myHandler
 put 16 into theFirstNumber
 put 4 into theSecondNumber
 put addNumbers(theFirstNumber,theSecondNumber) into myTotal
end myHandler
This handler will send 16 and 4 to our custom function addNumbers. 
The addNumbers function will catch these two numbers in its parameters 
num1 and num2, then add them together, and send back 20. The 
script myHandler will receive that 20 and put it into the variable 
myTotal. So myTotal now equals 20.

When you use a function in a handler, you must provide a place for its 
results to go -- a variable usually, or sometimes a field. For example, 
this will not work:

  addNumbers(theFirstNumber,theSecondNumber)

because there is no place for the returned information to go. A handler 
that uses a function must provide a place to store the information that 
the function sends back. This is true of built-in Rev functions too. For 
example, this will not work:

  the date

because there is no place for the date to be stored. You must provide a 
place:

  put the date into myDate

A handler that uses a custom function must follow the same rule. It must 
provide a place for the returned information to be stored:

  put addNumbers(theFirstNumber,theSecondNumber) into myTotal

Functions can be as short or as long as you want, and sometimes can be 
very complicated. But the basics are always the same: a handler asks a 
function to do some work and often sends some parameters to the function 
to tell it what to use for that work. The function does the work and 
returns the finished calculation to the original handler. The handler 
can use the finished calculation any way it wants, just as if it were 
any other variable.

--
Jacqueline Landman Gay | [EMAIL PROTECTED]
HyperActive Software   | http://www.hyperactivesw.com
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-04 Thread hershrev
Ok its up and running was my mistake did replace completely ,  it was 
twice because it had all the info of all the fields plus the info from 
the field itself.
thanks , hershrev
On Thursday, March 4, 2004, at 02:46 AM, Brian Yennie wrote:

Yes , All hats up for you.
Just a question, why when I write ...
put function () into field x it doesn't replace the old contents of 
the field ?
Try this.
Put the following in your stack script:
function latestFields
  local myVar
  repeat with i=1 to (the number of flds)
put fld i after myVar
  end repeat
  return myVar
end latestFields
Now in a button script, do this:

on mouseUp
  put latestFields() into last fld
end mouseUp
The function by being in the stack script becomes available to you 
whenever you need it. You may want to adjust where it puts the  results.


Now to compare if I write
on mouseUp
  repeat with x=1 to the number of flds
put text of field x  return after y
  end repeat
 put y into fld 1
end mouseUp
what is the difference besides function or message, speed wise or 
something else ?
thanks , hershrev

Functions and handlers (functions start with function, handlers with 
on) should execute at about the same speed, both very fast unless 
you are really counting your milliseconds. The convenience of writing 
a function rather than putting the code into your button's mouseUp 
handler is that you can reuse the function and call if from various 
other places.

HTH,
Brian
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-03 Thread hershrev
I think we are not on the same track.  
On Wednesday, March 3, 2004, at 02:03 AM, Dar Scott wrote:
On Tuesday, March 2, 2004, at 08:21 PM, hershrev wrote:

is there a way to imitate hard code with some kind of container ?
Here are a couple of ideas:

1.  Use a list of names--

Create a list in a manner much like this:

repeat with x = 1 to the number of fields
   put (the name of field x)  LF after myVar
end repeat
Now , how do you get  the contents of all the fields ?
if you put myVar into myQuery,  the result will be the field names and 
not the field content ? ( THE MAIN POINT IS TO GET THE LATEST DATA 
meaning if the user edits the field after the repeat script the result 
should be the updated contents as hard code)
if you come up with a recipe  for this I'll raise my hat for you.
thanks , hershrev


Dar Scott





___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-03 Thread Brian Yennie
Hershrev,

I'm not sure I understand what you mean by hard-code.
If you want a persistent way to reference a field, regardless of it's 
name, you can use the ID.
Or, to get all of the fields, something like:

repeat with i=1 to (the number of flds)
  put fld i after myVar
end repeat
If you want to write a function that always returns you the latest:

function latestFields
  local myVar
  repeat with i=1 to (the number of flds)
put fld i after myVar
  end repeat
  return myVar
end latestFields
HTH,
Brian
Now , how do you get  the contents of all the fields ?
if you put myVar into myQuery,  the result will be the field names and 
not the field content ? ( THE MAIN POINT IS TO GET THE LATEST DATA 
meaning if the user edits the field after the repeat script the result 
should be the updated contents as hard code)
if you come up with a recipe  for this I'll raise my hat for you.
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-03 Thread hershrev
On Wednesday, March 3, 2004, at 08:44 PM, Brian Yennie wrote:

Hershrev,

I'm not sure I understand what you mean by hard-code.
If you want a persistent way to reference a field, regardless of it's 
name, you can use the ID.
Or, to get all of the fields, something like:

repeat with i=1 to (the number of flds)
  put fld i after myVar
end repeat
If you want to write a function that always returns you the latest:

function latestFields
  local myVar
  repeat with i=1 to (the number of flds)
put fld i after myVar
  end repeat
  return myVar
What result will return myVar give, the fields names or contents of 
the fields ?
end latestFields

HTH,
Brian
Now , how do you get  the contents of all the fields ?
if you put myVar into myQuery,  the result will be the field names 
and not the field content ? ( THE MAIN POINT IS TO GET THE LATEST 
DATA meaning if the user edits the field after the repeat script the 
result should be the updated contents as hard code)
if you come up with a recipe  for this I'll raise my hat for you.
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-03 Thread Dar Scott
On Wednesday, March 3, 2004, at 06:06 PM, hershrev wrote:

Create a list in a manner much like this:

repeat with x = 1 to the number of fields
   put (the name of field x)  LF after myVar
end repeat
Now , how do you get  the contents of all the fields ?
if you put myVar into myQuery,  the result will be the field names and 
not the field content ? ( THE MAIN POINT IS TO GET THE LATEST DATA 
meaning if the user edits the field after the repeat script the result 
should be the updated contents as hard code)
I am probably still a little lost.  I guess I don't know what hard 
code is.

Once the above is set, you can get the contents with this:

put LF into bindingChar
put empty into valueAccumulator
repeat for each line f in myVar
  put field f after valueAccumulator
end repeat
Do you want to have all the field values evaluated each time you look 
at the variable?  I don't know how to do that.

Here are three things that might be close.

A.
Use a function instead of a variable.
   put catFields() into ...

B.
Use value on the variable.  Set it up like this:
   field Alpha  field Beta'  field Gamma

Use it like this

   put value(autoCatFields) into ...

C.
Use properties.  If all those field are in a group, then define a 
custom property with a getProp that calculates the concatenation of the 
values of all fields within the group.

   put the catFields of group Will Robinson into ...

Am I getting closer?

Dar Scott

___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-03 Thread hershrev
On Wednesday, March 3, 2004, at 08:52 PM, Dar Scott wrote:

On Wednesday, March 3, 2004, at 06:06 PM, hershrev wrote:

Create a list in a manner much like this:

repeat with x = 1 to the number of fields
   put (the name of field x)  LF after myVar
end repeat
Now , how do you get  the contents of all the fields ?
if you put myVar into myQuery,  the result will be the field names 
and not the field content ? ( THE MAIN POINT IS TO GET THE LATEST 
DATA meaning if the user edits the field after the repeat script the 
result should be the updated contents as hard code)
I am probably still a little lost.  I guess I don't know what hard 
code is.
Hard code is writing in the editor
on mouseUp
  put field 1  field 2 into mSql
end mouseUp
Once the above is set, you can get the contents with this:

put LF into bindingChar
put empty into valueAccumulator
repeat for each line f in myVar
  put field f after valueAccumulator
end repeat
Do you want to have all the field values evaluated each time you look 
at the variable?  I don't know how to do that.

Here are three things that might be close.

A.
Use a function instead of a variable.
   put catFields() into ...

B.
Use value on the variable.  Set it up like this:
   field Alpha  field Beta'  field Gamma

Use it like this

   put value(autoCatFields) into ...

C.
Use properties.  If all those field are in a group, then define a 
custom property with a getProp that calculates the concatenation of 
the values of all fields within the group.

   put the catFields of group Will Robinson into ...

Am I getting closer?

Dar Scott

___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-03 Thread Dar Scott
On Wednesday, March 3, 2004, at 06:50 PM, hershrev wrote:

If you want to write a function that always returns you the latest:

function latestFields
  local myVar
  repeat with i=1 to (the number of flds)
put fld i after myVar
  end repeat
  return myVar
What result will return myVar give, the fields names or contents of 
the fields ?
end latestFields
Contents

Dar Scott

___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-03 Thread hershrev
Yes , All hats up for you.
Just a question, why when I write ...
put function () into field x it doesn't replace the old contents of the 
field ?
Also to understand how does it work, when is this function activated ? 

On Wednesday, March 3, 2004, at 08:44 PM, Brian Yennie wrote:

Hershrev,

I'm not sure I understand what you mean by hard-code.
If you want a persistent way to reference a field, regardless of it's 
name, you can use the ID.
Or, to get all of the fields, something like:

repeat with i=1 to (the number of flds)
  put fld i after myVar
end repeat
If you want to write a function that always returns you the latest:

function latestFields
  local myVar
  repeat with i=1 to (the number of flds)
put fld i after myVar
  end repeat
  return myVar
end latestFields
Now to compare if I write
on mouseUp
  repeat with x=1 to the number of flds
put text of field x  return after y
  end repeat
 put y into fld 1
end mouseUp
what is the difference besides function or message, speed wise or 
something else ?
thanks , hershrev

HTH,
Brian
Now , how do you get  the contents of all the fields ?
if you put myVar into myQuery,  the result will be the field names 
and not the field content ? ( THE MAIN POINT IS TO GET THE LATEST 
DATA meaning if the user edits the field after the repeat script the 
result should be the updated contents as hard code)
if you come up with a recipe  for this I'll raise my hat for you.
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution
___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Hard code or portable code

2004-03-02 Thread Dar Scott
On Tuesday, March 2, 2004, at 08:21 PM, hershrev wrote:

is there a way to imitate hard code with some kind of container ?
Here are a couple of ideas:

1.  Use a list of names--

Create a list in a manner much like this:

repeat with x = 1 to the number of fields
   put (the name of field x)  LF after myVar
end repeat
Use it much like this (say to sum):

put 0 into fieldSum
repeat for each line f in myVar
  add field f to fieldSum
end repeat
OR

2.  Add a numerical subscript to fields of a particular type--

Say some fields are named count 1, count 2 and so on.

Create the count like this:

put 0 into numberOfCountFields
repeat with x = 1 to the number of fields
  if the name of field x starts with count  then
add 1 to numberOfCountFields
  end if
end repeat
(Or you can just type it into a custom property and use that, if the 
number is fixed.)

Use it like this:

put 0 into fieldSum
repeat with x = 1 to numberOfCountFields
  add field (count  x) to fieldSum
end repeat
3.
Or some other variation or combination...
Dar Scott





___
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution