The DO Command

Joseph Martinez developer at positivepractices.com
Sat Apr 12 16:27:55 CDT 2008


Thanks for the response.  I should probably explain further.  I would, of
course, just use explicit Revolution statements where applicable, but in the
cases where user variables or params are unforeseen I might use the "do"
command, such as in the following (not fully tested) example:

On theDate
  Ask "What date?" with "abbr system"
  Put theDate(it)
End theDate

function theDate p1
  put "Abbreviated,Abbr,Long,Short,Internet,English,System" into t1
  put "Internet,English,System" into t2
  put word 1 of p1 into t1a
  put word 2 of p1 into t2a
  if t1a is among the items of t1 and ((t2a is among the items of t2) OR
(t2a is empty)) then
    if t1a is not in t2a and t1a is not among the items of t2 then -- e.g.
internet internet
      put "put the" && t1a && t2a && "date into theDate" into tCmd
      replace space & space with empty in tCmd -- in case t2a is empty
    else
      put "put the" && t1a && "date into theDate" into tCmd
    end if
  end if
    If tCmd is empty then return the date
  do tCmd
  Return theDate
End theDate

I know I could use more explicit switch or if-then routines, but for me the
above method is a little more fun and efficient.  I also use some more
complex integrated handlers that do other things.  So, my understanding now
is that this will work on all platforms because the tCmd translates into
Revolution code.

As for MacOS Classic:

> As to MacOS (classic) support, you can tell what's supported in the
> different platforms by clicking on the Documentation button in the toolbar
> and then clicking "Dictionary" in the documentation window's toolbar.
> There's a column there that is "Platforms", and anything that doesn't work
> on OS 9 will not have the blue "face" OS 9 icon. However 90+% of Rev code
> works on OS 9 as well.

Since there is not the "blue face" OS 9 icon in the Dictionary (Rev Version
2.9) for the "do" command.  Would I have to do something like:

If the platform is MacOS and char 1 to 2 of the systemversion > 9 then do
tCmd

-- or --

Do tCmd as applescript

? Or, would the handler-function combo work on Classic because it is
compiled as Rev code?

Thanks again,  Joseph


On 4/12/08 12:48 PM, "Ken Ray" <kray at sonsothunder.com> wrote:


> On 4/12/08 1:57 PM, "Joseph Martinez" <developer at positivepractices.com>
> wrote:
> 
>> To save considerable development time, I make extensive use of the "do"
>> command for creating of an app intended eventually for cross-platform
>> distribution.  Is this asking for trouble?
>> 
>> I only use "do" with one-line type handlers, such as
>> 
>> Put "put doublespace(fld" && x & ") into fld" && x into tCmd
>> Do tCmd
> 
> Well actually there shouldn't be a need for "do" in this instance; is there
> some reason you can't write:
> 
> put doublespace(fld x) into fld x
> 
> ?
> 
> In most cases you'll find that "do" is rarely needed; Rev's code is
> inherently cross-platform without any need for "do". I think you may be
> confusing the "alternateLanguageName" used with "do" with the deployment on
> different platforms, so let me clear this up for you if that's the case:
> 
> The "alternateLanguageName" is used by the "do" function to determine how to
> *interpret* the text that's being "done". So you can "do" something as
> "AppleScript" (if the text that is being "done" is in AppleScript), and in
> Rev 2.9 you can "do" something as "VBScript", and if you have the proper
> plugin, you can even "do" something as "JavaScript".
> 
> If you don't specify an 'alternateLanguageName', Rev will assume that the
> text to be "done" is in proper Transcript (Revolution's native code).
> 
> Examples (I usually put the script to be done into a variable before "doing"
> it):
> 
> do "put the text of field 1 into field 2"  -- native Transcript (although
> you wouldn't use it this way (see below))
> 
> put "display dialog" && quote & "Hello" & quote into tScript
> do tScript as "AppleScript"
> -- if you tried to run the above without the "as AppleScript" you'd get an
> error)
> 
> put "Set App=Wscript.CreateObject(" & quote & "Wscript.Shell" & \
>   quote & ")" & CR & "App.Run" && quote & \
>   "C:\Windows\Explorer.exe /root,C:\" & quote & ", 1, False" into tScript
> do tScript as "VBScript"
> 
> As far as different computer platforms are concerned, 99% of Revolution's
> code is naturally cross-platform and doesn't have to be adjusted. Some
> exceptions that are platform specific are: AppleScript (Mac only) and
> Registry manipulation (Windows only). There are others, but you get the
> drift.
> 
> When writing cross platform apps, you may need to occasionally do an
> "if-then" or "switch-case" if you're trying to do something that works
> differently on different platforms. So for example, if you want to store
> preferences; on Windows you may want to use the Registry, but on Mac you
> would want to store files in the proper Preferences folder.
> 
> As to MacOS (classic) support, you can tell what's supported in the
> different platforms by clicking on the Documentation button in the toolbar
> and then clicking "Dictionary" in the documentation window's toolbar.
> There's a column there that is "Platforms", and anything that doesn't work
> on OS 9 will not have the blue "face" OS 9 icon. However 90+% of Rev code
> works on OS 9 as well.
> 
> Hope this helps,
> 
> Ken Ray
> Sons of Thunder Software, Inc.
> Email: kray at sonsothunder.com
> Web Site: http://www.sonsothunder.com/
> 
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
> 




More information about the use-livecode mailing list