Much of the code referred to here is the mcpher library. You can find out how to include it in your project here.
Just like VBA, Google Apps Script has an integrated development environment (IDE). Here's how to kick it off
One of the most common mistake js newbies make is to use = in place of ==.
In fact , since js allows assignments to take place inside a statement, then if (a=b) is perfectly legal. However the result will be not what you expect. Firstly b will be assigned to a, and if (a=b) will always be true for as long as b was non-zero or null. So if you are not careful, you will destroy the contents of a, and will make the wrong assumption about equality.
You can see the full list of operators here
a summary comparison against common VBA operators where they are different
+ & ( js uses + to join strings)
++ decrement by 1 (eg x++; is equivalent to x = x + 1)
-- increment by 1 (eg x--; is equivalent to x = x -1)
Arithmetic operators can also be combined with assignment =
+= (eg x += 20; is equivalent to x = x + 20)
-= (eg x-=20; is equivalent to x = x - 20)
*= (eg x*=20; is equivalent to x = x *20)
/= (eg x/=20; is equivalent to x = x /20)
You will sometimes see --x and x--. The mean almost the same thing , x=x-1, but the position of the -- is significant.
In case a. the result of --x is tested for non-zero i.e. after being decremented, but in case b, x is tested for non-zero before being decremented. In both cases, x is 0 after the if statement is executed.
I don't know if this is the name for this, but I call it conditional assignment. It's a favorite of old C programmers.
but this is so much more satisfying
we can combine multiple tests, as in this example
or use the result in an expression
Of course you dont have to use it- a series of ifs and elses will do the job, but isn't it so much more close to how you tackle the problem?
Iterating across a range of values.
VBA - the value of i after the loop in this case will be 10
In VBA, the starting array value is controlled by the setting for Option Base and the lbound and ubound functions are needed to discover the dimensions of an array,
var = new array(10);
For more like this see From VBA to Google Apps Script In the meantime why not join our forum,follow the blog or follow me on twitter to ensure you get updates when they are available.
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > From VBA to Google Apps Script >