SKITSANOS FOR RIA

Skitsanos

Saturday, March 13, 2010

Javascript: the new VBA

Source: Zef

Somewhere at the end of the eighties, my dad started work at his local university where he became the WordPerfect expert, which was the dominant word processor at the time. Beside acting as a helpdesk and laying out documents, he also spent a lot of time writing WordPerfect macros. WP’s macro language allowed you to add functionality and automate common tasks. All was well, until Microsoft came along with Microsoft Office.

It took Microsoft a long time to dominate the word processing market, but they managed to push WordPerfect practically out of the market with Word ‘97. My dad’s university also switched to Word around that release. Word uses a dialect of BASIC for writing macros: Visual Basic for Applications (VBA). He still does the majority of his programming work in VBA. To give you a flavor:

Public Function BusinessDayPrior(dt As Date) As Date
Select Case Weekday(dt, vbMonday)
Case 1
BusinessDayPrior = dt - 3
Case 7
BusinessDayPrior = dt - 2
Case Else
BusinessDayPrior = dt - 1
End Select
End Function
It is likely that within 10 years practically all word processing will be done in some sort of web application. Albeit in Google Docs or something else, and with this platform shift will also come another shift in macro language. Although it may not be surprising, it looks like that macro language is going to be Javascript.

Google has started introducing macro capabilities to its Google Docs offerings, calling it Google Apps Script, but if you look closely you will see it’s simply Javascript using a Google Docs API. The first application where Google Apps Script is introduced is in its spreadsheets, this is what it looks like:

function example() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var myValue = Browser.inputBox("Enter a number");
sheet.getRange("A1").setValue("Number entered:");
var b1Range = sheet.getRange("B1");
b1Range.setValue(myValue);
var valueToShow = b1Range.getValue() + 1;
Browser.msgBox("Answer: " + valueToShow);
}
Google’s Apps Script — I’m guessing they don’t like to abbreviate it to GAS — currently enables power users to define:
  • Custom spreadsheet functions
  • Custom menus in the spreadsheet application
  • Send e-mails
  • Read and manipulate spreadheets
  • Communicate with web services

Google took another step to become a serious Microsoft Office competitor. And my expectation is that more web applications will allow users to build macros in this fashion soon.

Another programming domain conquered by Javascript.

1 comment:

senocular said...

Given that google docs are in the web domain, that is no surprise. But this is also not entirely new - at least not for JavaScript. Adobe products (namely those Macromedia before Adobe acquired them) have had JavaScript APIs for extensibility as long as 10 or more years ago. And most of the suite products support some form of JavaScript-based extensibility.

I think more importantly, this shows how extensions are an important part of the application ecosystem. One of the reasons Firefox is as popular as it is, is because of its extensions and add-ons, something Chrome later realized it needed and added support for.

Webware development dedicated blog by Skitsanos R&D Labs. ASP.NET, XML, RIA, Adobe Flex, ActionScript 3, AIR, AJAX, Web 2.0, Backbase, CGI development with RealBasic and other web development issues.
News
Downloads