This VBA Programmer's Guide to Navigating the TCB describes access mechanisms for MicroStation's Terminal Control Block (the TCB). It attempts to answer questions that are posted occasionally to the MicroStation Programming Forum forums.

The terminology TCB has been traced by archaeologists to the days when minicomputers connected to graphic terminals by cable and were controlled by dedicated software. The TCB held the terminal settings. Why its use has persisted in MicroStation is a mystery.

Q It seems unfortunate that there are so many development languages, each with its own special syntax

A Languages are provided to suit different circumstances. Bear in mind that every computer language exists solely to distance the programmer from machine code: no-one wants to write in assembly code (if you do, please don't e-mail me). MicroStation Visual Basic for Applications (MVBA or simply VBA) in MicroStation V8 is a leap forward in capability when compared with the obsolescent MicroStation BASIC.

We've written a comparison of MicroStation development languages.

Q I'm in for a struggle with syntax. What is dot notation?

A Many languages, including VBA, have the concept of a user-defined-type (UDT). A UDT that you can't live without in MicroStation VBA is a Point3d.

Point3d is pre-defined in VBA …

Type Point3d
  x As Double
  y As Double
  z AS Double
End Type

In your code, you declare a Point3d like this …

Dim point As Point3d

You can read and write the X, Y, Z data members of a Point3d like this:

Dim length As Double, width As Double, height As Double
length = point.x
width = point.y
height = point.z

The dot notation illustrated here instructs the VBA interpreter to look inside the Point3d to get at its X, Y and Z data members. The dot notation is used in most programming languages these days. You'll encounter it in VB, C, C++, Java and Perl and, of course, MicroStation VBA.

Q I've seen postings about the TCB, which use arrow notation. My head hurts.

A Arrow notation (->) is a syntax used by C and C++. It's similar to dot notation, but if you want to know more then you should take a 'C' programming course. It's sufficient, for the purposes of navigating the TCB, to know that you should use the syntax tcb->xxx inside a C Expression to get at TCB member data.

Q Enough of this flim-flam: what about the TCB contents?

A The terminal control block (TCB) holds many of MicroStation's global settings. By global, I mean settings that belong to the design file rather than any individual model or element. An example is the active angle, available through the TCB member tcb->actangle. However, unlike BASIC, commonly-used components of the TCB are available through VBA calls. In the case of the active angle, it's available from the VBA ActiveSettings object …

Dim angle As Double
angle = ActiveSettings.Angle

Here's another example, which illustrates a difference from the BASIC way of things …

Dim masterUnitName As String
masterUnitName = ActiveModelReference.MasterUnit.Label

Here, ActiveModelReference.MasterUnit.Label is extracting the MasterUnit label from the active ModelReference. Since a DGN file may contain multiple models, the unit values and label are no longer part of the TCB. Instead, each model has its own units.

Since you're coding MicroStation VBA, you should know that the way units are expressed and labelled is quite different to MicroStation BASIC. With VBA, the ModelReference embeds its units in properties MasterUnit and SubUnit. The MasterUnit and SubUnit types each has a Label member. To get a model's master unit label with VBA you would write something like this …

Dim masterUnit As MeasurementUnit

masterUnit = ActiveModelReference.MasterUnit
Debug.Print "Master Unit label=" & masterUnit.Label

Q How do I get the Use Shared Cells setting?

A When placing a cell as a user, the Cells dialog provides a check-box option to use shared cells or normal cells. The TCB variable for this setting is tcb->ext_locks.sharedCells.

You can check the Use Shared Cells setting with VBA using this invocation …

' ---------------------------------------------------------------------
'   GetSharedCellSetting
'   Gets the state of the TCB variable tcb->ext_locks.sharedCells
'   Returns:    True if the Use Shared Cells toggle is checked
' ---------------------------------------------------------------------
Public Function GetSharedCellSetting() As Boolean
    GetSharedCellSetting = False
    Dim useSharedCells As Integer
    useSharedCells = GetCExpressionValue("tcb->ext_locks.sharedCells")
    If (useSharedCells <> 0) Then
        GetSharedCellSetting = True
        Debug.Print "Use Shared Cells=True"
    Else
        Debug.Print "Use Shared Cells=False"
    End If
End Function

Q How do I get the active Text Style settings?

A This information is available directly in VBA, from the design file's TextStyles collection. (with BASIC you had to use a C Expression).

Q Where can one find a list of TCB arguments?

A The TCB is formally documented as a 'C' header file in …\SDK\include\DgnPlatform\Tdb\tcb.r.h. This file is delivered when you install the MicroStation CONNECT SDK. It is a text file, so you can browse it with your favourite text editor (however, it doesn't make good bedtime reading). There is no friendly description or help file about the TCB. If you want to get at data not exposed by a ModelReference or Settings object, you must be prepared to dig deep. Alternatively, post a question to the BE Community forums.

Q What is a C expression?

A MicroStation includes an elegant engine called the C Expression Interpreter. This allows you to evaluate 'C' statements at run-time. You can see this in action with the Calculator MDL application (see MicroStation documentation). A simple C expression is 4 * 2 (the answer is eight).

With VBA you can use the GetCExpressionValue method …

Dim savePlaceArcMode
savePlaceArcMode = GetCExpressionValue( _
  "tcb->msToolSettings.igen.placeArcMode", "IGEN")

This VBA Programmer's Guide to Navigating the TCB is copyright (c) 2003…2025 Jon Summers. You may freely use and distribute at no cost the information here provided that you retain this copyright notice.