Archive for the “Concept” Category

One of the most useful methods for debugging VBA is Debug.Print, to see what variables contain or what a statement returns. JavaScript has a similar capability: console.log();. Read the rest of this entry »

Comments No Comments »

The most recent post in this series introduced the concept of loading properties from the Word object before being able to work with them. The line of code in question is range.load("text"); from the Basic API snippet for Script Lab. This article goes into that concept in more depth. Read the rest of this entry »

Comments No Comments »

My previous post on getting started with Script Lab and the Office JS APIs for Word looked at some similarities between the COM and Word JS API object models, based on the Script Lab Basic API call sample. This time, I’ll highlight the core part of the sample code that differs from working with COM/VBA. Read the rest of this entry »

Comments No Comments »

I hope you’ve had a chance to think about the code in the previous post for reading the value of a document property. This post will consider the problem of looping when async calls are involved, using that as the basis for the discussion. Read the rest of this entry »

Comments No Comments »

Besides writing to a specified place in a document, the other major thing an “App for Word” can do is communicate with Custom XML Parts. Mainly, I suppose the reason this was included in the original APIs is because Word can link a content control to a node in a Custom XML Part. Changing the content of either the content control or the node will mirror that change at the other end of the link. This capability is of interest for “data-mining” documents since it’s a fairly simple task to read a Custom XML Part from a closed Word document by leveraging the Office Open XML. Read the rest of this entry »

Comments No Comments »

As is often the case with code samples, error-handling is omitted for the sake of clarity and space. But serious code requires, of course, error handling, no matter which programming language is used.

VBA is old, comparatively speaking, and classic VB, upon which it was built, even older. We’re all familiar with On Error GoTo [label], On Error Resume Next and related commands.

More recent programming languages use a different pattern, generally known as “try…catch”. The .NET Framework languages use it (although VB.NET can still work with On Error) and it’s become a widely accepted standard. This is the basic pattern in synchronous JavaScript, as well. Read the rest of this entry »

Comments No Comments »

So, if JavaScript is so mutable, how can the developer be sure what an object actually has in the way of properties and methods? The language provides some properties that return useful information about an object. Read the rest of this entry »

Comments No Comments »

The previous post introduced Objects in JavaScript and showed two ways to declare and populate them. This entry provides more information about what can happen to objects that a VBA developer wouldn’t expect, as well as touch on the topic of variable scope. The reason for covering both in one place is the concern for minimizing unexpected problems and maintaining control of your code. Read the rest of this entry »

Comments No Comments »

Objects as a data type were introduced in a previous post. Now it’s time to look at them in more detail. Read the rest of this entry »

Comments 3 Comments »

Now that you have an idea of the basic JavaScript syntax it’s time to expand from code snippets to more complex subjects, starting with functions. This topic will extend over a number of posts as it’s not quite as simple as what we know from VBA… Read the rest of this entry »

Comments 1 Comment »

VBA provides useful functions for working with variables of the data types String, Number and (to a lesser extent) Boolean. For example, if you need information from a String you can use Len(), Left(), Mid() and Right() to determine the number of characters in the string, the characters counting from the beginning of the String, from any given position in the String or from the end (right) of the String, respectively.

JavaScript provides much of the same information, sometimes in the form of properties, sometimes in the form of methods (like VBA functions). The names are different from what we’re familiar with in VBA, but the functionality is all there, with some nice additions we’ve sometimes wished for! Read the rest of this entry »

Comments No Comments »

Data types determine what can be done with the content in a variable. For example, Numbers can be manipulated arithmetically; Boolean is used to test a variable’s state: does it or does it not meet a specified criterium.

Two of the data types used in VBA are also found in JavaScript and are used in the same way: String and Boolean.

JavaScript also supports the numerical data type, but in contrast to VBA and most other programming languages there’s only the one: Number. It’s not broken down into various integer and decimal types that exist primarily to limit memory storage requirements. So no need to worry about whether the value you’re assigning to a variable will be Integer or Long, Single or Double! JavaScript just goes whole hog and gives you 64-bit double precision floating point…

Then there are three data types not used in VBA: Read the rest of this entry »

Comments No Comments »