Things to look out for
Many of them will have been covered in passing in other pages, but are work repeating.
UpperCamelCase and most everything else uses
lowerCamelCase, and my classes are defined as
cUpperCamelCase. Essentially the java standard, except with a lower case c in front of every class so that in VBA, it is clear it is a custom class. The exception is where I emulate built in VBA functions - I keep whatever the VBA case is, such as
LCase for example. This means my conversion is easy, but yours may not be. If you don't stick to something, you'll spend hours tracking down misspellings.
this in js is kindof like
DebugPrint (cItem , cIndex, this.someProperty);
At first, you would think that
this.someProperty is based on the same
this.forEach. However, since a function is an object, the second
this would look for someProperty of the function it is part of, and would fail (silently unfortunately, since the value returned would be null and perfectly acceptable).
var self = this;
DebugPrint (cItem , cIndex, self.someProperty);
To get over this kind of thing, I usually define a variable
self to contain the value of
this that refers to the instance of the object we are inside, otherwise I always get caught out. I guarantee that sooner or later you will be too. Even though I know about, I still do it today.
Methods or properties
VBA doesn't care much.
is the same as
is a function,
will not execute
, but rather copy the source code for
and transfer the return value of
. So you need to be very careful that you don't get your methods and properties mixed up. See Google Apps Conversion approach
for how I tackle this.
Range.getValues() in google apps script will return a two dimensional array the size of the Range, just like Range.Values does in Excel. But not always. If the specified range is outside the current dataRange() of the sheet, the returned array will not be the same size as the requesting range. This can really suck if you didn't know that.
For more like this, see From VBA to Google Apps Script
. Why not join our forum
,follow the blog
or follow me on twitter
to ensure you get updates when they are available. Much of the code referred to here is the mcpher library. You can find out how to include it in your project here