VBA->JS: console.log = Debug.Print
July 11, 2018One 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();.
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();.
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.
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.
If you’re curious about the Office JS API application object models and want to get acquainted you can do so without any investment other than time. All you need is a Microsoft account and Office 365 / Office 2016 installed on your machine (Windows or Mac) or access to Office Online. Then you can install […]
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.
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 […]
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 […]
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.
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 […]
Objects as a data type were introduced in a previous post. Now it’s time to look at them in more detail.
In this last post on conditionals and loops I’ll present Arrays and how to loop using the last kind not yet discussed: “For Each”.
In the third part of working with conditionals we’re going to look at some looping operations. Again, the concept is the same as what’s used in VBA, just different syntax.
Now that you’ve familiarized yourself with the logical operators JavaScript uses it’s time to look at the basic conditional constructs. Looping constructs are the topic of the next post.
An important part of most programs we write is testing the values of variables and performing tasks based on the result. Typical VBA constructs that use comparisons are If, For, ForEach and Do…While. JavaScript provides the same functionality, using pretty much the same logic, but the syntax differs. Before we look at these in the […]
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, […]
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 […]
Due to an injury to my horse, I’m spending a lot of time at the stable. It’s much more economic to sit there for a couple of hours rather than drive back-and-forth. To make the most of my time, I try to do some work – learning more about JavaScript – while I’m there. Since […]
Up until now, you’ve had to take my word that JavaScript behaves the way I describe. That’s fine, for an article or two, but at some point a developer wants to actually try these things out… Unlike VB6, VB.NET or C# you can’t create an independent program using JavaScript, by itself. Similarly to VBA it […]
When working in VBA it doesn’t matter, for the most part, whether you type capital or small letters. VBA will monitor and compare with its internal list of keywords as well as variables you’ve declared and make corrections as you go. If there are variables that aren’t declared there are no automatic corrections, but VBA […]
The VB languages differentiate between concatenating (“adding”) strings and adding numbers. You’re supposed to use an ampersand (&) to concatenate a string and a plus sign (+) to add numbers. Although VBA will accept a plus sign to concatenate strings it’s frowned on as you can get unexpected results. JavaScript (like C#) must use the […]
Commenting code is important. JavaScript and C# use the same commenting conventions, which differ somewhat from VBA’s. Comments can be on a single line, similar to VBA; they can also extend across multiple lines:
In both VBA and JavaScript, as with most programming languages, those things with which code works are held in “variables”. Both VBA and JavaScript declare variables and assign values to them. Comparing how they do it: