Questions similar to this appear on the Be Communities. This problem appeared in the MicroStation Programming Forum.
Q
A MicroStation text elements contain any type of text: letters, numbers or punctuation. By numeric text we mean those text elements that display numeric data, and only numeric data. For example, the following are considered, for the purpose of this article, to be numeric …
Examples of non-numeric text are …
This article describes a MicroStation VBA project SumNumericText.mvba
.
The project includes several modules …
Main
entry point in modMain
UserForm
named frmSumNumericText
Implements IPrimitiveCommandEvents
A MicroStation selection set contains those elements that a user has selected using one of the selection idioms. You can select elements within a rectangle you draw with the mouse, or add elements to a selection set using MicroStation's choose element tool.
This utility expects to find numeric text elements in a MicroStation selection set. If there is no selection set, then it does nothing. It considers only text elements and ignores other types of element. Optionally, you can include text node elements. Of the text elements it finds, it operates only on those that contain text considered to be numeric.
This utility works with numeric text elements.
For each numeric text element, it attempts to convert the text content to a number.
It accumulates the values found in each text element in the selection set.
It displays the total in the Sum Numeric Text UserForm
.
Load the SumNumericText.mvba
project from MicroStation's Utilities|Macros|Project Manager menu.
Open MicroStation's keyin window, and run the VBA macro using this keyin …
vba run [SumNumericText]modMain.Main
The Sum Numeric Text UserForm
appears …
There are three text boxes that show …
Initially all three text boxes show zero, as you would expect.
There is a check box labelled Include Text Nodes. Set the check if you want to include numeric text found in text node elements. Clear the check if you want to exclude text in text node elements.
This utility works with numeric text elements. The elements may be embedded in a text node element or they may be individual text elements.
SumNumericText gets each numeric text element in the selection set,
extracts its value, and accumulates the total.
It displays the total in the UserForm
.
In this example, the user has selected four text elements, having content 123, 456, 789 and abc. The user has also selected a text node element that contains three text elements having content 111, 222 and 333. You can see that the number of numeric text elements found is six (because abc is not numeric) and the calculated total is 2,034. The calculated average is 339.0.
Press the Place Total button to create a new text element in your DGN model.
The text element contains the same text as that shown in the Total box in the UserForm
.
Download
SumNumericText.ZIP
(which contains SumNumericText.mvba
) and run it by following these instructions …
SumNumericText.mvba
to one of the folders in your computer's VBA search path (MS_VBASEARCHDIRECTORIES
).C:\ProgramData\Bentley\Organization\Standards\Macros
is a good choice
vba run [SumNumericText].modMain.Main
You will see the Sum Numeric Text UserForm
.
Post questions about MicroStation programming to the MicroStation Programming Forum.