STAAD.Pro Help

OS. Visual Basic Conventions


In Visual Basic or Visual Basic for Applications, an apostrophe ( ‘ ) is used to denote a comment.  Anything to the right of the apostrophe will be ignored by the program.

Tip: Throughout this documentation, these are displayed in the color green to make comments visually distinct from the remaining code.

Declaring Arrays

VB/VBA is flexible in the way it allows arrays to be declared. Most examples involving arrays in this reference manual will conform to the C++ zero indexing convention. In an array of 6 values, the positions in the array are referred to as 0-5.  Therefore an array of 6 values would be declared as follows:

Dim pdArray(5) As Double


Dim pdArray(0 To 5) As Double

In VB, a six value array can also be declared as:

Dim pdArray(1 To 6) As Double

In doing so, however, we might find that our loops and other statements used to access the various positions in the array might not work correctly in C++.

Line Continuation Character

A long coding statement can be written on more than one line, to make the code easier to read.  The VB line continuation character consists of a space followed by an underscore at the end of the line.  The line of code beneath the continuation character will be handled as though it was written on the same line as the line continuation character.

Functions and Subroutines

Though functions and subroutines perform similar actions in any language, it is important to understand a key difference in order to make writing OpenSTAAD macros easier. A function can return a value back to the function or routine that called it. A subroutine, on the other hand, does not directly return a value. Instead, a subroutine must make use of the ByRef methodology internally. OpenSTAAD has been written so that you can use many of its functions to return more than one value via a single function. While this is a very powerful feature, it can lead to some confusion given how VB syntax uses parenthesis. In VB syntax, a subroutine does not use parenthesis to enclose any values which are passed to it. VB reserves their use for functions only.

Thus, in OpenSTAAD the subroutines which are used to return multiple values from the model input, analysis results, or design results are required to use the subroutine syntax.

Note: As this is a merely a result of VB syntax and not that these OpenSTAAD functions behave differently, the documentation simply refers them all as "functions."
Tip: Often, though, the data passed in such a function is in the form of an array, which do use parenthesis (without a space) to indicate their dimensions.


objOpenSTAAD.GetNodeDisplacements  nNodeNo, nLC, pdDisps(0)
'The line of code above may also be written as the line shown below:
objOpenSTAAD.GetNodeDisplacements _
nNodeNo, nLC, pdDisps(0)