Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Applications / Excel / May 2007



Tip: Looking for answers? Try searching our database.

How to convert a VBA class to Applescript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gimme_this_gimme_that@yahoo.com - 22 May 2007 20:22 GMT
Hi,

Does Applescript have a class construct mirroring the class construct
in VBA?

Suppose I have a module named MYDBC in VBA with this code:

Option Explicit

Dim propDatabase As String

Public Property Get Database() As String
  Database = propDatabase
End Property

Public Property Let Database(newDatabase As String)
  propDatabase = newDatabase
End Property

Then in VBA I can have

dim mDBC as MDBC
set mDBC = new MDBC()
mDBC.Database = "asdfa"

Is there an Applescript counterpart?

Thanks.
Dave Balderstone - 22 May 2007 20:29 GMT
> Hi,
>
[quoted text clipped - 24 lines]
>
> Thanks.

The current (April) issue of MacTech has a huge supplementary section
on moving from VBA to Applescript...
has - 23 May 2007 13:54 GMT
On 22 May, 20:22, "gimme_this_gimme_t...@yahoo.com"
<gimme_this_gimme_t...@yahoo.com> wrote:
> Hi,
>
> Does Applescript have a class construct mirroring the class construct
> in VBA?

AppleScript doesn't include a class type - instead it supports a form
of prototype-based OOP using its 'script' type. (Script objects can
also also used as modules, although AppleScript's built-in support for
module management is sorely lacking.)

Simple example:

on makeFoo(x)
    script Foo
        property y : 2

        on bar(z)
            return x + y + z
        end bar
    end script
end makeFoo

set f to makeFoo(30)

f's bar(10)
--> 42

(Note: you can also use AppleScript's built-in 'copy' command to clone
existing objects, but this has technical problems so should almost
always be avoided. Stick with constructor functions as shown above;
they work just fine.)

The AppleScript Language Guide has a chapter on script objects; it
doesn't really explain how to use them effectively, but if you already
know OOP you should be able to figure it out. (This is what I did.) Or
you could take a look at various AppleScript books and see if any of
those has a halfway decent discussion of the subject; Matt Neuburg's
'AppleScript: The Definitive Guide' might be your best bet as it's the
most technical-oriented one.

You could also check out the libraries at AppleMods (http://
applemods.sourceforge.net/) which I wrote a few years back. Several of
them provide examples of AppleScript OOP (the Types library is a good
simple one to start with).

...

Alternatively, if you'd rather stick with more familiar class-based
OOP, you might consider using Python or Ruby instead of AppleScript -
see my sig for links to suitable Apple event bridges.

The only caveat is that their OSA support - needed to attach scripts
to attachable applications (System Events' folder actions, Mail's rule
actions, iCal's alarms, etc.) - is currently a bit lacking, although
that's being worked on (see http://appscript.sourceforge.net/pyosa.html
for an unfinished but mostly usable Python component).

Also, here's a link to a recent article on rb-appscript that includes
an example of scripting Excel with it:
http://www.oreillynet.com/pub/a/mac/2007/02/27/replacing-applescript-with-ruby.html

HTH

has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
http://appscript.sourceforge.net/objc-appscript.html
gimme_this_gimme_that@yahoo.com - 29 May 2007 06:09 GMT
This was helpful.

Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.