Basic Help Microstation

139
7/25/2019 Basic Help Microstation http://slidepdf.com/reader/full/basic-help-microstation 1/139 A to Z Reference This section contains a complete, alphabetical reference to all commands in the standard BASIC language. When syntax is described, the following notations are used: & string_expression1 & string_expression2 Descr. Returns the concatenation of string_expression1  and string_expression2 . Adds string_expression2  to the end of string_expression1  and returns a string with a length that is the sum of the lengths of string_expression1  and string_expression2 . This operator can be used interchangeably with the plus (+) operator when used with string operands and is provided for clarity of code. Example: Sub Main() 'Assign a concatenated string to variable s$ and a string to s2$, 'then concatenate the two variables and display in a dialog box. s$ = "This string" & " is concatenated" s2$ = " with the & operator" MbeMessageBox s$ & s2$ End Sub Notation Description keyword Elements belonging to the standard BASIC language, referred to in this manual as keywords, appear in the typeface shown to the left. variable Items that are to be replaced with information that you supply appear in italics. The type of replacement is indicated in the following description. text$ The presence of a type-declaration character following a parameter signifies that the parameter must be a variable of that type or an expression that evaluates to that type. rnd# A function's return type is indicated by a type-declaration character. This is strictly informative and does not mean that the function must be accompanied by that type-declaration character. Functions that return strings are an exception to this rule. In their case, the $ character is required. [parameter%] Square brackets indicate that the enclosed items are optional. {Input | Binary} Braces indicate that you must choose one of the enclosed items, which are separated by a vertical bar. start% To end% Words that must appear as part of a statement's syntax are shown without type- declaration characters (for example, To). Page 1 of 139 A to Z Reference 12/18/2006 file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Transcript of Basic Help Microstation

Page 1: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 1/139

A to Z Reference

This section contains a complete, alphabetical reference to all commands in the standard BASIClanguage. When syntax is described, the following notations are used:

&

string_expression1 & string_expression2

Descr. Returns the concatenation of string_expression1 and string_expression2.

Adds string_expression2 to the end of string_expression1 and returns a string with a length that isthe sum of the lengths of string_expression1 and string_expression2. This operator can be usedinterchangeably with the plus (+) operator when used with string operands and is provided for clarityof code.

Example:

Sub Main()

'Assign a concatenated string to variable s$ and a string to s2$,'then concatenate the two variables and display in a dialog box.

s$ = "This string" & " is concatenated"s2$ = " with the & operator"MbeMessageBox s$ & s2$

End Sub

Notation Description

keywordElements belonging to the standard BASIC language, referred to in this manual askeywords, appear in the typeface shown to the left.

variableItems that are to be replaced with information that you supply appear in italics.The type of replacement is indicated in the following description.

text$The presence of a type-declaration character following a parameter signifies thatthe parameter must be a variable of that type or an expression that evaluates tothat type.

rnd#

A function's return type is indicated by a type-declaration character. This isstrictly informative and does not mean that the function must be accompanied bythat type-declaration character.Functions that return strings are an exception to this rule. In their case, the $character is required.

[parameter%] Square brackets indicate that the enclosed items are optional.

{Input |Binary}

Braces indicate that you must choose one of the enclosed items, which areseparated by a vertical bar.

start% Toend% Words that must appear as part of a statement's syntax are shown without type-declaration characters (for example, To).

Page 1 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 2: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 2/139

'

'text

Descr. Causes the compiler to skip all characters between this character and the end of the currentline. This is very useful for commenting your code to make it more readable.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This whole line is treated as a comment.i$ = "Strings" 'This is a valid assignment with a comment.This line will cause an error (the apostrophe is missing).

End Sub

*

expression1 * expression2

Descr. Returns the product of expression1 and expression2. The operands can be expressions of anynumeric data type.

Example:

Sub Main()

'This example assigns values to two variables and their product to'a third variable, then displays the product of S * T.S# = 123.55T# = 2.55U# = S * TMbeMessageBox Str$(S * T)

End Sub

+

expression1 + expression2

Descr. If expression1 and expression2 are both numeric, then this operator returns the sum ofexpression1 and expression2. If both expressions are strings, then this operator returns a new stringrepresenting the concatenation of expression1 and expression2. Mixed string and numeric operandsare invalid. For string operands, the plus (+) is interchangeable with the & operator. (See & [operator].)

Example:

Sub Main()

Page 2 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 3: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 3/139

  'This example assigns string and numeric variable values and'then uses the + operator to concatenate the strings and form the'sums of numeric variables.i$ = "Strings" + " can be concatenated"j% = 120 + 5 'addition of numeric literalsk# = j% + 2.7 'addition of numeric variableMbeMessageBox i$ + Str$(j%) + Str$(k#)

End Sub

-

expression1 - expression2

Descr. Returns the difference between expression1 and expression2.

Example:

Sub Main()

'This example assigns values to two numeric variables and their'difference to a third variable, then displays the result.I% = 100J# = 22.55K# = I - JMbeMessageBox "The difference is: " + Str$(K#)

End Sub

/

expression1 / expression2

Descr. Returns the quotient of expression1 and expression2.

Example:

Sub Main()

'This example assigns values to two variables and their quotient to a'third variable, then displays the result.I% = 100J# = 22.55K# = I / JMbeMessageBox "The quotient of I/J is: " + Str$(K#)

End Sub

<

expression1 < expression2

Descr. Returns TRUE if expression1 is less than expression2; otherwise, returns FALSE. If both

Page 3 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 4: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 4/139

expressions are strings, the < operator performs a case-sensitive comparison between the two stringexpressions, returning TRUE if expression1 is less than expression2.

Lowercase characters in a string sort higher than uppercase characters, so a comparison of `a' and`A' would indicate that `A' is less than `a'.

Example:

Sub Main()

'Test two literals and display the result.If 5 < 2 Then

MbeMessageBox "Five is less than Two"Else

MbeMessageBox "Five is not less than Two"End If'Test two strings and display the result.If "This string expression" < "That string" Then

MbeMessageBox "This is less than That"

ElseMbeMessageBox "That is less than This"

End IfEnd Sub

<=

expression1 <= expression2

Descr. Returns TRUE if expression1 is less than or equal to expression2; otherwise, returns FALSE. If both expressions are strings, the <= operator performs a case-sensitive comparison between the twoexpressions, returning TRUE if expression1 is less than or equal to expression2.

Lowercase characters in a string sort higher than uppercase characters, so a comparison of `a' and`A' would indicate that `A' is less than `a'.

Example:

Sub Main()

'Test two literals and display the result.If 5 <= 2 ThenMbeMessageBox "Five is less than or equal to Two"

ElseMbeMessageBox "Five is not less than or equal to Two"

End If'Test two strings and display the result.If "This string" <= "That string" Then

MbeMessageBox "This is less than or equal to That"Else

MbeMessageBox "That is less than or equal to This"End If

End Sub

<>

Page 4 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 5: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 5/139

 expression1 <> expression2

Descr. Returns TRUE if expression1 is not equal to expression2; otherwise returns FALSE. If the twoexpressions are strings, the <> operator performs a case-sensitive comparison between the twoexpressions, returning TRUE if expression1 is not equal to expression2.

Lowercase characters in a string sort higher than uppercase characters, so a comparison of `a' and`A' would indicate that `A' is less than `a'.

Example:

Sub Main()

'Test two literals and display the result.If 5 <> 2 Then

MbeMessageBox "Five is not equal to Two"

ElseMbeMessageBox "Five is equal to Two"End If'Test two strings and display the result.If "This string" <> "That string" Then

MbeMessageBox "This is not equal to That"Else

MbeMessageBox "The strings are equal"End If

End Sub

=

expression1 = expression2

Descr. Returns TRUE if expression1 is equal to expression2; otherwise returns FALSE. If the twoexpressions are strings, the = operator performs a case-sensitive comparison between the twoexpressions, returning TRUE if expression1 is equal to expression2. Strings of different lengths arenever equal to one another.

This operator is also used for assignment of values to variables. It operates as a logical equivalency

operator only in a logical comparison context.

Example:

Sub Main()

'Assignment of values: the variable S is assigned a value of 100.22.S# = 100.22'Logical equivalence: the value of S is compared to 150.99.If S = 150.99 Then

MbeMessageBox "The value of S is 150.99"Else

MbeMessageBox "The value of S is not 150.99"End IfEnd Sub

Page 5 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 6: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 6/139

>

expression1 > expression2

Descr. Returns TRUE if expression1 is greater than expression2; otherwise returns FALSE. If the twoexpressions are strings, the > operator performs a case-sensitive comparison between the twoexpressions, returning TRUE if expression1 is greater than expression2.

Example:

Sub Main()

'Test two literals and display the result.If 5 > 2 Then

MbeMessageBox "Five is greater than Two"Else

MbeMessageBox "Five is less than or equal to Two"End If'Test two strings and display the result.If "This string" > "That string" Then

MbeMessageBox "This is greater than That"Else

MbeMessageBox "That is less than or equal to This"End If

End Sub

>=

expression1 >= expression2

Descr. Returns TRUE if expression1 is greater than or equal to expression2; otherwise returns FALSE.If the two expressions are strings, the >= operator performs a case-sensitive comparison between thetwo expressions, returning TRUE if expression1 is greater than or equal to expression2.

Example:

Sub Main()

'Test two literals and display the result.If 5 >= 2 Then

MbeMessageBox "Five is greater than or equal to Two"Else

MbeMessageBox "Five is less than Two"End If'Test two strings and display the result.If "This string" >= "That string" Then

MbeMessageBox "This is greater than or equal to That"Else

MbeMessageBox "That is less than This"End If

End Sub

\

Page 6 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 7: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 7/139

 expression1 \ expression2

Descr. Returns the integer division of expression1 and expression2.

This operator operates by rounding expression1 and expression2 prior to division. The integer part ofthe result is then returned as a nonfractional number.

Example:

Sub Main()

'Assign the quotient of two literals to a variable and display the'result.s% = 100.99 \ 2.6MbeMessageBox "Integer divide of 100.99 \ 2.6 is: " & Str$(s)

End Sub

^

expression1 ^ expression2

Descr. Returns expression1 raised to the power specified in expression2. Fractional and negativeexponents are allowed.

The following are special cases:

It is important to note that raising a number to a negative exponent produces a fractional result(either a Double or a Single). In the statement a% = b%^c%, the variables b and c are first promotedto Doubles, then the power operation is applied, and finally the result converted to an Integer (rounding, if necessary) and stored in a.

Example:

Sub Main()

s# = 2 ^ 5 'Returns 2 to the 5th power.r# = 16 ^ .5 'Returns the square root of 16.MbeMessageBox "Two to the 5th power is: " & Str$(s)

End Sub

Special Case Value

n^0 1

0^-n undefined

0^+n 0

1^n 1

Page 7 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 8: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 8/139

 s$ = "This is a very long line that I want to split " + _"onto two lines"

Descr. The `_' character is the line-continuation character.

This character allows you to split a single BASIC statement onto more than one line.

The line-continuation character cannot be used within strings and must be preceded by white space(either a space or a tab).

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'The line-continuation operator is useful when concatenating long

'strings.Msg$ = "This line is a line of text that" + crlf + "extends beyond " _+ "borders of the editor" + crlf + "so it is split into " _+ "multiple lines"

'It is also useful for separating and continuing long calculation'lines:b# = .124a# = .223S# = ( (((Sin(b) ^ 2) + (Cos(a) ^ 2)) ^ .5) / _

(((Sin(a) ^ 2) + (Cos(b) ^ 2)) ^ .5) ) * 2.00MbeMessageBox Msg + crlf + "The value of S is: " + Str$(S)

End Sub

Abs

Abs%(number%)Abs&(number&)Abs!(number!)Abs#(number#)

Descr. Returns the absolute value of a given number.

When Integer variables are assigned the absolute value of real numbers, the real number is roundedfirst, and the absolute value of the rounded number is returned.

Example:

Sub Main()

'Assign absolute values to variables of 4 types and display the result.S1% = Abs(- 10.55)S2& = Abs(- 10.55)S3! = Abs(- 10.55)S4# = Abs(- 10.55)

MbeMessageBox Str$(S1) + Str$(S2) + Str$(S3) + Str$(S4)End Sub

Page 8 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 9: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 9/139

And

expression1 And expression2 

Descr. Returns TRUE if both expression1 and expression2 are TRUE. If either expression is FALSE,then the And operator returns FALSE.

If the two expressions are numeric, then the result is the bitwise And of the two arguments.

If either of the two operands is a floating-point number, then the two operands are first converted toLongs, then a bitwise And is performed.

Example:

Sub Main()

N1 = 1001N2 = 1000B1 = TrueB2 = False'Perform a numeric bitwise And operation and store the result in N3.N3 = N1 And N2'Perform a logical And comparing B1 and B2 and display the result.If B1 And B2 Then

MbeMessageBox "B1 and B2 is True; N3 is: " + Str$(N3)Else

MbeMessageBox "B1 and B2 is False; N3 is: " + Str$(N3)End If

End Sub

ArrayDims

ArrayDims%(arrayvariable)

Descr. Returns the number of dimensions of a given array.

This function can be used to determine whether a given array contains any elements if the array isinitially dimensioned with null dimensions and then redimensioned by another function, such as theFileList function, as shown in the following example.

Example:

Sub Main()

'Allocate an empty (null-dimensioned)'array; fill the array with a list of'filenames, which resizes the array; then test the array dimension and'display an appropriate message.

Dim f$()FileList f$,"C:\*.BAT"If ArrayDims(f$) = 0 Then

MbeMessageBox "The array is empty"

Page 9 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 10: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 10/139

  ElseMbeMessageBox "The array size is: " + Str$(ArrayDims(F$))

End IfEnd Sub

ArraySort

ArraySort s$()ArraySort a%()ArraySort a&()ArraySort a!()ArraySort a#()

Descr. Sorts a single-dimensioned array. If a string array is specified, then the routine sortsalphabetically in ascending order (using case-sensitive string comparisons). If a numeric array isspecified, the ArraySort statement sorts smaller numbers to the lowest array index locations.

A run-time error is generated if you specify an array with more than one dimension.

Example:

Sub Main()

'Dimension an array and fill it with filenames using FileList,'then sort the array and display it.Dim F$()FileList f$,"C:\*.*"ArraySort f$

result = MbeSelectBox% ("Choose a file", f$)End Sub

Asc

Asc%(text$)

Descr. Returns the numeric code for the first character of the given string.

The return value is an Integer between 0 and 255.

Example:

Sub Main()

s$ = "ABC"Dim a%(3)'Fill the array with the ASCII values of the string s components and'display the result.For i = 1 To 3

a%(i) = Asc(Mid$(s$,i,1))

Next iMbeMessageBox Str$(a%(1)) + Str$(a%(2)) + Str$(a%(3))End Sub

Page 10 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 11: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 11/139

Atn

atn#(number#)

Descr. Returns the angle (in radians) whose tangent is number.

Pi (3.1415926536) radians = 180 degrees.

One radian = 57.2957795131 degrees.

One degree = .0174532925 radians.

Example:

Sub Main()

'Find the angle whose tangent is 1 (45 degrees) and display the result.a# = Atn(1.00)MbeMessageBox "1.00 is the tangent of " + Str$(a#) +" radians (45 degrees)"

End Sub

Basic.Capability%

Basic.Capability%(which%)

Descr. This method returns TRUE if the specified capability exists on the host operating environment;otherwise, this function returns FALSE.

The which parameter specifies which capability to test for. It can be any of the following values:

Example:

Sub Main()

'Test to see whether your current environment supports disk drives and'hidden file attributes and display the result.Msg$ = "This OS "

Value Returns TRUE if the platform supports

1 Disk drives

2 System file attribute (ebSystem)

3 Hidden file attribute (ebHidden)

4 Volume label file attribute (ebVolume)

5 Archive file attribute (ebArchive)

6 Denormalized floating-point math

Page 11 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 12: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 12/139

  If Basic.Capability(1) ThenMsg = Msg + "supports disk drives."

elseMsg = Msg + "does not support disk drives."

End IfMbeMessageBox Msg

End Sub

Basic.Eoln$

Basic.Eoln$

Descr. Returns a string containing the end-of-line character sequence appropriate to the hostoperating environment.

This string will be either a carriage-return, a carriage-return line-feed, or a line-feed.

Example:

Sub Main()

'This example writes two lines of text in a message box.MbeMessageBox "This is the first line of text " + Basic.Eoln$ + _"The second line"

End Sub

Basic.FreeMemory

Basic.FreeMemory&

Descr. Returns the number of bytes of free memory in BASIC's data space.

This function returns the size of the largest free block in BASIC's data space. Before this number isreturned, the data space is compacted, consolidating free space into a single contiguous free block.

BASIC's data space contains strings and dynamic arrays.

Example:

Sub Main()

'Display free memory in a dialog box.MbeMessageBox "The free memory space is: " + Str$(Basic.FreeMemory)

End Sub

Basic.OS

Basic.OS

Page 12 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 13: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 13/139

Descr. Returns a number indicating the host operating environment.

Example:

Sub Main()

'Determine the OS this version was created for and display the'appropriate message.o% = Basic.OSSelect Case o%

Case 2S$ = "Win32"

Case 12S$ = "DOS"

Case ElseS$ = "Neither Win32 nor DOS"

End SelectMbeMessageBox "The current version was created for " + S$

End Sub

Basic.PathSeparator$

Basic.PathSeparator$ 

Descr. Returns a string containing the path separator appropriate for the host operating environment.

The returned string will be a slash `/', a backslash `\', or a colon `:'.

Example:

Sub Main()

MbeMessageBox "The path separator for this environment is: " + _Basic.PathSeparator$

End Sub

Value Constant Platform

2 ebWin32 Microsoft Win32 ('95, NT, Win32s)

3 ebSolaris Sun Solaris 2.x

4 ebSunOS SunOS

5 ebHPUX HP/UX

7 ebIrix Silicon Graphics IRIX

8 ebAIX IBM AIX

10 ebMacintosh Apple Macintosh

12 ebDOS32 MS-DOS

13 ebClix Intergraph Clix

Page 13 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 14: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 14/139

Beep

Beep

Descr. Makes a single system beep.

Example:

Sub Main()

'Beep five times and display a reminder message.For i = 1 To 5

BeepSleep(500)

Next iMbeMessageBox "Do you have an upcoming appointment?"

End Sub

Call

Call subroutine_name [(arguments)]

Descr. Transfers control to the given subroutine, optionally passing the specified arguments.

Using this statement is equivalent to:

subroutine_name [arguments]

Use of the Call statement is optional. The subroutine to which control is transferred by Call must bedeclared outside of the Main procedure, as shown in the following example.

Example:

Sub Example_Call (S$)

'This subroutine is declared externally to Main and displays the text

'passed in the parameter S$.MbeMessageBox "Example CALL: " + S$End SubSub Main()

'Assign a string variable to display, then call subroutine'Example_Call, passing parameter S$ to be displayed in a'message box within the subroutine.S$ = "Display this text"Example_Call "Display this text"Call Example_Call ("Second form of Call statement")

End Sub

CDbl

Page 14 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 15: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 15/139

 CDbl#(number#)

Descr. Returns the double-precision equivalent of the passed numeric expression (number).

This function has the same effect as assigning the numeric expression number to a double-precisionvariable.

Example:

Sub Main()

i% = 100j! = 123.44MbeMessageBox Str$(CDbl(i * j))MbeMessageBox Str$(CDbl(i) * j)MbeMessageBox Str$(CDbl(i) * CDbl(j))

End Sub

Chr$

Chr$(Code%)

Descr. Returns the character whose value is Code.

Code must be an integer between 0 and 255. In addition, Code cannot be an expression.

The Chr$ function can be used within constant declarations, as in the following example:

Example:

Const crlf$ = Chr$(13) + Chr$(10)

Sub Main()'Concatenate carriage return (13) and line feed (10) to clf$,'then display a multiple-line message using clf$ to separate lines.CLF$ = Chr$(13) + Chr$(10)MbeMessageBox ("First line" + CLF + "Second line")'Fill an array with the ASCII characters for ABC and display their'corresponding characters.

Dim a%(3)For i = 1 To 3a%(i) = (64 + i)

Next iMbeMessageBox Chr$(a(1)) + Chr$(a(2)) + Chr$(a(3))

End Sub

CInt

CInt%(number#)

Descr. Returns the integer portion of the given expression.

Page 15 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 16: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 16/139

The passed numeric expression must be within the following range:

-32768 <= number <= 32767

A run-time error results if the passed expression is not within the above range.

CInt has the same effect as assigning a numeric expression to a variable of type Integer. CInt differs from the Fix and Int functions in that CInt rounds instead of truncating.

Example:

Sub Main()

'This example demonstrates the various results of integer manipulation'with CInt.'(1) Assign i to 100.55 and display its integer representation (101).i# = 100.55MbeMessageBox "CInt I = " + Str$(CInt(I))'(2) Set J to 100.22 and display the CInt representation (100).j# = 100.22MbeMessageBox "CInt J = " + Str$(CInt(J))'(3) Assign K (integer) to the CInt sum of I and J and display K (201).k% = CInt(I + J)MbeMessageBox("The integer sum of 100.55 and 100.22 is: " + Str$(k))'(4) Reassign i to 50.35 and recalculate K, then display'(note rounding).i# = 50.35k% = CInt(I + J)MbeMessageBox("The integer sum of 50.35 and 100.22 is: " + Str$(k))

End Sub

CLng

CLng&(number#)

Descr. Returns a Long representing the result of the given numeric expression.

The passed numeric expression must be within the following range:

-2147483648 <= number <= 2147483647

A run-time error results if the passed expression is not within the above range.

CLng has the same effect as assigning a numeric expression to a Long variable.

Example:

Sub Main()

i% = 100j& = 123.666

'Display results for various conversions of i and j (note rounding).MbeMessageBox Str$(CLng(i * j)) 'Displays 12367.MbeMessageBox Str$(CLng(i) * j) 'Displays 12366.MbeMessageBox Str$(CLng(i) * CLng(j)) 'Displays 12400.

Page 16 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 17: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 17/139

 End Sub

Close

Close [[#] filenumber% [,[#] filenumber%]]

Descr. If no arguments are specified, this statement closes all files. Otherwise, the Close statementcloses each specified file.

Example:

Sub Main()

'Open four files and close them in various combinations.Open "Test1" for Input Access Read Lock Read Write as #1 len=128Open "Test2" for Output as #2

Open "Test3" for Random as #3Open "Test4" for Binary as #4Close #1 'Closes file 1 only.Close #2, #3 'Closes files 2 and 3.Close 'Closes all remaining files (4).

End Sub

Command$

Command$

Descr. Returns a string representing the argument from the command line used to start the macro.

Example:

Sub Main()

'Get the command line and parameters, check to see whether the string' "/s" is present, and display the result.CMD$ = Command$If (InStr(Cmd,"/s")) <> 0 Then

MbeMessageBox "Macro started with /s switch"ElseMbeMessageBox "Macro started without /s switch"

End IfMbeMessageBox "Startup line was: " + CMD$

End Sub

Const

const name = expression [,name = expression]...

Descr. Declares a constant for use within the current macro.

Page 17 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 18: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 18/139

name is only valid within the current BASIC macro.

expression must be assembled from literals or other constants. Calls to functions are not allowedexcept calls to the Chr$ function when used in the declarations part of the code or outside the SubMain...End Sub.

- The constants are declared before the Sub Main declaration.

Example:

Const CRLF = Chr$(13) + Chr$(10)

Const T$ = "This is a constant"Sub Main()

'Display the declared constants in a dialog box (CRLF produces a new'line in the dialog box).MbeMessageBox T + CRLF + "The constants are shown above"

End Sub

Cos

Cos#(angle#)

Descr. Returns the cosine of a given angle.

The angle parameter is given in radians.

Example:

Sub Main()

'Assign the cosine of PI/4 radians (45 degrees) to C# and display its'value.C# = Cos(3.14159 / 4)MbeMessageBox "The cosine of 45 degrees is: " + Str$(C)

End Sub

CSng

CSng!(number#)

Descr. Returns a single representing the result of the given numeric expression number.

This function has the same effect as assigning a numeric expression to a single variable.

Example:

Sub Main()

Page 18 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 19: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 19/139

  'Assign variables of different types and display their CSng'conversions.S1# = CSng(150.61010101)S2& = CSng(150.62020202)S3% = CSng(150.63030303)S4! = CSng(150.64040404)MbeMessageBox Str$(S1) + Str$(S2) + Str$(S3) + Str$(S4)

End Sub

CStr

CStr(number#)

Descr. Returns a string representing the result of the given expression. The result is returned infloating point `E' notation, if the result is very small or very large. Unlike Str$, the string returned byCStr will not contain a leading space if the expression is positive.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'Assign two variables and display them using CStr conversions.A# = 123.456B# = -123.456MbeMessageBox CStr(A) + crlf + CStr(B)

End Sub

Date$

Date$[()]Date$ = newdate$

Descr. The Date$ function returns the current system date as a 10-character string. The statementform of Date$ sets the system date to the specified date.

The format for the date used by Date$ is MM-DD-YYYY.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()' This example saves the current date to Cdate$, then changes` the date and displays the result. It then changes the date back' to the saved date and displays the result.Cdate$ = Date$()Date$ = "01/01/94"MbeMessageBox("Saved date is: " + Cdate + crlf + "Changed date is: " + _

Date$())Date$ = CdateMbeMessageBox("Restored date to: " + Cdate)

End Sub

Page 19 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 20: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 20/139

DateAdd

DateAdd#(interval$, increment&, date1$ | date1#)

Descr. The DateAdd function returns a double-precision number representing the sum of date1 anda specified number (increment) of a specified time interval (interval$).

DateAdd adds a specified number (increment) of time intervals (interval$) to the specified date(date1). The following table describes the parameters to the DateAdd function:

The interval$ parameter specifies what unit of time is to be added to the given date. It can be any ofthe following:

To add days to a date, you may use either day, day of the year, or weekday, as they are all equivalent("d", "y", "w").

DateAdd will never return an invalid date/time expression. The following example adds two monthsto December 31, 1992:

s# = DateAdd("m", 2, "December 31, 1992")

Parameter Description

interval$ a string expression that indicates the time interval used in the addition.

incrementa double-precision number that indicates the number of time intervals you wish toadd. Positive values result in dates in the future; negative values result in dates in the

 past.

date1a double-precision number or a valid date/time. String expression. An example of avalid date/time string would be "January 1, 1993."

Time Interval

"y" Day of the year"yyyy" Year

"d" Day

"m" Month

"q" Quarter

"ww" Week

"h" Hour

"n" Minute

"s" Second

"w" Weekday

Page 20 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 21: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 21/139

In this example, s is returned as the double-precision number equal to "February 28, 1993", not"February 31, 1993".

A run-time error is generated if you attempt to subtract a time interval that is larger than the timevalue of the date.

Example:

Sub Main()

'This example gets today's date using the Date$ function; adds one'year, two months, one week, and two days to it; and then displays the'result in a dialog box.Dim dDate#Dim sDate$sDate$ = Date$NewDate# = DateAdd("yyyy", 3, sDate)NewDate = DateAdd("mm", 2, NewDate)NewDate = DateAdd("ww", 1, NewDate)

NewDate = DateAdd("dd", 2, NewDate)s$ = "One year, two months, one week, and two days from now will be: "s$ = s$ + format$(NewDate, "long date")MbeMessageBox s$

End Sub

DateDiff

DateDiff&(interval$, date1$ | date1#, date2$ | date2#)

Descr. Returns a double-precision number representing the number of given time intervals betweendate1 and date2.

The DateDiff  function will return the number of days or the number of whole weeks between twodates. The following table describes the parameters:

The following table lists the valid time interval strings and the meanings of each. The Format$ function uses the same expressions.

Parameter Description

interval$a string expression that indicates the specific time interval you wish to find thedifference between.

date1a double-precision number or a valid date/time string expression. An example of avalid date/time string would be "January 1, 1993".

date2a double-precision number or a valid date/time string expression. An example of avalid date/time string would be "January 1, 1993".

Time Interval

"y" Day of the year

"yyyy" Year

Page 21 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 22: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 22/139

To find the number of days between two dates, you may use either day or day of the year, as they are both equivalent ("d", "y").

The time interval weekday ("w") will return the number of weekdays occurring between date1 anddate2, counting the first occurrence but not the last. However, if the time interval is week ("ww"), thefunction will return the number of calendar weeks between date1 and date2, counting the number ofSundays. If date1 falls on a Sunday, then that day is counted, but if date2 falls on a Sunday, it is notcounted.

DateDiff  will return a negative date/time value if date1 occurs later in time than date2.

Example:

Sub Main()

'This example gets today's date and adds 10 days to it. It then'calculates the difference between the two dates in days and weeks'and displays the result.Today$ = Date$TodayR# = DateValue(Date$)

NextWeek# = DateAdd("d", 10, Today)Difdays# = DateDiff("d", Today, NextWeek)Difweek# = DateDiff("ww", Today, NextWeek)S$ = "The difference between " + Str$(Today) + " and " + Str$(NextWeek)S$ = S$ + " is: " + Str$(Difdays) + " days or " + Str$(DifWeek) + _

" weeks"MbeMessageBox S$

End Sub

DatePart

DatePart%(interval$, date1$ | date1#)

Descr. Returns a number representing a specified part of a valid date/time expression.

The DatePart function decomposes the given date and returns a given date/time element. The

following table describes the parameters:

"d" Day

"m" Month

"q" Quarter

"ww" Week

"h" Hour

"n" Minute

"s" Second

"w" Weekday

Page 22 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 23: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 23/139

The following table lists the valid time interval strings and the meanings of each. The Format$ function uses the same expressions.

The weekday expression starts with Sunday as 1 and ends with Saturday as 7.

Example:

const crlf = chr$(13) + chr$(10)

Sub Main()'This example displays the parts of the current dateToday$ = Date$Qtr = DatePart("q",Today)Yr = DatePart("yyyy",Today)Mo = DatePart("m",Today)

 Wk = DatePart("ww",Today)Da = DatePart("d",Today)S$ = "Quarter: " + Str$(Qtr) + crlfS$ = S$ + "Year : " + Str$(Yr) + crlfS$ = S$ + "Month : " + Str$(Mo) + crlfS$ = S$ + "Week : " + Str$(Wk) + crlf

S$ = S$ + "Day : " + Str$(Da) + crlfMbeMessageBox S$

End Sub

DateSerial

DateSerial#(year%, month%, day%)

Descr. The DateSerial function returns a double-precision number representing the specified date.

The number is returned in days, where Dec 30, 1899 is 0.

Example:

Parameter Description

interval$a string expression that indicates the specific time interval you wish to identify withinthe given date.

date1either a double-precision number or a valid date/time string expression. An exampleof a valid date/time string would be "January 1, 1993".

Time Interval

"y" Day of the year

"yyyy" Year

"d" Day

"m" Month

"q" Quarter

"ww" Week

Page 23 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 24: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 24/139

Sub Main()

'This example converts a date to a real number representing the'serial date in days since Dec 30, 1899 (which is day 0).Tdate# = DateSerial(1990,08,22)MbeMessageBox "DateSerial value for Aug 22, 1990, is: " + Str$(Tdate)

End Sub

DateValue

DateValue#(date_string$)

Descr. Returns a double-precision number representing the date contained in the specified stringargument.

Example:

Sub Main()

'This example returns the day of the month for today's date.Dim TDay as LongTdate$ = Date$TDay = DateValue(Tdate)MbeMessageBox Tdate + "The date value is: " + Str$(Tday)

End Sub

Day

Day%(serial#)

Descr. Returns the day of the date encoded in the specified serial parameter. The value returned is between 1 and 31 inclusive.

Example:

Sub Main()

'This example returns the day of the month for today's date.Dim TDay as LongTdate$ = Date$TDay! = Day(DateValue(Tdate))MbeMessageBox ("The day part of " + Tdate + " is: " + Str$(TDay))

End Sub

DDB

DDB#(Cost#, Salvage#, Life#, Period#)

Descr. This function calculates the depreciation of an asset for a specified Period of time using thedouble-declining balance method.

Page 24 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 25: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 25/139

The double-declining balance method calculates the depreciation of an asset at an accelerated rate.The depreciation is at its highest in the first period and becomes progressively lower in eachadditional period. DDB uses the following formula to calculate the depreciation:

DDB =((Cost - Total_depreciation_from_all_other_periods) * 2)/Life

DDB uses the following parameters:

Life and Period must be expressed using the same units. If Life is expressed in months, then Period must also be expressed in months.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example calculates the depreciation for capital equipment'that cost $10,000, has a service life of 10 years, and is worth'$2,000 as scrap. The dialog box displays the depreciation for each

'of the first 4 years.S$ = "Depreciation Table" + crlf + crlfFor yy = 1 To 4

CurDep# = DDB(10000.0, 2000.0, 10, yy)S$ = S$ + "Year " + Str$(yy) + " : " + Str$(CurDep) + crlf

Next yyMbeMessageBox S$

End Sub

DDEExecute

DDEExecute channel%, command$

Descr. Sends an execute message to another application.

The channel must first be initiated using DDEInitiate. An error will result if channel is invalid.

If the receiving application does not execute the instructions, BASIC generates a run-time error.

The format of command$ depends on the receiving application.

Win32 is the platform that applies to DDEExecute. The DDEML library is required for DDEsupport. This library is loaded when the first DDEInitiate statement is encountered and remainsloaded until the BASIC system is terminated. Thus, the DDEML library is required only if DDE

Parameter Description

Cost a double-precision number that represents the initial cost of the asset

Salvagea double-precision number that represents the estimated value of the asset at the endof its predicted useful life

Life a number that represents the predicted length of the asset's useful life

Period a number that represents the period for which you wish to calculate the depreciation

Page 25 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 26: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 26/139

statements are used within a macro.

Example:

Sub Main()

Dim ch As Integer

q$ = Chr$(34)ch = DDEInitiate("Excel", "C:\SHEETS\TEST.XLS")CMD$ = "[SELECT(" + q$ + "R1C1:R8C1" + q$ + ")]"DDEExecute ch,cmd$DDETerminate ch

End Sub

DDEInitiate

DDEInitiate%(app$, topic$)

Descr. Initializes a DDE link to another application and returns a unique number subsequently usedto refer to the open DDE channel.

The function returns 0 if BASIC cannot establish the link. This will occur under any of the followingcircumstances:

1. The specified application is not running.2. The topic was invalid for that application.3. Memory or system resources are insufficient to establish the DDE link.

app$ specifies the name of the application (the server) with which a DDE conversion will beestablished. topic$ specifies the name of the topic for the conversation. The possible values for this

 parameter are described in the documentation for the server application.

Win32 is the platform that applies to DDEInitiate. The DDEML library is required for DDEsupport. This library is loaded when the first DDEInitiate statement is encountered and remainsloaded until the BASIC system is terminated. Thus, the DDEML library is required only if DDEstatements are used within a macro.

Example:

Sub Main()

Dim ch As Integerq$ = Chr$(34)ch = DDEInitiate("Excel", "C:\SHEETS\TEST.XLS")CMD$ = "[SELECT(" + q$ + "R1C1:R8C1" + q$ + ")]"DDEExecute ch, cmd$DDETerminate ch

End Sub

DDEPoke

Page 26 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 27: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 27/139

 DDEPoke channel%, dataItem$, value$

Descr. Sets the value of a data item in the receiving application associated with an open DDE link.

The channel must first be initiated using DDEInitiate. An error will result if channel is invalid.

The format for dataItem$ and value$ depends on the receiving application.

Win32 is the platform that applies to DDEPoke. The DDEML library is required for DDE support.This library is loaded when the first DDEInitiate statement is encountered and remains loaded untilthe BASIC system is terminated. Thus, the DDEML library is required only if DDE statements areused within a macro.

Example:

Sub Main()

ch = DDEInitiate("Excel", "C:\SHEETS\TEST.XLS")

DDEPoke ch, "R1C1", "980"DDETerminate ch

End Sub

DDERequest

DDERequest$ (channel%, dataItem$)

Descr. Returns a string representing the value of the given data item in the receiving application

associated with the open DDE channel.

The channel must first be initiated using DDEInitiate. An error will result if channel is invalid.

The formats for dataItem$ and the returned value depend on the receiving application.

Win32 is the platform that applies to DDERequest. The DDEML library is required for DDEsupport. This library is loaded when the first DDEInitiate statement is encountered and remainsloaded until the BASIC system is terminated. Thus, the DDEML library is required only if DDEstatements are used within a macro.

Example:

Sub Main()

ch = DDEInitiate("Excel", "C:\SHEETS\TEST.XLS")s$ = DDERequest$(ch, "R1C1")DDETerminate chMbeMsgBox s$

End Sub

DDESend

DDESend application$, topic$, item$, data$

Page 27 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 28: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 28/139

Descr. Initiates a DDE conversation with the server as specified by application$ and topic$ andsends that server a new value for the specified item.

The DDESend statement performs the equivalent of the following statements:

ch% = DDEInitiate(application$, topic$)DDEPoke ch$, item$, data$

DDETerminate ch%

Win32 is the platform that applies to DDESend. The DDEML library is required for DDE support.This library is loaded when the first DDEInitiate statement is encountered and remains loaded untilthe BASIC system is terminated. Thus, the DDEML library is required only if DDE statements areused within a macro.

Example:

` The following code fragment sets the content of the first cell in an

` Excel spreadsheet.On Error Goto Trap1DDESend "Excel", "C:\EXCEL\TEST.XLS", "R1C1", "Hello, world."On Error Goto 0` Add more lines here ...

Trap1:MbeMsgBox "Error sending data to Excel."Exit Sub `Reset error handler

DDETerminate

DDETerminate channel%

Descr. Closes the specified DDE channel.

The channel must first be initiated using DDEInitiate. An error will result if channel is invalid.

All open DDE channels are automatically terminated when the macro ends.

Win32 is the platform that applies to DDETerminate. The DDEML library is required for DDEsupport. This library is loaded when the first DDEInitiate statement is encountered and remains

loaded until the BASIC system is terminated. Thus, the DDEML library is required only if DDEstatements are used within a macro.

Example:

Sub Main()

Dim ch As Integerq$ = Chr$(34)ch = DDEInitiate("Excel", "C:\SHEETS\TEST.XLS")CMD$ = "[SELECT(" + q$ + "R1C1:R8C1" + q$ + ")]"DDEExecute ch, cmd$DDETerminate ch

End Sub

Page 28 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 29: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 29/139

DDETerminateAll

DDETerminateAll

Descr. Closes all open DDE channels.

All open DDE channels are automatically terminated when the macro ends.

Win32 is the platform that applies to DDETerminateAll. The DDEML library is required for DDEsupport. This library is loaded when the first DDEInitiate statement is encountered and remainsloaded until the BASIC system is terminated. Thus, the DDEML library is required only if DDEstatements are used within a macro.

Example:

Sub Main()

Dim ch As Integerq$ = Chr$(34)ch = DDEInitiate("Excel", "C:\SHEETS\TEST.XLS")CMD$ = "[SELECT(" + q$ + "R1C1:R8C1" + q$ + ")]"DDEExecute ch, cmd$DDETerminateAll

End Sub

DDETimeOut

DDETimeOut milliseconds&

Descr. This statement sets the number of milliseconds that must elapse before a DDE commandtimes out. The default is 10,000 (10 seconds).

Win32 is the platform that applies to DDETimeOut. The DDEML library is required for DDEsupport. This library is loaded when the first DDEInitiate statement is encountered and remainsloaded until the BASIC system is terminated. Thus, the DDEML library is required only if DDEstatements are used within a macro.

Example:

Sub Main()

Dim ch As Integerq$ = Chr$(34)ch = DDEInitiate("Excel", "C:\SHEETS\TEST.XLS")DDETimeOut (20000)CMD$ = "[SELECT(" + q$ + "R1C1:R8C1" + q$ + ")]"DDEExecute ch, cmd$DDETerminate ch

End Sub

Declare

Page 29 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 30: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 30/139

 Declare Sub name [([argumentlist])]Declare Function name [([argumentlist])] [As type]

Descr. You can use the Declare statement to create a prototype for a BASIC routine that occurs laterin the source module.

The name parameter is any valid BASIC name. When you declare functions, you can include a type-declaration character to indicate the return type.

The optional argumentlist specifies the arguments received by the routine. By default, argumentsare passed by reference. When a routine requires a value rather than a reference, include the ByVal keyword. For example, the following subroutine:

Sub MessageBeep (ByVal numBeeps%, message#)

would be declared as follows:

Declare Sub MessageBeep (ByVal numBeeps%, message#)

For function declarations, the return type can be specified using a type-declaration character (i.e., $,% or &) or by specifying the [As type] clause. The valid types are Integer, Long and String.

Declare statements must appear outside of any Sub or Function declaration. Declare statements areonly valid during the life of that macro.

DEF...

DEFInt letterrangeDEFLng letterrangeDEFStr letterrangeDEFsng letterrangeDEFdbl letterrange

Descr. Establishes the default type assigned to undeclared or untyped variables.

The DEF... statement controls automatic type declaration of variables. Normally, if a variable is

encountered that hasn't yet been declared with the Dim statement or does not appear with an explicittype-declaration character, then that variable is declared implicitly as an integer (DEFInt A-Z). Thiscan be changed using the DEF... statement to specify starting letter ranges for type other thaninteger. The letterrange parameter is used to specify starting letters. Thus, any variable that beginswith a specified character will be declared using the specified type.

The syntax for letterrange is:

letter [-letter] [,letter [-letter]]...

DEF... variable types are superseded by an explicit type declaration--using either a type-declaration

character or the Dim statement.

DEF... only affects how macros are compiled and has no effect at run time. DEF... can only appearoutside all Sub and Function declarations.

Page 30 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 31: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 31/139

Example:

DEFStr a-l

DEFLng m-rDEFSng s-uDEFDbl v-w

DEFInt x-zSub Main()a = "This stuff"

 m = 100.52s = 100.52v = 100.55x = 100.52MbeMessageBox a & Str$(m) & Str$(s) & Str$(v) & Str$(x)

End Sub

Dim

Dim name [(<subscripts>)] [As [New] type] [,name [(<subscripts>)] _[As [New] type]]...

Descr. Declares a list of local variables and their corresponding types and sizes.

If a type-declaration character is used when specifying name (such as %, &, $ or !), the optional [As type] expression is not allowed. For example, the following are allowed:

Example:

Dim  Temperature  As Integer

Dim Temperature%

The subscripts parameter allows the declaration of dynamic and fixed arrays. subscripts uses thefollowing syntax:

[lower to] upper [,[lower to] upper]...

The lower and upper parameters are Integers specifying the lower and upper bounds of the array.

If lower is not specified, then the lower bound as specified by Option Base is used (or 0 if noOption Base statement has been encountered). BASIC supports a maximum of 60 array dimensions.

The total size of an array (not counting space for strings) is limited to 64K.

Dynamic arrays are declared by not specifying any bounds:

Example:

Dim  a()

The type parameter specifies the type of the data item being declared. It can be any of the followingdata types: String, Integer, Long, Single, Double, Object, application-defined object,application-defined data type, or any user-defined data type.

Page 31 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 32: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 32/139

A Dim statement within a subroutine or function declares variables local to that subroutine orfunction. If the Dim statement appears outside of any subroutine or function declaration, then thatvariable has the same scope as variables declared with the Private statement.

Implicit Variable Declaration

If BASIC encounters a variable that has not been explicitly declared with Dim, then the variable will be implicitly declared using the specified type-declaration character (%, $ or &). If the variableappears without a type-declaration character, then the first letter is matched against any pendingDEF... statements, using the specified type if found. If no DEF... statement has been encounteredcorresponding to the first letter of the variable name, then Integer is used.

Creating New Objects

The optional [New] keyword is used to declare a new instance of the specified application-definedobject. This keyword can only be used with application-defined object data types. Furthermore, thiskeyword cannot be used when declaring arrays.

At run time, the application or extension that defines that object type is notified that a new object is being defined. The application should respond by creating a new physical object (within theappropriate context) and returning a reference to that object, which is immediately assigned to thevariable being declared.

When that variable goes out of scope (i.e., the Sub or Function procedure in which the variable isdeclared ends), the application is notified. The application can choose any appropriate actions, suchas destroying the physical object.

Example:

Sub Main()

'The following are examples using the Dim statement to declare various'variable types.Dim a As integerDim a%Dim b As longDim b&Dim c As stringDim c$Dim MyArray(10) As integerDim MyStrings$(2,10)

Dim FileNames$(5 to 10)Dim Values(1 to 10, 100 to 200)End Sub

Dir$

Dir$[(filespec$ [,attributes])]

Descr. If filespec$ is specified, then the Dir$ function returns the first file matching that filespec$. If

filespec$ is not specified, then Dir$ returns the next file matching the initial filespec$ as shown inthe example.

Page 32 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 33: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 33/139

The filespec$ argument can include wild cards, such as * and ?. The * character matches anysequence of zero or more characters, whereas the ? character matches any single character. Multiple*'s and ?'s can appear within the expression to form complete searching patterns. The following tableshows some examples:

An error is generated if Dir$ is called without first calling it with a valid filespec$.

If there is no matching filespec$, then an empty string is returned.

If no path is specified on filespec$, then the current directory is used.

You can control which files are included in the search by specifying the optionalattributes

  parameter. This parameter contains any OR'ed combination of the following attributes:

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example dimensions a null array and fills it with directory'entries. The result is displayed in a dialog box.Dim a$(10)a(1) = Dir$("*.*")i% = 1

 While (a(i) <> "") And (i < 10)i = i+1a(i) = Dir$

This pattern Matches these files Doesn't match these files

*S*.TXTSAMPLE.TXTGOOSE.TXTSAMS.TXT

SAMPLESAMPLE.DAT

C*T.TXTCAT.TXTACATS.TXT

CAP.TXT

C*TCATCAP.TXT

CAT.DOC

C?TCATCUTCT

CAT.TXT

CAPIT

* (All files)

Constant Value Includes

ebNormal 0 Clear the read-only and archive attributes

ebReadOnly 1 Set read-only attribute

ebHidden 2 Set hidden attribute

ebSystem 4 Set system file attribute

ebArchive 32 Set archive attribute

Page 33 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 34: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 34/139

  WendMbeMessageBox a(1) + crlf + a(2) + crlf + a(3) + crlf + a(4)

End Sub

Do...Loop

Do {While | Until} condition statements LoopDostatements

Loop {While | Until} conditionDostatements

Loop

Descr. Repeats a block of BASIC statements while a condition is TRUE or until a condition is TRUE. Ifthe {While | Until} conditional clause is not specified, then the loop repeats the statements forever(or until BASIC encounters an Exit Do statement).

The condition parameter specifies any Boolean expression.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'The first example uses the Do...While statement, which performs the'iteration, then checks the condition, and repeats if the condition'is True.

Dim a$(100)i% = 0Do

i = i+1If i = 1 Then

a(i) = Dir$("*.*")Else

a(i) = Dir$End If

Loop While (a(i) <> "")Msg$ = "There are " + Str$(i) + " files found" + crlfMbeMessageBox Msg + a(1) + crlf + a(2) + crlf + a(3) + crlf + a(10)'The second example uses the Do While...Loop, which checks the'condition and then repeats if the condition is True.Dim a$(100)i% = 1a(i) = Dir$("*.*")Do While a(i) <> ""

i = i+1a(i) = Dir$

LoopMsg$ = "There are " + Str$(i) + " files found" + crlfMbeMessageBox Msg + a(1) + crlf + a(2) + crlf + a(3) + crlf + a(10)'The third example uses the Do Until...Loop, which does the iteration'and then checks the condition and repeats if the condition is True.Dim a$(100)i% = 1a(i) = Dir$("*.*")Do Until a(i) = ""

i = i+1

Page 34 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 35: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 35/139

  a(i) = Dir$LoopMsg$ = "There are " + Str$(i) + " files found" + crlfMbeMessageBox Msg + a(1) + crlf + a(2) + crlf + a(3) + crlf + a(10)'The last example uses the Do...Until Loop, which performs the'iteration first, checks the condition, and repeats if the condition'is True.Dim a$(100)

i% = 0Do

i = i+1If i = 1 Then

a(i) = Dir$("*.*")Else

a(i) = Dir$End If

Loop Until (a(i) = "")Msg$ = "There are " + Str$(i) + " files found" + crlfMbeMessageBox Msg + a(1) + crlf + a(2) + crlf + a(3) + crlf + a(10)

End Sub

ebArchive

Descr. 32-bit position of a file attribute indicating that a file hasn't been backed up.

Example:

Sub Main()

'Dimension an array and fill it with filenames with Archive bit set.Dim s$()FileList(s$), "*.*", ebArchivea% = SelectBox("Archived Files", "Choose one", s$)If a >= 0 Then 'If a% is -1, then user pressed Cancel.

MbeMessageBox "You selected ARCHIVE file " + s$(a)Else

MbeMessageBox "No selection made"End If

End Sub

ebDirectory

Descr. 16-bit position of a file attribute indicating that a file is a directory entry.

Example:

Sub Main()

'Dimension an array and fill it with directory names using the'ebDirectory constant.Dim s$()

FileList(s$), "*.*", ebDirectorya% = MbeSelectBox("Choose One", s(), "Directories")If a >= 0 Then

MbeMessageBox "You selected directory " + S$(a)

Page 35 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 36: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 36/139

  ElseMbeMessageBox "No selection made"

End IfEnd Sub

ebHidden

Descr. 2-bit position of a file attribute indicating that a file is hidden.

Example:

Sub Main()

'Dimension an array and fill it with filenames using`the ebHidden attribute.Dim s$()

FileList(S$), "*.*", ebHiddena% = SelectBox("Hidden Files","Choose one", S$)If a >= 0 Then

MbeMessageBox "You selected hidden file " + S$(a)Else

MbeMessageBox "No selection made"End If

End Sub

ebNone

Descr. 64-bit value used to select files with no other attributes. This value can be used with the Dir$ and FileList commands. These functions will return only files with no attributes set when used withthis constant.

Example:

Sub Main()

'Dimension an array and fill it with filenames with no attributes set.Dim s$()FileList(S$), "*.*", ebNonea% = SelectBox("No Attributes", "Choose one", S$)If a >= 0 Then

MbeMessageBox "You selected file " + S$(a)Else

MbeMessageBox "No selection made"End If

End Sub

ebNormal

Descr. 0

Page 36 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 37: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 37/139

Value used to search for "normal" files. This value can be used with the Dir$ and FileList commands and will return files with the Archive, Volume, ReadOnly or no attributes set. It will notmatch files with Hidden, System or Directory attributes.

Example:

Sub Main()

'Dimension an array and fill it with filenames with Normal attributes.Dim s$()FileList(S$),"*.*", ebNormala% = SelectBox("Normal Files", "Choose one", S$)If a >= 0 Then

MbeMessageBox "You selected file " + S$(a)Else

MbeMessageBox "No selection made"End If

End Sub

ebReadOnly

Descr. Bit[1] position of a file attribute indicating that a file is read-only.

Example:

Sub Main()

'Dimension an array & fill it with filenames with ReadOnly attributes.

Dim s$()FileList(S$), "*.*", ebReadOnlya% = SelectBox("ReadOnly", "Choose one", S$)If a >= 0 Then

MbeMessageBox "You selected file " + S$(a)Else

MbeMessageBox "No selection made"End If

End Sub

ebSystem

Descr. Bit[4] position of a file attribute indicating that a file is a system file.

Example:

Sub Main()

'Dimension an array and fill it with filenames with System attributes.Dim s$()FileList(S$), "*.*", ebSystem

a% = SelectBox("System Files", "Choose one", S$)If a >= 0 ThenMbeMessageBox "You selected file " + S$(a)

Else

Page 37 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 38: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 38/139

  MbeMessageBox "No selection made"End If

End Sub

ebVolume

Descr. Bit[8] position of a file attribute indicating that a file is the volume label.

Example:

Sub Main()

'Dimension an array and fill it with filenames with Volume attributes.Dim s$()FileList(S$), "*.*", ebVolumeIf ArrayDims(a) > 0 Then

MbeMessageBox "The volume name is: " + a(1)ElseMbeMessageBox "No volumes found"

End IfEnd Sub

End

End

Descr. Terminates execution of the current macro. All open files are closed.

Example:

Sub Main()

MbeMessageBox "The next line will terminate the script"End

End Sub

Environ$

Environ$(variable$)Environ$(VariableNumber%)

Descr. Returns the value of the specified environment variable.

If variable$ is specified, then this function looks for that variable$ in the environment. If variable$ cannot be found, an empty string is returned.

If VariableNumber is specified, then this function looks for the nth variable within the environment(the first variable being number 1). If there is no such environment variable, then an empty string isreturned. Otherwise, the entire entry from the environment is returned in the following format:

Page 38 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 39: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 39/139

  variable = value

Example:

Sub Main()

'This example looks for the DOS Comspec variable and displays the

'value in a dialog box.Dim a$(1)a(1) = Environ$("COMSPEC")MbeMessageBox a(1)

End Sub

To retrieve and set the values of MicroStation configuration variables, use the MicroStation BASICextensions: MbeGetConfigVar (page8144) and MbeDefineConfigVar.

See also MbeGetConfigVar, MbeSetConfigVar.

Eof

Eof%(filenumber%)

Descr. Returns TRUE if the end of file has been reached for the given file; otherwise returns FALSE.

The filenumber parameter is a number that is used to refer to the open file--the number passed to theOpen statement.

With sequential files, Eof  returns TRUE when the end of the file has been reached (i.e., the next fileread command will result in a run-time error).

With Random or Binary files, Eof  returns TRUE after an attempt has been made to read beyond theend of the file. Thus, Eof  will only return TRUE when Get was unable to read the entire record.

Example:

Sub Main()

'This example opens the Autoexec.Bat file and reads lines from the

'file until the end of file is reached.Dim S$Open "C:\AUTOEXEC.BAT" For Input As 1Do While Not Eof(1)

Input #1,SLoopCloseMbeMessageBox "The last line was" + crlf + S

End Sub

Eqv

expression1 Eqv expression2

Page 39 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 40: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 40/139

Descr. If both operands are relational, then Eqv returns the logical equivalence of expression1 andexpression2. Eqv returns TRUE if expression1 and expression2 are the same (i.e., either both TRUE or both FALSE); otherwise Eqv returns FALSE.

If both operands are numeric, then the result is the bitwise Eqv of the arguments.

If either of the two operands is a floating-point number, the two operands are converted to Longs,then a bitwise Eqv is performed.

For numeric operands, bitwise Eqv works as follows:

Example:

Sub Main()

'This example assigns False to A, performs some equivalent operations,'and displays a dialog box with the result. Since A is equivalent to'False, and False is equivalent to 0, and by definition, A = 0, then'the dialog box will display "A is False".A = False

If ((A Eqv False) And (False Eqv 0) And (A = 0)) ThenMbeMessageBox "A is False"

ElseMbeMessageBox "A is True"

End IfEnd Sub

Erase

Erase array1 [,array2]...

Descr. The Erase statement erases the elements of the specified arrays.

For dynamic arrays, the elements are erased and the array is redimensioned to have no dimensions(and therefore no elements). For fixed arrays, only the elements are erased; the array dimensions arenot changed.

After a dynamic array is erased, the array will contain no elements and no dimensions. Thus, beforethe array can be used by your program, the dimensions must be reestablished using the Redim statement.

Up to 32 parameters can be specified with the Erase statement.

The meaning of erasing an array element depends on the type of element being erased:

Bit in expression1 Bit in expression2 Bit in result

1 1 1

0 1 0

1 0 0

0 0 1

Page 40 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 41: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 41/139

 

Example:

Sub Main()

Dim a$(1)a(1) = Dir$("*.*")MbeMessageBox aErase aMbeMessageBox a(1)

End Sub

Erl

Erl%[()]

Descr. Returns 0 (BASIC does not support line numbers).

Example:

Sub Main()

'Since the Erl function normally specifies a line number, it will'always return 0 within this product, as shown below.

a = ErlIf a = 0 Then

MbeMessageBox "Returned 0"Else

MbeMessageBox "Returned non-0" + Str$(a)End If

End Sub

Err (function)

Err%[()]

Descr. The Err function returns an Integer representing the run time error that caused the current

Element type What Erase does to that element

Integer Sets the element to 0.

Long Sets the element to 0.

Double Sets the element to 0.0.

Single Sets the element to 0.0.

String Frees the string, then sets the element to an empty string.

Object Decrements the reference count and sets the element to Nothing.

User-defined types Sets each structure element as a separate variable.

Page 41 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 42: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 42/139

error trap.

Err can only be used while within an error trap.

When a function or statement ends, the value returned by Err is reset to 0.

Example:

Sub Main()

'This example forces error 10, with a subsequent transfer to'the TestError label. TestError tests the error and, if not'error 55, resets Err to 999 (user-defined error) and returns to'the Main subroutine.On Error Goto TestErrorError 10MbeMessageBox("The returned error is: " + Str$(Err()) + " : " + Error$)Exit Sub

TestError:

If Err = 55 Then 'File already open.MbeMessageBox "Cannot copy an open file. Close it and try again."

ElseMbeMessageBox "Error " + Str$(Err) + " has occurred"Err = 999

End IfResume Next

End Sub

Err (statement)

Err = value%

Descr. The statement form of Err sets the value returned by the Err function to a specific value.

Only positive values less than 32767 are valid.

Setting value to -1 has the side effect of resetting the error state. This allows you to perform errortrapping within an error handler.

Example:

Sub Main()

'This example forces error 10, with a subsequent transfer to'the TestError label. TestError tests the error and, if not'error 55, resets Err to 999 (user-defined error) and returns to'the Main subroutine.On Error Goto TestErrorError 10MbeMessageBox("The returned error is: " + Str$(Err()) + " : " + Error$)Exit Sub

TestError:

If Err = 55 Then 'File already open.MbeMessageBox "Cannot copy an open file. Close it and try again."Else

MbeMessageBox "Error " + Str$(Err) + " has occurred"

Page 42 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 43: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 43/139

  Err = 999End IfResume Next

End Sub

Error

Error errornumber%

Descr. This function simulates the occurrence of the given run-time error.

The errornumber parameter can be a built-in error number or a user-defined error number. Err can be used within the error trap handler to determine the value of the error.

Example:

Sub Main()

'This example forces error 10, with a subsequent transfer to'the TestError label. TestError tests the error and, if not'error 55, resets Err to 999 (user-defined error) and returns to'the Main subroutine.On Error Goto TestErrorError 10MbeMessageBox("The returned error is: " + Str$(Err()) + " : " + Error$)Exit Sub

TestError:If Err = 55 Then 'File already open.

MbeMessageBox "Cannot copy an open file. Close it and try again."Else

MbeMessageBox "Error " + Str$(Err) + " has occurred"Err = 999

End IfResume Next

End Sub

Error$

Error$ [(errornumber%)]

Descr. Returns the text corresponding to the given error number or the most recent error.

If errornumber is omitted, then the function returns the text corresponding to the most recent run-time error. If no run-time error has occurred, then an empty string ("") is returned.

If the Error statement was used to generate a user-defined run-time error, then this function willreturn an empty string ("").

Example:

Sub Main()

Page 43 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 44: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 44/139

  'This example forces error 10, with a subsequent transfer to'the TestError label. TestError tests the error and, if not'error 55, resets Err to 999 (user-defined error) and returns to'the Main subroutine.On Error Goto TestErrorError 10MbeMessageBox("The returned error is: " + Str$(Err()) + " : " + Error$)Exit Sub

TestError:If Err = 55 Then 'File already open.

MbeMessageBox "Cannot copy an open file. Close it and try again."Else

MbeMessageBox "Error " + Str$(Err) + " has occurred"Err = 999

End IfResume Next

End Sub

Exit Do

Exit Do 

Descr. This statement can only appear within a Do...Loop statement. It causes execution to continueon the next statement after the Loop clause.

Example:

Sub Main()

'This example will load an array with directory entries unless there'are more than three entries, in which case, the Exit Do terminates'the loop.'If fewer than 3 entries are found, a dialog box displays the count;'otherwise, a dialog box displays "More than three entries found."Dim a$(5)i% = 0Do

i = i+1If i = 1 Then

a(i) = Dir$("*.*")Else

a(i) = Dir$

End IfIf i >= 3 Then Exit DoLoop While (a(i) <> "")If i <> 3 Then

MbeMessageBox "There are " + Str$(i) + " files found"Else

MbeMessageBox "Exited on i = 3"End IfMbeMessageBox a(1) + crlf + a(2) + crlf + a(3) + crlf + a(10)

End Sub

Exit For

Page 44 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 45: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 45/139

 Exit For

Descr. This statement ends the For...Next block in which it appears. Execution will continue on theline immediately after the Next statement.

This statement can only appear within a For...Next block.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example will fill an array with directory entries`until a null entry is encountered or 100 entries have been`processed. The dialog box displays a count of files found and`then some entries from the array.Dim a$(100)Dim i%For i% = 1 To 100

If i = 1 Thena(i) = Dir$("*.*")

Elsea(i) = Dir$

End IfIf (a(i) = "") Or (i >= 100) Then Exit For

Next iMsg$ = "There are " + Str$(i) + " files found" + crlfMbeMessageBox Msg + a(1) + crlf + a(2) + crlf + a(3) + crlf + a(10)

End Sub

Exit Function

Exit Function

Descr. This statement ends execution of the function in which it appears. Execution will continue onthe statement or function following the call to this function.

This statement can only appear within a function.

Example:

Function Test_Exit () As Integer

'This function displays a message & then terminates with Exit Function.MbeMessageBox("Testing function exit: returning to Main")Test_Exit = 0Exit FunctionMbeMessageBox("This line should never execute")

End FunctionSub Main()

a% = Test_Exit()MbeMessageBox "This is the last line of Main"

End Sub

Exit Sub

Page 45 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 46: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 46/139

 Exit Sub

Descr. This statement ends the current subroutine. Execution is transferred to the statementfollowing the call to the current subroutine.

This statement can appear anywhere within a subroutine. It cannot appear within a function.

Example:

Sub Main()

'This example displays a dialog box & then exits. The last line should'never execute because of the Exit Sub statement.MbeMessageBox("Terminating Main")Exit SubMbeMessageBox("Still here in Main")

End Sub

Exp

Exp#(value#)

Descr. Returns the value of e raised to the power of value.

Range of value: 0 <= value <= 709.782712893.

A run-time error is generated if value is out of the range specified above.

Example:

Sub Main()

'This example assigns a to e raised to the 12.4 power and displays it'in a dialog box.a# = Exp(12.40)MbeMessageBox "e to the 12.4 power is: " + Str$(a)

End Sub

False

Descr. 0, used in conditionals and Boolean expressions.

Example:

Sub Main()

'This example assigns False to A, performs some equivalent operations,'and displays a dialog box with the result. Since A is equivalent to'False, and False is equivalent to 0, and by definition, A = 0, then

Page 46 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 47: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 47/139

  'the dialog box will display "A is False".A = Falseif ((A = False) and (False Eqv 0) And (A = 0)) Then

MbeMessageBox "A is False"Else

MbeMessageBox "A is True"End If

End Sub

FileAttr

FileAttr%(filenumber%, attribute%)

Descr. Returns the file mode (if attribute is 1) or the operating system file handle (if attribute is 2).

If attribute is 1, then one of the following values is returned:

The filenumber parameter is a number that is used to refer to the open file--the number passed to the

Open statement.

Example:

Sub Main()

'This example opens a file for input, reads the file attributes, and'determines the file mode for which it was opened. The result is'displayed in a dialog box.Open "C:\AUTOEXEC.BAT" For Input As 1a% = FileAttr(1,1)Select Case a

Case 1MbeMessageBox "Opened for input"

Case 2MbeMessageBox "Opened for output"

Case 3MbeMessageBox "Opened for random"

Case 4MbeMessageBox "Opened for append"

Case 32MbeMessageBox "Opened for binary"

Case ElseMbeMessageBox "Unknown file mode"

End Select

a = FileAttr(1,2)MbeMessageBox "File handle is: " + Str$(a)Close

End Sub

1 Input

2 Output

4 Random

8 Append

32 Binary

Page 47 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 48: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 48/139

FileCopy

FileCopy source$, destination$

Descr. The FileCopy command copies a source$ file to a destination$ file.

The source$ parameter must specify a single file. It cannot contain wild cards (? or *) but maycontain path information.

The destination$ specifies a single, unique destination file and may contain drive and pathspecifiers. The file will be copied and renamed if the source$ and destination$ filenames are not thesame. Note that some platforms do not support drive letters and may not support dots to indicatecurrent and parent directories.

Example:

Sub Main()

'This example copies the Autoexec.Bat file to "AUTOEXEC.SAV", then'opens the copied file and tries to copy it again, generating an error.On Error Goto ErrHandlerFileCopy "C:\AUTOEXEC.BAT", "C:\AUTOEXEC.SAV"Open "C:\AUTOEXEC.SAV" For Input As # 1FileCopy "C:\AUTOEXEC.SAV", "C:\AUTOEXEC.SV2"CloseExit Sub

ErrHandler:If Err = 55 Then 'File already open.

MbeMessageBox "Cannot copy an open file. Close it and try again."Else

MbeMessageBox "An unspecified file copy error has occurred"End IfResume Next

End Sub

FileDateTime

FileDateTime#(filename$)

Descr. The FileDateTime function returns a double-precision number representing the date and timeof the given file. The number is returned in days, where Dec 30, 1899 is 0.

FileDateTime retrieves the date and time of the file specified by filename$. A run-time error resultsif the file does not exist. The value returned can be used with the date/time functions (i.e., Year,Month, Day, Weekday, Minute, Second, Hour) to extract the individual elements.

Example:

Sub Main()

'This example gets the file date/time of the Autoexec.Bat file and'displays it in a dialog box.

Page 48 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 49: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 49/139

  If FileExists "C:\Autoexec.Bat" ThenA# = FileDateTime("C:\AUTOEXEC.BAT")MbeMessageBox Str$(Year(A)) + Str$(Month(A)) + Str$(Day(A))

ElseMbeMessageBox "The file does not exist"

End IfEnd Sub

FileDirs

FileDirs array$() [,dirspec$]

Descr. This statement fills an array$ with directory names from disk.

array$() is any previously declared string array. The FileDirs function reallocates this array toexactly hold all the directory names matching a given specification.

array$ must specify either a 0- or a 1-dimensioned dynamic array or a single-dimensioned fixedarray. If the array is dynamic, then it will be redimensioned to exactly hold the new number ofelements. If the array is fixed, each array element is first erased, then the new elements are placedinto the array. If there are fewer elements than will fit in the array, then the remaining elements areunused. A run-time error results if the array is too small to hold the new elements.

The dirspec$ parameter specifies the file search mask, such as:

T*. C:\*.*

If dirspec$ is not specified, then * is used, which fills the array with all the subdirectory nameswithin the current directory.

Example:

Sub Main()

'This example fills an array with directory entries and displays the'first one.Dim A$()FileDirs A,"C:\*.*"

MbeMessageBox A(1)

End Sub

FileExists

FileExists%(filename$)

Descr. TRUE if the filename$ is a valid file; FALSE otherwise.

FileExists determines whether a given filename$ is valid. FileExists will return FALSE if  filename$ 

specifies a subdirectory.

Example:

Page 49 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 50: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 50/139

Sub Main()

'This example checks to see whether there is an Autoexec.Bat file in'the root directory of the C drive, then displays either its date and'time of creation or the fact that it does not exist.If FileExists("C:\AUTOEXEC.BAT") Then

a# = FileDateTime("C:\AUTOEXEC.BAT")MbeMessageBox Str$(Year(A#)) + Str$(Month(A#)) + Str$(Day(A#))

ElseMbeMessageBox "File does not exist"

End IfEnd Sub

FileLen

FileLen&(filename$)

Descr. Returns the length of the given filename$ in bytes.

This function is used in place of Lof  to retrieve the length of a file without first opening the file. Arun-time error results if the file does not exist.

Example:

Sub Main()

'This example checks to see whether there is a C:\AUTOEXEC.BAT file'and, if there is, displays the length of the file.

If (FileExists("C:\AUTOEXEC.BAT") And _(FileLen("C:\AUTOEXEC.BAT") <> 0)) Thenb% = FileLen("C:\AUTOEXEC.BAT")MbeMessageBox "The length of Autoexec.Bat is: " + Str$(B)

ElseMbeMessageBox "File does not exist"

End IfEnd Sub

FileList

FileList array$() [,filespec$ [,include_attr% [,exclude_attr]]]

Descr. This statement fills an array with filenames from disk. The filenames must conform to aneight character filename handle and three character filename extension (8.3 DOS format), or anMDL abort will occur.

The array$() is any previously declared string array. The FileList function reallocates this array toexactly hold all the files matching a given filespec$.

The filespec$ argument can include wild cards, such as * and ?. The * character matches any

sequence of zero or more characters, whereas the ? character matches any single character. Multiple*s and ?s can appear within the expression to form complete searching patterns. The following tableshows some examples:

Page 50 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 51: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 51/139

 

Thus, if filespec$ is not specified, * is used.

include_attr is a number indicating what types of files you want included in the list. Similarly,exclude_attr specifies attributes of files you want excluded from the list. These numbers can be anycombination of the following:

If include_attr is not specified, then the value 97 is used (ebReadOnly Or ebArchive Or ebNone). Ifexclude_attr is not specified, then hidden files and subdirectories are excluded from the list (18).

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example fills an array a with the directory of the current drive'for all files that have normal or no attributes and excludes those'with system attributes. The dialog box displays four filenames from

'the array.Dim a$()FileList a,"*.*", (ebNormal + ebNone), ebSystemIf ArrayDims(a) > 0 Then

This pattern Matches these files Doesn't match these files

*S*.TXTSAMPLE.TXTGOOSE.TXTSAMS.TXT

SAMPLESAMPLE.DAT

C*T.TXT CAT.TXTACATS.TXT

CAP.TXT

C*TCATCAP.TXT

CAT.DOC

C?TCATCUTCT

CAT.TXTCAPIT

* (All files)

Constant Value Includes

ebNormal 0 Read-only, archive, subdir, none

ebReadOnly 1 Read-only files

ebHidden 2 Hidden files

ebSystem 4 System files

ebVolume 8 Volume label

ebDirectory 16 DOS subdirectories

ebArchive 32 Files that have changed since the last backup

ebNone 64 Files with no attributes

Page 51 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 52: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 52/139

  MbeMessageBox a(1) + crlf + a(2) + crlf + a(3) + crlf + a(4)Else

MbeMessageBox "No files found"End If

End Sub

FileParse$

FileParse$(filename$[, operation])

Descr. This statement takes a filename and extracts a given portion of the filename from it.

filename$ can specify any valid filename (it does not have to exist). For example:

..\test.datC:\sheets\test.dat

test.dat

The optional operation parameter specifies which portion of the filename$ to extract. It can be any ofthe following values.

If operation is not specified, then the full name is returned. A run-time error will result if operation isnot one of the above values.

A runtime error results if filename$ is empty.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example parses the file string "C:\TestSub\Autoexec.Bat" into its'component parts and displays them in a dialog box.Dim a$(6)Dim i%For i = 1 To 5

a(i) = FileParse$("C:\TestSub\Autoexec.Bat",i-1)Next iMbeMessageBox a(1)+ crlf + a(2) + crlf + a(3) + crlf + a(4) + crlf + a(5)

End Sub

Fix

0 Full name c:\sheets\test.dat

1 Drive c

2 Path c:\sheets

3 Name test.dat

4 Root test

5 Extension dat

Page 52 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 53: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 53/139

 Fix%(number#)

Descr. Returns the integer part of number.

This function returns the integer part of the given value by removing the fractional part. The sign is preserved.

Fix differs from the Int function in that Fix truncates negative numbers in a positive direction.

Example:

Sub Main()

'This example returns the fixed part of a number and assigns it to b,'then displays the result in a dialog box.a# = -19923.45

b% = Fix(a)MbeMessageBox ("The fixed portion of 19923.45 is: " + Str$(b))End Sub

For...Next

For counter = start To end [Step increment][statements][Exit For][statements]

Next [counter]

Descr. Repeats a block of statements a specified number of times, incrementing a loop counter by agiven increment each time through the loop.

If increment is not specified, then 1 is assumed. The expression given as increment is evaluated onlyonce. Changing the step during execution of the loop will have no effect.

The first time through the loop, counter is equal to start. Each time through the loop, increment isadded to counter by the amount specified in increment.

The For...Next statement continues executing until an Exit For statement is encountered whencounter is greater than end. The expression specified by end is evaluated only once. Thus, changingthe end expression during execution of the loop will have no effect.

If end is greater than start, then increment must be positive. If end is less than start, then incrementmust be negative.

For...Next statements can be nested. In such a case, the Next [counter] statement applies to theinnermost For...Next.

The Next [counter] can be optimized for next loops by separating each counter with a comma. The

ordering of the counters must be consistent with the nesting order (innermost counter appearing before outermost counter):

Page 53 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 54: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 54/139

  Next i,j

Example:

Function Factorial (n%) As Integer

'Calculate N factorial.

f% = nFor i% = n To 2 Step -1

f = f * iNext iFactorial = f

End FunctionSub Main()

'This example calculates the value of 5 factorial using a For...Next'loop in function factorial.MbeMessageBox "5 factorial is: " + Str$(Factorial(5))'Constructs a truth table for the OR statement using nested loops.Msg$ = NullFor X% = True To False

For Y% = True To FalseZ = X Or YMsg = Msg + Format$(Abs(X),"0") + " OR "Msg = Msg + Format$(Abs(Y),"0") + " = "Msg = Msg + Format$(Z,"True/False") + crlf

Next YNext XMbeMessageBox Msg

End Sub

Format$

Format$(Expression [,Userformat$])

Descr. Returns a string formatted to user specification.

The Format$ function has two parts, consisting of:

If no Userformat$ parameter is given and the expression is numeric, then Format$ performs thesame function as the Str$ command, except that it does not preserve a leading space for positivevalues.

Built-In Formats

To format numeric expressions, you can specify one of the built-in formats. There are two categoriesof built-in formats: one deals with numeric expressions and the other with date/time values.The

ExpressionA string or numeric expression to be formatted. The numeric expression can beentered as a double, a single, an integer, a long, a scientific notation, or a string.

Userformat$

A format expression that can be either one of the built-in BASIC formats or a user-defined format consisting of characters that specify how the expression should bedisplayed.String, numeric, and date/time formats cannot be mixed in a single Userformat$expression.

Page 54 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 55: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 55/139

following tables list the built-in numeric and date/time format strings, followed by an explanation ofwhat each does.

Date formats are listed in the following table:

NumericFormat

Description

General Number Display the numeric expression as is, with no additional formatting.

CurrencyDisplay the numeric expression as currency, with thousand separator if necessary.The actual formatted output depends on the Currency settings in the Internationalsection of the Control Panel.

FixedDisplay at least one digit to the left of the decimal separator and two digits to theright.

StandardDisplay the numeric expression with thousand separator if necessary. Display atleast one digit to the left of the decimal separator and two digits to the right.

PercentDisplay the numeric expression multiplied by 100. A percent sign (%) will appearat the right of the formatted output. Two digits are displayed to the right of thedecimal separator.

ScientificDisplay the number using scientific notation. One digit appears before the decimalseparator and two after.

Yes/No Display No if the numeric expression is 0. Display Yes for all other values.

True/False Display False if the numeric expression is 0. Display True for all other values.

On/Off Display Off if the numeric expression is 0. Display On for all other values.

DateFormat

Description

GeneralDate

Display the date and time. If there is no fractional part in the numeric expression, thenonly the date is displayed. If there is no integral part in the numeric expression, thenonly the time is displayed. Output is in the following form: 1/1/93 01:00:00 AM.

Long

Date

Display a long date, as specified in the International section of the Control Panel.

MediumDate

Display a short date, as specified in the International section of the Control Panel, only print out the abbreviated name of the month.

ShortDate

Display a short date, as specified in the International section of the Control Panel.

LongTime

Display the long time, as defined in the International section of the control panel. Thedefault is: h:mm:ss. When Format$ is used to format a time value, the Expressionargument should be a double-precision floating point value. Such a value can beobtained using the TimeValue function.

MediumTime

Display the time using the 12-hour clock. Hours and minutes are displayed, and theAM/PM designator is at the end. When Format$ is used to format a time value, theExpression argument should be a double-precision floating point value. Such a value

Page 55 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 56: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 56/139

User-Defined Formats

In addition to the built-in formats, you can also specify a user-defined format, by using charactersthat have special meaning when used in a format expression. The following tables list the charactersyou can use for numeric, string, and date/time formats and explain their functions.

can be obtained using the TimeValue function.

ShortTime

Display the time using the 24-hour clock. Hours and minutes are displayed.WhenFormat$ is used to format a time value, the Expression argument should be a double-

 precision floating point value. Such a value can be obtained using the TimeValuefunction.

Character Meaning

Emptystring

This displays the numeric expression as is, with no additional formatting.

0

This is a digit placeholder.

This will display a number or a 0. If there exists a number in the numeric expressionin the position where the 0 appears, the number will be displayed. Otherwise, a 0 will

 be displayed. If there are more 0s in the format string than there are digits, the leadingand trailing 0s are displayed without modification.

#

This is a digit placeholder.

This will display a number or nothing. If there exists a number in the numericexpression in the position where the pound sign appears, the number will be

displayed. Otherwise, nothing will be displayed. Leading and trailing 0s are notdisplayed.

.

This is the decimal placeholder.

This designates the number of digits to the left of the decimal and the number ofdigits to the right. The character used in the formatted string depends on the decimal

 placeholder character specified in the International section of the Control Panel.

%

This is the percentage operator.

The numeric expression is multiplied by 100, and the percent character is inserted in

the same position as it appears in the user-defined format string.

,

This is the thousand separator.

The common use for the thousand separator is to separate thousands from hundreds.To specify this use, the thousand separator must be surrounded by digit placeholders.Commas appearing before any digit placeholders are specified are just displayed.Adjacent commas with no digit placeholders specified between them and the decimalmean divide the number by 1,000 for each adjacent comma in the format string. Acomma immediately to the left of the decimal has the same function. The actualthousand separator character used depends on the character specified in the

International section of the Control Panel.

These are the scientific notation operators.

Page 56 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 57: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 57/139

 Numeric formats can contain one to three parts. Each part is separated by a semicolon. If you specifyone format, it applies to all values. If you specify two formats, the first applies to positive values andthe second to negative values. If you specify three formats, the first applies to positive values, thesecond to negative values, and the third to 0s. If you include semicolons with no format betweenthem, the format for positive values is used.

String formats are listed in the following table:

E-E+e-e+

This displays the number in scientific notation. At least one digit placeholder mustexist to the left of E-, E+, e-, or e+. Any digit placeholders displayed to the left of E-,E+, e-, or e+ determine the number of digits displayed in the exponent. Using E+ ore+ places a + in front of positive exponents and a - in front of negative exponents.Using E- or e- places a - in front of negative exponents and nothing in front of

 positive exponents.

:

This is the time separator.

This separates hours, minutes, and seconds when time values are being formatted.The actual character used depends on the character specified in the Internationalsection of the Control Panel.

/

This is the date separator.

This separates months, days, and years when date values are being formatted. Theactual character used depends on the character specified in the International section ofthe Control Panel.

-+$()space

These are the literal characters you can display.

To display any other character, you should precede it with a backslash or enclose it inquotes.

\

This designates the next character as a displayed character.

To display characters, precede them with a backslash. To display a backslash, use two backslashes. Double quotation marks can also be used to display characters. Numericformatting characters, date/time formatting characters, and string formattingcharacters cannot be displayed without a preceding backslash.

"ABC"

This displays the text between the quotation marks.

The text between the quotation marks is displayed, but the quotation marks are not.To designate a double quotation mark within a format string, use two adjacent doublequotation marks.

*This will display the next character as the fill character.

Any empty space in a field will be filled with the specified fill character.

Character Meaning

@

This is a character placeholder.

This will display a character if one exists in the expression in the same position.Otherwise, it will display a space. Placeholders are filled from right to left unless the

Page 57 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 58: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 58/139

Date/time formats are listed in the following table:

format string specifies left to right.

&

This is a character placeholder.

This will display a character if one exists in the expression in the same position.Otherwise, it will display nothing. Placeholders are filled from right to left unless theformat string specifies left to right.

<This character forces lowercase.

All characters in the expression are displayed in lowercase.

>This character forces uppercase.

All characters in the expression are displayed in uppercase.

!This character forces placeholders to be filled from left to right. The default is right toleft.

Character Meaning

cDisplay the date as ddddd and the time as ttttt. Only the date is displayed if nofractional part exists in the numeric expression. Only the time is displayed if nointegral portion exists in the numeric expression.

d Display the day without a leading 0 (1-31).

dd Display the day with a leading 0 (01-31).

ddd Display the day of the week abbreviated (Sun-Sat).

dddd Display the day of the week (Sunday-Saturday).

dddddDisplay the date as a Short Date, as specified in the International section of theControl Panel.

ddddddDisplay the date as a Long Date, as specified in the International section of theControl Panel.

w Display the number of the day of the week (1-7). Sunday is 1; Saturday is 7.

ww Display the week of the year (1-53).

mDisplay the month without a leading 0 (1-12). If m immediately follows h or hh, m istreated as minutes (0-59).

mmDisplay the month with a leading 0 (01-12). If mm immediately follows h or hh, mmis treated as minutes with a leading 0 (00-59).

mmm Display the month abbreviated (Jan-Dec).

mmmm Display the month (January-December).

q Display the quarter of the year (1-4).

y Display the day of the year (1-366).

Page 58 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 59: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 59/139

Example:

Sub Main()

a# = 1199.234MbeMessageBox Format$(a,"General Number")MbeMessageBox Format$(a,"Currency")MbeMessageBox Format$(a,"Standard")MbeMessageBox Format$(a,"Fixed")MbeMessageBox Format$(a,"Percent")MbeMessageBox Format$(a,"Scientific")MbeMessageBox Format$(True,"Yes/No")MbeMessageBox Format$(True,"True/False")

MbeMessageBox Format$(True,"On/Off")da$ = Date$MbeMessageBox Format$(da,"General Date")MbeMessageBox Format$(da,"Long Date")MbeMessageBox Format$(da,"Medium Date")MbeMessageBox Format$(da,"Short Date")ti$ = Time$tiDouble# = TimeValue(ti)MbeMessageBox Format$(tiDouble,"Long Time")MbeMessageBox Format$(tiDouble,"Medium Time")MbeMessageBox Format$(tiDouble,"Short Time")A# = 12445601.234MbeMessageBox Format$(A,"0,0.00")

MbeMessageBox Format$(A,"##,###,###.###")End Sub

yy Display the year, not the century (00-99).

yyyy Display the year (1000-9999).

h Display the hour without a leading 0 (0-24).

hh Display the hour with a leading 0 (00-24).

n Display the minute without a leading 0 (0-59).

nn Display the minute with a leading 0 (00-59).

s Display the second without a leading 0 (0-59).

ss Display the second with a leading 0 (00-59).

tttttDisplay the time according the International section of the Control Panel. A leading 0is displayed if specified in the Control Panel.

AM/PM

Display the time using a 12-hour clock. Display an uppercase AM for time values

 before 12 noon. Display an uppercase PM for time values after 12 noon and before 12midnight.

am/pm Display the time using a 12-hour clock. and append a lowercase am or pm.

A/P Display the time using a 12-hour clock. and append an uppercase A or P.

a/p Display the time using a 12-hour clock. and append a lowercase a or p.

AMPMDisplay the time using a 12-hour clock. Display the string s1159 for values before 12noon and s2359 for values after 12 noon and before 12 midnight.

Page 59 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 60: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 60/139

FreeFile

FreeFile%[()]

Descr. Returns the next available file number. This number is suitable for use in the Open statement.

The value returned will always be between 1 and 255 inclusive.

Example:

Sub Main()

'This example assigns A to the next free file number and displays it'in a dialog box.A = FreeFileMbeMessageBox "The next free file number is: " + Str$(A)

End Sub

Function...End Function

Function name[(parameter [As type]...)] [As type]name = expression

End Function

Descr. Creates a user-defined function.

The return value is determined by the following statement:

name = expression

The name of the function follows BASIC naming conventions. It can include type-declarationcharacters: %, & and $.

If no assignment is encountered before the function exits, then 0 will be returned for numericfunctions, and an empty string will be returned for string functions.

The type of the return value is determined by the As type clause on the Function statement itself. Asan alternative, a type-declaration character can be added to the Function name:

Function Test() As StringTest = "Hello, World"

End FunctionFunction Test$()

Test = "Hello, World"End Function

Parameters are passed to a function by reference, meaning that any modifications to a passed parameter change that variable in the caller. To avoid this, simply enclose variable names in

 parentheses, as in the following example function calls:

i = UserFunction(10,12,(j))

Page 60 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 61: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 61/139

If a function is not to receive a parameter by reference, then the optional ByVal keyword can beused:

Function Test(ByVal filename As String) As Stringstatements

End Function

A function returns to the caller when either of the following statements is encountered:

End FunctionExit Function

Functions can be recursive.

Example:

Function Factorial(n%) As Integer

'This function calculates N! (N-factorial).f% = 1For i = n To 2 Step -1

f = f * iNext iFactoral = f

End FunctionSub Main()

'This example calls user-defined function Factorial and displays`the result in a dialog box.A% = 0Do While A% < 2

A% = MbeInputBox("Enter an integer number greater than 2: ")

NextB = factorial(A)MbeMessageBox "The factorial of " + Str$(A) + " is: " + Str$(B)

End Sub

Fv

Fv#(Rate#, Nper#, Pmt#,Pv#, Due%)

Descr. This function calculates the future value of an annuity based on periodic fixed payments and aconstant rate of interest.

An annuity is a series of fixed payments made to an insurance company or other investmentcompany over a period of time. Examples of annuities are mortgages and monthly savings plans.

Fv requires the following parameters:

Parameter Description

Ratea double-precision number representing the interest rate per period. Make sure that

annual rates are normalized for monthly periods (divided by 12).

 NPera double-precision number representing the total number of payments (periods) in theannuity.

Page 61 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 62: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 62/139

Rate and NPer values must be expressed in the same units. If Rate is expressed as a percentage permonth, then NPer must also be expressed in months. If Rate is an annual rate, then the NPer mustalso be given in years.

Positive numbers represent cash received, whereas negative numbers represent cash paid out.

Example:

Sub Main()

'This example calculates the future value of 100 dollars paid'periodically for a period of 10 years (120 months) at a rate of'10% per year (or .10/12 per month) with payments made on the'first of the month. The value is displayed in a dialog box.'Note that payments are negative values.a# = Fv((.10/12),120,-100.00,0,1)MbeMessageBox "Future value is: " + Format$(a,"Currency")

End Sub

Get

Get [#] filenumber% [,recordnumber%], variable

Descr. Retrieves data from a random or binary file and stores that data into the specified variable.

The variable parameter is the name of any variable of any of the following types:

Pmta double-precision number representing the amount of each payment per period.Payments are entered as negative values, whereas receipts are entered as positivevalues.

Pva double-precision number representing the present value of your annuity. In the caseof a loan, the present value would be the amount of the loan, whereas in the case of aretirement annuity, the present value would be the amount of the fund.

Dueindicates when payments are due for each payment period. A 0 specifies payment atthe end of each period, whereas a 1 indicates payment at the start of each period.

Variabletype

File storage description

Integer 2 bytes are read from the file.

Long 4 bytes are read from the file.

String

In binary files, variable-length strings are read by first determining the specifiedstring variable's length and then reading that many bytes from the file.In random files, variable-length strings are read by first reading a 2-byte length andthen reading that many characters from the file.

Double 8 bytes are read from file (IEEE format).Single 4 bytes are read from file (IEEE format).

Page 62 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 63: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 63/139

The optional recordnumber parameter specifies which record is to be read from the file. For binary files, this number represents the first byte to be read starting with the beginning of the file (the first

 byte is 1). For random files, this number represents the record number starting with the beginning ofthe file (the first record is 1). This value ranges from 1 to 2147483647. If recordnumber is notspecified, the next record is read from the file (if no records have been read yet, then the first recordin the file is read). If recordnumber is not specified, the commas must still appear, as in the followingexample:

Example:

Get #1,,recvar

If recordnumber is specified, it overrides any previous change in file position specified with the Seek statement.

With random files, a run-time error will occur if the length of the data being read exceeds the reclen parameter specified with the Open statement. If the length of the data being read is less than therecord length, the file pointer is advanced to the start of the next record. With binary files, the dataelements being read are contiguous--the file pointer is never advanced.

Example:

Const Crlf = Chr$(13) + Chr$(10)

Sub Main()'This example opens a file for random write, then writes 10'records into the file with the values 10...50. Then the file'is closed and reopened in random mode for read, and the'records are read with the Get statement. The result is displayed'in a dialog box.Open "Test2.Dat" For Random Access Write As #1For X% = 1 to 10

Y% = X * 10Put #1,X,Y

Next XClosePstr$ = ""Open "Test2.Dat" For Random Access Read As #1For Y = 1 to 5

Get #1,y,XPstr = Pstr + "Record " + Str$(Y) + ": " + Str$(X) + crlf

Next YMbeMessageBox Pstr

CloseEnd Sub

User-defined

Each member of a user-defined data type is read individually.In binary files, variable-length strings within user-defined types are read by firstreading a 2-byte length followed by the string's content. This storage is different fromvariable-length strings outside of user-defined types.When reading user-defined types, the record length must be greater than or equal tothe combined size of each element within the data type.

Arrays Arrays cannot be read from a file using the Get statement.

Objects Object variables cannot be read from a file using the Get statement.

Page 63 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 64: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 64/139

GetAttr

GetAttr%(filename$)

Descr. This function returns an Integer containing the attributes of the specified file.

The attribute value returned is the sum of the attribute bits set for the file. The value of each attributeis as follows:

To determine whether a particular attribute is set, you can And the values shown above with the value

returned by GetAttr. If the result is TRUE, the attribute is set.

Example:

Sub Main()

'This example tests to see whether Test2.DAT exists. If it does not,'then it creates the file. The file attributes are then'retrieved with the GetAttr function, and the result is displayed.If Not FileExists("Test2.Dat") Then

Open "Test2.Dat" For Random Access Write As #1Close

End IfMsg$ = ""Y% = GetAttr("Test2.Dat")If Y And ebNone Then Msg = Msg + "No Archive bit is set" + crlfIf Y And ebRead Then Msg = Msg + "The Read-Only bit is set" + crlfIf Y And ebHidden Then Msg = Msg + "The Hidden bit is set" + crlfIf Y And ebSystem Then Msg = Msg + "The System bit is set" + crlfIf Y And ebVolume Then Msg = Msg + "The Volume bit is set" + crlfIf Y And ebDirectory Then Msg = Msg + "The Directory bit is set" + crlfIf Y And ebArchive Then Msg = Msg + "The Archive bit is set"MbeMessageBox Msg

End Sub

Global

Constant Value Includes

ebNormal 0 Read-only, archive, subdir, none

ebReadOnly 1 Read-only files

ebHidden 2 Hidden files

ebSystem 4 System files

ebVolume 8 Volume label

ebDirectory 16 DOS subdirectories

ebArchive 32 Files that have changed since the last backup

ebNone 64 Files with no attributes

Page 64 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 65: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 65/139

Descr. See Public.

GoSub

GoSub label

Descr. This statement causes execution to continue at the specified label. Execution can later bereturned to the statement following the GoSub by using the Return statement.

The label parameter must be a label within the current function or subroutine. GoSub outside thecontext of the current function or subroutine is not allowed.

Example:

Sub Main()

'This example gets a name from the user and then branches`to a subroutine'to check the input. If the user clicks Cancel or enters a null name,'the program terminates; otherwise, the name is set to Michael,'and a message is displayed.UName$ = Ucase$(MbeInputBox$("Enter your name: "))GoSub CheckNameMbeMessageBox "Hello, " + UNameExit Sub

CheckName:If (UName$ = "") Then

GoSub BlankName

ElseIf UName = "MICHAEL" ThenGoSub RightName

ElseGoSub OtherName

End IfReturn

BlankName:MbeMessageBox "No name? Clicked Cancel? I'm shutting down"Exit Sub

RightName:Return

OtherName:MbeMessageBox "I am renaming you Michael!"

UName = "MICHAEL"ReturnEnd Sub

Goto

Goto label

Descr. Transfers execution to the line containing the specified label.

The compiler will produce an error if label does not exist.

Page 65 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 66: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 66/139

The label must appear within the same subroutine or function as the Goto.

Labels must begin with a letter and end with a colon. Keywords cannot be used as labels. Labels arenot case-sensitive.

Example:

Sub Main()

'This example gets a name from the user and then branches to`a statement,'depending on the input name. If the name is not Michael, it is reset'to Michael unless it is null or the user clicks Cancel--in which case,'the program displays a message and terminates.UName$ = Ucase$(MbeInputBox$("Enter your name: "))If Uname = "MICHAEL" Then

Goto RightNameElse

Goto WrongName

End If WrongName:If (UName$ = "") Then

MbeMessageBox "No name? Clicked Cancel? I'm shutting down"Else

MbeMessageBox "I am renaming you Michael!"UName = "MICHAEL"Goto RightName

End IfExit Sub

RightName:MbeMessageBox "Hello, Michael!"

End Sub

Hex$

Hex$(number&)

Descr. Returns a string containing the hexadecimal equivalent of the specified number.

The returned string contains only the number of hexadecimal digits necessary to represent thenumber, up to a maximum of eight.

The number parameter can be any type but is rounded to the nearest whole number before convertingto hex. If the passed number is an Integer, then a maximum of four digits are returned; otherwise,up to eight digits can be returned.

Example:

Sub Main()

'This example inputs a number and displays it in decimal and'hex until the input number is 0 or an invalid input.

Do XS$ = MbeInputBox$("Enter a number: ")X = Val(XS)If X <> 0 Then

Page 66 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 67: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 67/139

  MbeMessageBox "Dec:" + Str$(X) + " Hex: " + Hex$(X)Else

MbeMessageBox "Terminating program"End If

Loop While X <> 0End Sub

Hour

Hour%(serial#)

Descr. Returns the hour of the day encoded in the specified serial parameter. The value returned is between 0 and 23 inclusive.

Example:

Sub Main()

'This example takes the current time; extracts the hour,'minute, and second; and displays them as the current time.XT# = TimeValue(Time$())XH# = Hour(XT)XM# = Minute(XT)XS# = Second(XT)MbeMessageBox "Current time is: " + Str$(XH)+":"+Str$(XM)+":"+Str$(XS)

End Sub

If...Then...Else

Syntax 1

If condition Then statement [Else statement]

Syntax 2

If condition Then[statement]

[ElseIf condition Then[statement]]

[Else[statement]]

End If

Descr. Conditionally executes a statement or group of statements.

In the single-line version, the statement can either be a single statement, or many statements can beseparated using the colon (:).

Example:

Sub Main()

'This example inputs a name from the user and checks to see whether it'is Michael or Mike using three forms of

Page 67 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 68: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 68/139

  `the If...Then...Else statement.'It then branches to a statement that displays a welcome message'depending on the user's name.UName$ = Ucase$(MbeInputBox$("Enter your name: "))If UName$ = "MICHAEL" Then GoSub MikeNameIf UName = "MIKE" Then

GoSub MikeNameExit Sub

End IfIf UName = "" Then

MbeMessageBox ("Your name can't be <null>; I'll call you Mike!")UName = "MIKE"GoSub MikeName

ElseIf UName = "MICHAEL" ThenGoSub MikeName

ElseGoSub OtherName

End IfExit Sub

MikeName:MbeMessageBox "Hello, Michael!"

ReturnOtherName:

MbeMessageBox "Hello, " + UName + "!"Return

End Sub

Imp

expression1 Imp expression2

Descr. If both operands are relational, then Imp returns the logical implication of expression1 andexpression2. Imp returns FALSE when expression1 is TRUE and expression2 is FALSE; otherwise, Impreturns TRUE.

If both operands are numeric, then the result is the bitwise Imp of the arguments.

If either of the two operands is a floating-point number, then the two operands are first converted toLongs, then a bitwise Imp is performed.

For numeric operands, bitwise Imp works as follows:

Example:

Sub Main()

Bit in expression1 Bit in expression2 Bit in result

1 1 1

0 1 1

1 0 0

0 0 1

Page 68 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 69: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 69/139

  'This example compares the result of two expressions to determine'whether one implies the other.a=10b=20c=30d=40If (a < b) Imp (c < d) Then

MbeMessageBox "a is less than b implies that c is less than d"

ElseMbeMessageBox "a is less than b does not imply that c is" + _

"less than d"End IfIf (a < b) Imp (c > d) Then

MbeMessageBox "a is less than b implies that c is" + _"greater than d"

ElseMbeMessageBox "a is less than b does not imply that c is" + _

"greater than d"End If

End Sub

Input #

Input [#]filenumber%, variable[,variable]...

Descr. This statement reads data from the file referenced by filenumber into the given variables.

Each variable must be type-matched to the data in the file. For example, a string variable must bematched to a string in the file.

The following parsing rules are observed while reading each variable in the variable list:

1. Leading white space is ignored (spaces and tabs).2. When reading strings, if the first character on the line is a quotation mark, then characters are

read up to the next quotation mark or the end-of-line, whichever comes first. Blank lines areread as empty strings. If the first character read is not a double quotation mark, then charactersare read up to the first comma or the end of the line, whichever comes first. String delimiters(quotation mark, comma or end-of-line) are not included in the returned string.

3. When reading numbers, scanning stops when the first non-numerical character (such as acomma, a letter, or any other unexpected character) is encountered. Numeric errors are ignored

while reading numbers from a file. The resultant number is automatically converted to thesame type as the variable into which the value will be placed. If there is an error in conversion,then 0 is stored into the variable.

4. End of line is interpreted as either a single line feed or a carriage-return line-feed pair. Thus,text files from any platform can be interpreted using this command.

The filenumber parameter is a number that is used to refer to the open file--the number passed to theOpen statement.

filenumber must reference a file opened in Input mode. It is good practice to use the Write statement to write date elements to files read with the Input statement to ensure that the variable list

is consistent between the input and output routines.

Example:

Page 69 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 70: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 70/139

Sub Main()

'This example creates a file called Test2.Dat and writes a series of'variables into it. Then the variables are read using`the Input # function.Open "Test2.Dat" for output as #1C$ = MbeInputBox$("Enter some text: ")A# = 10.0

 Write #1,A,C,192, A+20CloseOpen "Test2.Dat" for input as #1Input #1,X%,ST$,Y%,Z%

MbeMessageBox "Recrd: + Str$(X) + " " + ST + " " + Str$(Y) + " " + Str$(Z)Close

End Sub

Input$

Input$(numbytes%,[#]filenumber%)

Descr. Returns a character string containing numbytes characters read from a given sequential file.

The Input$ function reads all characters, including spaces and end-of-lines.

The filenumber parameter must reference a file opened in either Input or Binary mode. filenumberis a number that is used to refer to the open file--the number passed to the Open statement.

Example:

Sub Main()

'This example opens the Autoexec.Bat file and displays it in a'dialog box.X = FileLen("C:\Autoexec.Bat")If X > 0 Then

Open "C:\Autoexec.Bat" for input as #1Else

MbeMessageBox "File not found or empty"Exit Sub

End IfIf X > 80 Then

Ins$ = Input$ (80,#1)Else

Ins = Input$ (X,#1)End IfCloseMbeMessageBox "File length: " + Str$(X) + Chr$(13) + Chr$(10) + Ins

End Sub

InStr

InStr([start%,] search$, find$ [,compare%])

Descr. Returns the first character position of string find$ within string search$.

Page 70 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 71: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 71/139

If the string is found, then its character position within search$ is returned, with 1 being the character position of the first character.

If start is specified, then the search starts at that character position within search$. The start parameter must be between 1 and 65535. If not specified, then the search starts at the beginning(start = 1).

If the string is not found or start is greater than the length of search$ or search$ is empty, then 0 isreturned.

The compare parameter controls how the strings are compared:

If compare is not specified, then string comparisons use the current Option Compare setting. If noOption Compare statement has been encountered, then Binary is used (i.e., string comparisons arecase-sensitive).

Example:

Sub Main()

'This example checks to see whether one string is in another and,'if it is, then it copies the string to a variable and displays the'result.

A$ = "This string contains the name Stuart and other characters"X% = InStr (A$,"Stuart",0)Y% = InStr (A$,"Stuart",1)If X <> 0 Then

B$ = Mid$(A$,X,6)MbeMessageBox B + " was found--same case"Exit Sub

ElseIf Y <> 0 ThenB$ = Mid$(A$,Y,6)MbeMessageBox B + " was found--different case"ExitSub

ElseMbeMessageBox "String not found"

End IfEnd Sub

Int

Int%(number#)

Descr. This function returns the integer part of a given value by returning the first integer less thanthe given value, sign is preserved.

Int differs from the Fix function, in that Int truncates negative numbers in a negative direction.

0 String comparisons are case-sensitive.

1 String comparisons are case-insensitive.

Any other value A run-time error is produced.

Page 71 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 72: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 72/139

Example:

Sub Main()

'This example extracts the integer part of a number.A# = -1234.5224B% = Int (A)

MbeMessageBox "The integer part of -1234.5224 is: " + Str$(B)End Sub

The output of the previous example is: -1235.

IPmt

IPmt#(rate#, per#, nper#, pv#, fv#, due%)

Descr. This function returns the interest payment for a given period of an annuity based on periodic,fixed payments and a fixed interest rate.

An annuity is a series of fixed payments made to an insurance company or other investmentcompany over a period of time. Examples of annuities are mortgages, monthly savings plans andretirement plans.

The following table describes the different parameters:

Parameter Description

RateA double-precision number that represents the interest rate per period. If the payment

 periods are monthly, be sure to divide the annual interest rate by 12 to get themonthly rate.

PerA double-precision number that represents the payment period for which you arecalculating the interest payment. If you want to know the interest paid or receivedduring period 20 of an annuity, this value would be 20.

 NPerA double-precision number that represents the total number of payments in theannuity. This is usually expressed in months, and you should be sure that the interestrate given above is for the same period that you enter here.

Pv

A double-precision number that represents the present value of your annuity. In thecase of a loan, the present value would be the amount of the loan because that is theamount of cash you have in the present. In the case of a retirement plan, this valuewould be the current value of the fund because you have a set amount of principal inthe plan.

Fv

A double-precision number that represents the future value of your annuity. In thecase of a loan, the future value would be zero because you will have paid it off. In thecase of a savings plan, the future value would be the balance of the account after all

 payments are made.

Due

A parameter that indicates when payments are due. If this parameter is 0, then

 payments are due at the end of each period (usually, the end of the month). If thisvalue is 1, then payments are due at the start of each period (the beginning of themonth).

Page 72 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 73: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 73/139

Rate and Nper must be in expressed in the same units. If Rate is expressed in percentage paid permonth, then NPer must also be expressed in months. If Rate is an annual rate, then the period givenin Nper should also be in years or the annual Rate should be divided by 12 to represent a monthlyrate.

If the function returns a negative value, it represents interest you are paying out, whereas positivevalues represent interest paid to you.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example calculates the amount of interest paid`on a $1,000.00 loan financed over 36 months with an`annual interest rate of 10%. Payments are due at the beginning of`the month. The interest paid during the first 10 months`is displayed in a table.Msg = ""

For x = 1 to 10IPM# = IPmt((.10/12) , x, 36, 1000, 0, 1)Msg = Msg + Format$(X,"00") + " : " + Format$(IPM," 0,0.00") + crlf

Next xMbeMessageBox Msg

End Sub

IRR

IRR#(ValueArray#(), Guess#)

Descr. This function returns the internal rate of return for a series of periodic payments and receipts.

The internal rate of return is the equivalent rate of interest for an investment consisting of a series of positive and/or negative cash flows over a period of regular intervals. It is usually used to project therate of return on a business investment that requires a capital investment up front and a series ofinvestments and returns on investment over time.

IRR  requires the following parameters:

The value of IRR  is found by iteration. It starts with the value of Guess and cycles through thecalculation adjusting Guess until the result is accurate within 0.00001 percent. After 20 tries, if aresult cannot be found, IRR  fails, and the user must pick a better guess.

Parameter Description

ValueArray()

An array of double-precision numbers that represent payments and receipts. Positivevalues are payments, and negative values are receipts.There must be at least one positive and one negative value to indicate the initialinvestment (negative value) and the amount earned by the investment (positivevalue).

GuessA number you guess as the value that the IRR function will return. The mostcommon guess is .1 (10 percent).

Page 73 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 74: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 74/139

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example illustrates the purchase of a lemonade stand for $800'and a series of incomes from the sale of lemonade over 12 months.

'The projected incomes for this example are generated in two'For...Next Loops, and then the internal rate of return is calculated'and displayed. (Not a bad investment!)Dim Valu#(12)

 Valu(1) = - 800 'initial investmentPStr$ = Str$(Valu(1)) + ", "'Calculate the second through fifth months' sales.For X = 2 To 5

 Valu(X) = 100 + (X*2)PStr = PStr + Str$(Valu(X)) + ", "

Next x'Calcluate the sixth through twelfth months' sales.For X = 6 To 12

 Valu(X) = 100 + (X*10)PStr = PStr + Str$(Valu(X)) + ", "Next x'Calcluate the equivalent investment return rate.Retrn# = IRR(Valu,.1)PStr = "The values: " + crlf + PStr + crlf + crlfMbeMessageBox PStr + "Return rate: " + Format$(Retrn,"Percent")

End Sub

Is

object Is [object | Nothing]

Descr. The Is operator returns TRUE if the two operands refer to the same object; otherwise, it returnsFALSE.

This operator is used to determine whether two object variables refer to the same object. Bothoperands must be object variables of the same type (i.e., the same application-defined object type or

 both of type object).

The reserved word Nothing can be used to determine whether an object variable is uninitialized.

Uninitialized object variables reference no object.

Item$

Item$(text$, first%, last% [, delimiters$])

Descr. Returns all the items between first and last within the specified formatted text list.

An item is a substring of a delimited text string delimited by commas, end-of-lines or user-defineddelimiters. The first parameter specifies the first item in the sequence to return. All items betweenfirst and last are returned.

Page 74 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 75: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 75/139

By default, items are separated by commas and end of lines. This can be changed by specifyingdifferent delimiters in the delimiters$ parameter.

If first is greater than the number of items in text$, then an empty string is returned.

If last is greater than the number of items in text$, then all items from first to the end of text are

returned.

Example:

Const Crlf = Chr$(13) + Chr$(10)

Sub Main()'This example creates two delimited lists and extracts a range from'each, then displays the result in a dialog box.IList$ = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"SList$ = "1/2/3/4/5/6/7/8/9/10/11/12/13/14/15"R5List$ = Item$(IList,5,12)R2List$ = Item$(SList,2,9,"/")MbeMessageBox "Returned lists are: " + crlf + R5List + crlf + R2List

End Sub

ItemCount

ItemCount%(text$ [, delimiters$])

Descr. Returns the number of items in the specified delimited text.

Items are substrings of a delimited text string. By default, items are separated by commas and/orend-of-lines. This can be changed by specifying different delimiters in the delimiters$ parameter. Forexample, to parse items using a backslash:

n = ItemCount(text$,"\")

Example:

Sub Main()

'This example creates two delimited lists and then counts the number

'of items in each. The counts are displayed in a dialog box.IList$ = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"SList$ = "1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19"R1% = ItemCount(IList)R2% = ItemCount(SList,"/")MbeMessageBox "Lists contain: " + Str$(R1) +" and " + Str$(R2) +" items"

End Sub

Kill

Kill filespec$

Descr. Deletes all files matching filespec$.

Page 75 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 76: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 76/139

The filespec$ argument can include wild cards, such as * and ?. The * character matches anysequence of zero or more characters, whereas the ? character matches any single character. Multiple*'s and ?'s can appear within the expression to form complex searching patterns. The following tableshows some examples:

Example:

Sub Main()

'This example looks to see whether file Test1.Dat exists.'If it does not, then it creates both Test1 and Test2.Dat.'The existence of the files is tested again; if they exist,

'a message is generated, and then they are deleted. The final'test looks to see whether they are still'there and displays the result.If Not FileExists("Test1.Dat") Then

Open "Test1.Dat" For Output As #1Open "Test2.Dat" For Output As #2Close

End IfIf FileExists ("Test1.Dat") Then

MbeMessageBox "File Test1.Dat exists"Kill "Test?.Dat"

End IfIf FileExists ("Test1.Dat") Then

MbeMessageBox "File Test1.Dat still exists"ElseMbeMessageBox "Test?.Dat successfully deleted"

End IfEnd Sub

LBound

LBound%(ArrayVariable() [, dimension%])

Descr. Returns the lower bound of the specified dimension of the specified array variable.

If dimension is not specified, the first dimension is assumed (i.e., dimension = 1).

This pattern Matches these files Doesn't match these files

*S*.TXTSAMPLE.TXTGOOSE.TXTSAMS.TXT

SAMPLESAMPLE.DAT

C*T.TXTCAT.TXTACATS.TXT

CAP.TXT

C*TCATCAP.TXT

CAT.DOC

C?TCATCUTCT

CAT.TXT

CAPIT

* (All files)

Page 76 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 77: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 77/139

Example:

Sub Main()

'This example dimensions two arrays and displays their lower bounds.Dim A(5 To 12)Dim B(2 To 100, 9 To 20)

LBa = LBound(A)LBb = LBound(B,2)MbeMessageBox "Lowr bnd A: " + Str$(LBa) + " Lowr bnd B: " + Str$(LBb)'This example uses LBound and UBound to dimension a dynamic array to'hold a copy of an array redimmed by the FileList statement.Dim FL$()FileList FL,"*.*"count = UBound(FL)Redim NL$(LBound(FL) To UBound(FL))For X = 1 To count

NL(X) = FL(X)Next xMbeMessageBox "The last element of the new array is: " + NL(count)

End Sub

LCase$

LCase$(str)

Descr. Returns the lowercase equivalent of the specified string.

Example:

Sub Main()

'This example shows the LCase function used to change uppercase'names to lowercase with an uppercase first letter.Lname$ = "WILLIAMS"Fl$ = Left$(Lname,1)Rest$ = Mid$(Lname,2,Len(Lname))Lname = Fl + LCase$(Rest)MbeMessageBox "The converted name is: " + Lname

End Sub

Left$

Left$(str$, NumChars%)

Descr. Returns the leftmost NumChars characters from a given string.

If NumChars is 0, then an empty string is returned.

If NumChars is greater than or equal to the number of characters in the specified string, the entire

string is returned.

Example:

Page 77 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 78: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 78/139

Sub Main()

'This example shows the Left$ function used to change uppercase'names to lowercase with an uppercase first letter.Lname$ = "WILLIAMS"Fl$ = Left$(Lname,1)Rest$ = Mid$(Lname,2,Len(Lname))Lname = Fl + LCase$(Rest)MbeMessageBox "The converted name is: " + Lname

End Sub

Len

Len%(str$)Len%(variable)

Descr. Returns the number of characters in a given string, or 0 if the string is empty.

If used with a non-String variable, Len returns the number of bytes occupied by that variable.

When used with user-defined data types, the function returns the combined size of each memberwithin the structure. Since variable-length strings are stored elsewhere, the size of each variable-length string within a structure is 2 bytes.

The following table describes the sizes of the individual data elements:

The Len function always returns 0 with object variables or any application-defined object variable.

Example:

Data

elementSize

Integer 2 bytes.

Long 4 bytes.

Float 4 bytes.

Double 8 bytes.

String Number of characters in the string.

Objects0 bytes. Both application-defined object variables and variables of type object are

always returned as 0 size.User-definedtype

Combined size of each structure member element.

Variable-length strings within structures require 2 bytes of storage. Arrays withinstructures are fixed in their dimensions. The elements for fixed arrays are storedwithin the structure and therefore require the number of bytes for each array elementmultiplied by each array dimension:array_element_size * dimension1 * dimension2...

Page 78 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 79: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 79/139

Const Crl = Chr$(13) + Chr$(10)

Sub Main()'This example shows the Len function used in a routine to change'uppercase names to lowercase with an uppercase first letter.Lname$ = "WILLIAMS"Fl$ = Left$(Lname,1)Ln% = Len(Lname)Rest$ = Mid$(Lname,2,Ln)Lname = Fl + LCase$(Rest)MbeMessageBox "The converted name is: " + Lname'This example returns a table of lengths for standard numeric types.Dim Lns(4)A% = 100B& = 200C! = 200.22D# = 300.22Lns(1) = Len(A)Lns(2) = Len(B)Lns(3) = Len(C)Lns(4) = Len(D)

Pstr$ = "Lengths of standard types:" + crlfPstr = Pstr + "Integer: " + Str$(Lns(1)) + crlfPstr = Pstr + "Long: " + Str$(Lns(2)) + crlfPstr = Pstr + "Single: " + Str$(Lns(3)) + crlfPstr = Pstr + "Double: " + Str$(Lns(4)) + crlfMbeMessageBox Pstr

End Sub

Let

[Let] variable = expression

Descr. Assigns the result of an expression to a variable.

Let is supported for compatibility with other implementations of BASIC.

Example:

Sub Main()

Let A$ = "This is a String"Let B% = 100Let C# = 1213.3443

End Sub

Like

expression$ Like pattern$

Descr. The Like operator compares two strings, returning TRUE if expression$ matches the given pattern$. FALSE is returned if the match fails at any point.

Case sensitivity is controlled by the Option Compare setting.

Page 79 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 80: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 80/139

 pattern$ can contain special characters that allow more flexible matching:

A range specifies a grouping of characters. To specify a match of any of a group of characters, usethe syntax [ABCDE]. To specify a range of characters, use the syntax [A-Z]. Special characters mustappear within brackets, such as []*?#.

The following table shows some examples:

Example:

Sub Main()

'This example demonstrates various uses of the Like function.A$ = "This is a string variable of 123456 characters"B$ = "123.45"If A Like "[A-Z][g-i]*" Then MbeMessageBox "Comparison is True"If B Like "##3.##" Then MbeMessageBox "Comparison is True"If A Like "*variable" Then MbeMessageBox "Comparison is True"

End Sub

Line Input #

Line Input [#]filenumber%, text$

Descr. This statement reads an entire line into the given string variable text$.

The file is read up to the next end of line, but the end-of-line (EOL) character(s) are not returned in

the string. The file pointer is positioned after the terminating end of line.

The filenumber parameter is a number that is used to refer to the open file--the number passed to the

Character Evaluates to

? Matches a single character.

* Matches one or more characters.

# Matches any digit.

[range] Matches if the character in question is within the specified range.

[!range] Matches if the character in question is not within the specified range.

expression$ pattern$ (True) pattern$ (False)

"MBE" "M*E", "M*" "M* B"

"MicroStation" "M*[a-e]roStation" "M[a-e]ro"

"Version" "V[e]?s*n" "V[r]?s*N"

"5.0" "#.#","#?#" "###", "#?[!0-9]"

"[ABC]" "[[]*]" "[ABC]", "[*]"

Page 80 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 81: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 81/139

Open statement. filenumber must reference a file opened in Input mode.

The text$ parameter is any string variable reference. This statement will automatically declare thevariable if the specified variable has not yet been used or dimensioned.

This statement recognizes either a single line-feed or a carriage-return line-feed pair as the EOL

delimiter.

Example:

Const Crlf = Chr$(13) + Chr$(10)

Sub Main()'This example reads five lines of the Autoexec.Bat file and'displays them in a dialog box.Open "C:\Autoexec.Bat" For Input As #1For X = 1 To 5

Line Input # 1,Lin$Msg$ = Msg + Lin$ + crlf

Next xMbeMessageBox Msg

End Sub

Line$

Line$(text$, first%[, last%])

Descr. Returns a single line or a group of lines from a text buffer between first and last.

Lines are delimited by carriage-return line-feed pairs.

If last is not specified, only one line is returned.

If first is greater than the number of lines in text$, an empty string is returned.

If last is greater than the number of lines in text$, all lines from first to the end of the text arereturned.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example reads five lines of the Autoexec.Bat file, extracts the`third and fourth lines with the Line$ function, and displays them`in a dialog box.Txt$ = NullOpen "C:\Autoexec.Bat" For Input As #1For X = 1 To 5

Line Input # 1,Lin$Txt = Txt + Lin+ crlf

Next xLines$ = Line$(Txt,3,4)MbeMessageBox Lines

End Sub

Page 81 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 82: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 82/139

LineCount

LineCount%(text$)

Descr. Returns the number of lines in the specified text file.

Lines are delimited by carriage-return, line-feed, or both.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()Txt$ = NullX = 1Open "C:\Autoexec.Bat" For Input As #1

 While (X < 20) And Not EOF(1)Line Input # 1,Lin$Txt = Txt + Lin + crlfX = X + 1

 WendLines! = LineCount(Txt)MbeMessageBox "Number of lines"MbeMessageBox "in Txt is: " + Str$(Lines) + crlf + crlf + Txt

End Sub

Loc

Loc%(filenumber%)

Descr. Returns the position of the file pointer in the given file.

The filenumber parameter is a number that is used to refer to the open file--the number passed to theOpen statement.

The Loc function returns different values depending on the mode in which the file was opened:

Example:

Const crlf = Chr$(13) + Chr$(10)

File mode Returns

Input current byte position divided by 128.

Output current byte position divided by 128.

Append current byte position divided by 128.

Binary position of the last byte read or written.

Random number of the last record read or written.

Page 82 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 83: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 83/139

 Sub Main()'This example reads 25 lines of the Autoexec.Bat file, determines the`current location of the file pointer, and displays it in a`dialog box.Open "C:\Autoexec.Bat" For Input As #1For X = 1 To 25

If Not EOF(1) ThenLine Input # 1,Lin$

Msg$ = Msg + Lin$ + crlfEnd If

Next xLc% = Loc(1)CloseMbeMessageBox "The file location is: " + Str$(Lc)

End Sub

Lock

Lock [#] filenumber% [,{record& | [start&] To end&}]

Descr. The Lock  statement locks a section of the specified file, preventing other processes fromaccessing that section of the file until the Unlock  statement is issued.

The filenumber parameter is a number that is used to refer to the open file--the number passed to theOpen statement.

For sequential files, the record, start and end parameters are ignored. The entire file is locked.

The section of the file is specified using one of the following:

The lock range must be the same as that used to subsequently unlock the file range, and all lockedranges must be unlocked before the file is closed. Ranges within files are not unlocked automaticallywhen your script terminates, which can cause file access problems for other processes. It is a goodidea to group the Lock  and Unlock  statements close together in the code, both for readability and sosubsequent readers can see that the lock and unlock are performed on the same range. This practicealso reduces errors in file locks.

Example:

Const Crlf = Chr$(13) + Chr$(10)

Sub Main()

Syntax Description

 No parameters

Lock the entire file (no record specification is given).

record& Lock the specified record number (for Random files) or byte (for Binary files).

to end&Lock from the beginning of the file to the specified record (for Random files) or

 byte (for Binary files).

start& toend& Lock the specified range of records (for Random files) or bytes (for Binary files).

Page 83 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 84: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 84/139

  'This example creates Test2.Dat and fills it with 10 string'variable records. These are displayed in a dialog box. The file'is then reopened for read/write, and each record is locked,'modified, rewritten, and unlocked. The new records are then'displayed in a dialog box.A$ = "This is record number: "B$ = "0"Rec$ = ""

Msg$ = ""Open "Test2.Dat" For Random Access Write Shared As #1For x% = 1 To 10

Rec = A + Str$(x)Lock #1,xPut #1,,RecUnlock #1,xMsg = Msg + Rec + crlf

Next xCloseMbeMessageBox "The records are: " + crlf + MsgMsg = ""Open "Test2.Dat" For Random Access Read Write Shared As #1

For x = 1 To 10Rec = Mid$(Rec,1,23) + Str$(11-x)Lock #1,xPut #1,x,RecUnlock #1,xMsg = Msg + Rec + crlf

Next xMbeMessageBox "The records are: " + crlf + MsgClose

End Sub

Lof

Lof%(filenumber%)

Descr. Returns the number of bytes in the given file.

The filenumber parameter is a number that is used to refer to the open file--the number passed to theOpen statement.

The file must currently be open.

Example:

Const Crlf = Chr$(13) + Chr$(10)

Sub Main()'This example creates a test file, writes 10 records into it,'then finds the length of the file and displays it in a message box.A$ = "This is record number: "Rec$ = NullMsg$ = NullOpen "Test2.Dat" For Random Access Write Shared As #1

For x% = 1 To 10Rec = A + Str$(x)Put #1,,RecMsg = Msg + Rec + crlf

Page 84 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 85: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 85/139

  Next xCloseOpen "Test2.Dat" For Random Access Read Write Shared As #1X% = Lof(1)CloseMbeMessageBox "The length of Test2.Dat is: " + Str$(X)

End Sub

Log

Log#(number#)

Descr. Returns the natural logarithm of a given number.

The value of number must be greater than 0. The value of e is 2.71828.

Example:

Sub Main()

'This example calculates the natural log of 100 and displays it in'a message box.X# = Log(100)MbeMessageBox "The natural logarithm of 100 is: " + Str$(X)

End Sub

LSet

LSet dest$ = source$LSet dest_udt_variable = source_udt_variable

Descr. In syntax 1, the LSet statement copies the source string source$ into the destination stringdest$. If source$ is shorter in length than dest$, then the string is left-aligned within dest$, and theremaining characters are padded with spaces. If source$ is longer in length than dest$, then source$is truncated, copying only the leftmost number of characters that will fit in dest$.

In syntax 2, the source structure is copied byte for byte into the destination structure. This is useful

for copying structures of different types. Only the number of bytes of the smaller of the twostructures is copied. Neither the source structure nor the destination structure can contain strings.

Example:

Const Crlf = Chr$(13) + Chr$(10)

Sub Main()'This example replaces a 40-character string of asterisks (*) with'an RSet and LSet string and then displays the result.Dim Msg$, TmpStr$TmpStr = String$(40, "*")

Msg = "Here are two strings that have been right-" + crlfMsg = Msg + "and left-justified in a 40-character string"Msg = Msg + crlf + crlfRSet TmpStr = "Right->"

Page 85 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 86: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 86/139

  Msg = Msg & TmpStr & crlfLSet TmpStr = "<-Left"Msg = Msg & TmpStr & crlfMbeMessageBox Msg

End Sub

LTrim$

LTrim$(str$)

Descr. Returns the specified string with leading spaces removed.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example displays a right-justified string and its LTrim result.A$ = " <= This is a right-justified string"B$ = LTrim$(A)MbeMessageBox A + crlf + B

End Sub

Main

Sub Main()End Sub

Descr. This defines the subroutine that receives execution control from the host application.

Example:

Sub Main()

MbeMessageBox "This is a Main subroutine"End Sub

Mid$

Mid$(str$, start% [, length%])Mid$(str$, start%[, length%]) = newvalue$

Descr. The Mid$ function returns a substring of the specified string, beginning with start, for lengthcharacters. The statement form of Mid$ replaces one part of a string with another.

If length is not specified, then the entire string, starting at start, is returned or replaced.

If start is greater than the length of str$, then an empty string is returned.

Page 86 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 87: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 87/139

The str$ parameter specifies the string variable containing the substring to be copied or replaced. Thesubstring within str$ to be operated on starts at the character position specified by start for lengthnumber of characters. If length is not specified, then the rest of the string is assumed.

The newvalue$ parameter is any string or string expression to be inserted into the target string. Theresultant string is never longer than the original length of str$.

Example:

Const Crlf = Chr$(13) + Chr$(10)

Sub Main()'This example displays a substring from the middle of a string'variable using the Mid$ function and replaces the first four'characters with "NEW " using the Mid$ statement.A$ = "This is the Main string containing text"B$ = Mid$(A,13,Len(A$))Mid$ (B,1) = "NEW "MbeMessageBox A + crlf + B

End Sub

Minute

Minute%(serial#)

Descr. Returns the minute of the hour encoded in the specified serial parameter. The value returnedis between 0 and 59 inclusive.

Example:

Sub Main()

'This example takes the current time; extracts the hour,'minute, and second; and displays them as the current time.XT# = TimeValue(Time$())XH# = Hour(XT)XM# = Minute(XT)XS# = Second(XT)MbeMessageBox "Current time is: " + Str$(XH)+":"+Str$(XM)+":"+Str$(XS)

End Sub

MIRR

MIRR#(ValueArray#(), FinanceRate#, ReinvestRate#)

Descr. This function returns the modified internal rate of return for a series of periodic payments andreceipts.

The modified internal rate of return is the equivalent rate of return on an investment in which payments and receipts are financed at different rates. The interest cost of investment and the rate ofinterest received on the returns on investment are both factors in the calculations.

Page 87 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 88: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 88/139

The MIRR  function requires the following parameters:

FinanceRate and ReinvestRate should be expressed as percentages. For example, 11 percent should be expressed as 0.11.

To return the correct value, be sure to order your payments and receipts in the correct sequence.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example illustrates the purchase of a lemonade stand for $800'financed with money borrowed at 10%. The returns are estimated to'accelerate as the stand gains popularity. The proceeds are placed'in a bank at 9 percent interest. The incomes are estimated

'(generated) over 12 months. This program first generates the'income stream array in two For...Next loops, and then the modified'internal rate of return is calculated and displayed. Notice that the`annual rates are normalized to monthly rates by dividing them by 12.Dim Valu#(12)

 Valu(1) = -800 'initial investmentPStr$ = Str$(Valu(1)) + ", "For X = 2 To 5

 Valu(X) = 100 + (X*2) 'incomes months 2-5PStr = PStr + Str$(Valu(X)) + ", "

Next xFor X = 6 To 12

 Valu(X) = 100 + (X*10) 'incomes months 6-12

PStr = PStr + Str$(Valu(X)) + ", "Next xRetrn# = MIRR (Valu,.1/12,.09/12) 'note: normalized annual ratesPStr = "The values: " + crlf + PStr + crlf + crlfMbeMessageBox PStr + "Modified rate: " + Format$(Retrn,"Percent")

End Sub

MkDir

MkDir dir$

Descr. Creates a new directory as specified by dir$.

Parameter Description

ValueArray

()

An array of double-precision numbers representing the payments and receipts.Positive values are payments (invested capital), and negative values are receipts(returns on investment).There must be at least one positive (investment) value and one negative (return)value

FinanceRateA double-precision number representing the interest rate paid on invested monies(paid out).

ReinvestRateA double-precision number representing the rate of interest received on incomesfrom the investment (receipts).

Page 88 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 89: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 89/139

Example:

Sub Main()

'This example creates a new directory on the default drive. If'this causes an error 70, then the directory already exists and'the program terminates. If no error, the directory is removed

'with the RmDir statement.On Error Resume NextMkDir "TestDir"If Err = 70 Then 'Check whether directory exists.

Msg$ = "Directory exists! Error: " + Str$(Err)RmDir "TestDir"

ElseMsg = "TestDir created. Error: " + Str$(Err)

End IfMbeMessageBox Msg

End Sub

Mod

expression1 Mod expression2

Descr. Returns the remainder of expression1 /expression2 as a whole number.

Both operands are converted to whole numbers before performing the modulo operation.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example uses the Mod operator to determine the value of a'randomly selected card where card 1 is the ace (1) of clubs and'card 52 is the king (13) of spades. Since the values recur in a'sequence of 13 cards within 4 suits, we can use the Mod function to'determine the value of any given card number.CVal$="ACE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,JACK,QUEEN,KING"RandomizeCard% = Random(1,52)

 Value = Card Mod 13

If Value = 0 Then Value = 13CardNum$ = Item$(Cval,Value)If Card < 53 Then Suit$ = "spades"If Card < 40 Then Suit$ = "hearts"If Card < 27 Then Suit$ = "diamonds"If Card < 14 Then Suit$ = "clubs"Msg$ = "Card number " + Str$(Card) + " is the "Msg$ = Msg$ + CardNum + " of " + SuitMbeMessageBox Msg

End Sub

Month

Page 89 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 90: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 90/139

Month%(serial#)

Descr. Returns the month of the date encoded in the specified serial parameter. The value returned is between 1 and 12 inclusive. The serial value for a text formatted date can be obtained with theDateValue function.

Example:

Sub Main()

'This example returns the current month in a dialog box.Dim TDay as LongMons$ = "Jan., Feb., Mar., Apr., May, Jun., Jul., Aug., Sep., Oct., Nov

., Dec."Tdate$ = Date$TDay! = Month(DateValue(Tdate))MbeMessageBox ("The current month is: " + Item$(Mons,TDay))

End Sub

Name

Name oldfile$ As newfile$

Descr. Renames a file.

Each parameter must specify a single filename. Wild-card characters such as * and ? are not allowed.

Example:

Sub Main()

'This example creates a file called Test.Dat and then renames'it to Test2.Dat.On Error Resume NextIf FileExists ("Test.Dat") Then

Name "Test.Dat" As "Test2.Dat"If Err <> 0 Then

Msg$ = "File exists and cannot be renamed! Error: " + Str$(Err)Else

Msg = "File exists and renamed to Test2.Dat"

End IfElse

Open "Test.Dat" For Output As #1CloseName "Test.Dat" As "Test2.Dat"If Err <> 0 Then

Msg$ = "File created but not renamed! Error: " + Sr$(Err)Else

Msg = "File created and renamed to Test2.Dat"End If

End IfMbeMessageBox Msg

End Sub

Not

Page 90 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 91: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 91/139

 Not expression1

Descr. TRUE if expression1 is FALSE; otherwise, returns FALSE.

If the operand is numeric, then the result is the bitwise Not of the argument.

If the operand is a floating-point value (either Single or Double), it is first converted to a Long, thena bitwise Not is performed.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example demonstrates the use of the Not operator in comparing'logical expressions and for switching a True/False toggle variable.

A = TrueB = FalseSWITCH = TrueIf (A and Not B) And (Not (A = B)) Then

Msg$ = "A And Not B = True" + crlfElse

Msg = "A And Not B = False" + crlfEnd IfMsg = Msg + "Switch is now " + Format$(Switch,"True/False") + crlfSwitch = Not SwitchMsg = Msg + "Switch is now " + Format$(Switch,"True/False") + crlfSwitch = Not SwitchMsg = Msg + "Switch is now " + Format$(Switch,"True/False")

MbeMessageBox MsgEnd Sub

Now

Now#[()]

Descr. The Now function returns a double-precision number representing the current date and time.The number is returned in days where Dec 30, 1899, is 0.

Example:

Sub Main()

'This example shows how the Now function can be used as an elapsed-'time counter.T1# = Now()MbeMessageBox "Wait a while and click OK"T2# = Now()T3# = Second(T2) - Second(T1)MbeMessageBox "Elapsed time was: " + Str$(T3) + " seconds"

End Sub

NPer

Page 91 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 92: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 92/139

 NPer#(Rate#, Pmt#, Pv#, Fv#, Due%)

Descr. This function returns the number of periods for an annuity based on periodic fixed paymentsand a constant rate of interest.

An annuity is a series of fixed payments paid to or received from an investment over a period oftime. Examples of annuities are mortgages, retirement plans, monthly savings plans, and term loans.

NPer requires the following parameters:

Positive numbers represent cash received, whereas negative numbers represent cash paid out.

Example:

Sub Main()

'This example calculates the number of $100.00 monthly payments`necessary to accumulate $10,000.00 at an annual rate of 10%. Payments

`are made at the beginning of the month.ag# = NPer((.10/12),100,0,10000,1)MbeMessageBox "Number of monthly periods is: " + Format$(ag,"Standard")

End Sub

Npv

Npv#(Rate#, ValueArray#())

Descr. This function calculates the net present value of an annuity based on periodic payments andreceipts, and a discount rate.

Npv requires the following parameters:

Parameter Description

RateA double-precision number representing the interest rate per period. If the periods aremonthly, be sure to normalize annual rates by dividing them by 12.

Pmt

A double-precision number representing the amount of each payment or income.

Income is represented by positive values, whereas payments are represented bynegative values.

PvA double-precision number representing the present value of your annuity. In thecase of a loan, the present value would be the amount of the loan, and the futurevalue (see below) would be zero.

FvA double-precision number representing the future value of your annuity. In the caseof a loan, the future value would be zero, and the present value would be the amountof the loan.

Due

Parameter that indicates when payments are due for each payment period. A 0

specifies payment at the end of each period, whereas a 1 indicates payment at thestart of each period.

Page 92 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 93: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 93/139

 

Positive numbers represent cash received, whereas negative numbers represent cash paid out.

For accurate results, be sure to enter your payments and receipts in the correct order, as Npv uses theorder of the array values to interpret the order of the payments and receipts.

If your first cash flow occurs at the beginning of the first period, that value must be added to the

return value of Npv. It should not be included in the array of cash flows.

Npv differs from the Pv function in that the payments are due at the end of the period and the cashflows are variable. Pv's cash flows are constant, and payment may be made at either the beginning orend of the period.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example illustrates the purchase of a lemonade stand for $800

'financed with money borrowed at 10%. The returns are estimated to'accelerate as the stand gains popularity. The incomes are estimated'(generated) over 12 months. This program first generates the income'stream array in two For...Next loops, and then the net present value'(Npv) is calculated and displayed. Note normalization of the annual`10% rate.Dim Valu#(12)

 Valu(1) = -800 'initial investmentPStr$ = Str$(Valu(1)) + ", "For X = 2 To 5 'months 2-5

 Valu(X) = 100 + (X*2)PStr = PStr + Str$(Valu(X)) + ", "

Next x

For X = 6 To 12 'months 6-12 Valu(X) = 100 + (X*10) 'accelerated incomePstr = PStr + Str$(Valu(X)) + ", "

Next xNetVal# = NPV ((.10/12),Valu)PStr = "The values: " + crlf + PStr + crlf + crlfMbeMessageBox PStr + "Net present value: " + Format$(NetVal,"Currency")

End Sub

Null

Null[()]

Parameter Description

RateA double-precision number that represents the interest rate over the length of the

 period. If the values are monthly, annual rates must be divided by 12 to normalizethem to monthly rates.

ValueArray()

An array of double-precision numbers representing the payments and receipts.Positive values are payments, and negative values are receipts.There must be at least one positive and one negative value.

Page 93 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 94: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 94/139

Descr. Returns a null string (a string that contains no characters and requires no storage).

An empty string ("") can also be used to remove all characters from a string. However, empty stringsstill require some memory for storage. Null strings require no memory.

Example:

Sub Main()

'This example shows how the Null function can be used to initialize'and reset strings.A$ = Null()B$ = "This string is several characters long"MbeMessageBox "A: >" + A + "< B: =>" + B + "<="B = NullMbeMessageBox "A: =>" + A + "<= B: =>" + B + "<="

End Sub

Oct$

Oct$(number%)

Descr. Returns a string containing the octal equivalent of the specified number.

The returned string contains only the number of octal digits necessary to represent the number.

The number parameter can be any type but is rounded to the nearest whole number before converting

to the octal equivalent.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example displays the octal equivalent of several numbers.St$ = "The octal values are: " + crlfFor X% = 1 To 5

Y% = X * 10St = St + Str$(Y) + " : $" + Oct$(Y) + crlf

Next xMbeMessageBox St

End Sub

On Error

On Error {Goto label | Resume Next | Goto 0}

Descr. Defines the action taken when a trappable run-time error occurs.

The form On Error Goto label causes execution to transfer to the specified label when a run-timeerror occurs.

Page 94 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 95: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 95/139

The form On Error Resume Next causes execution to continue at the next line after the line thatcaused the error.

The form On Error Goto 0 causes any existing error trap to be removed.

If an error trap is in effect when the macro ends, then an error will be generated.

An error trap is only active within the subroutine or function in which it appears.

Once an error trap has gained control, appropriate action should be taken, and then control should beresumed using the Resume statement. Resume resets the error handler and continues execution. If a

 procedure ends while an error is pending, then an error will be generated. (The Exit Sub or ExitFunction statement also resets the error handler, allowing a procedure to end without displaying anerror message.)

Errors within an Error Handler

If an error occurs within the error handler, then the error handler of the caller (or any procedure inthe call stack) will be invoked. If there is no such error handler, then the error is fatal, causing themacro to stop executing. The following statements reset the error state (i.e., these statements turn offthe fact that an error occurred):

ResumeErr=-1

Resume forces execution to continue either on the same line or on the line following the line thatgenerated the error. The Err=-1 statement allows explicit resetting of the error state so that the scriptcan continue normal execution without resuming to the statement that caused the error condition.

The On Error statement will not reset the error. Thus, if an On Error statement occurs within anerror handler, it has the effect of changing the location of a new error handler for any new errors thatmay occur once the error has been reset.

Example:

Sub Main()

'This example tries to create a new subdirectory in the current path.'If it is successful, then it displays a message "Directory created."'Otherwise, it executes the error trap and changes the message. After

'performing this twice, the error trap is reset to Resume Next,'which ignores the error (if any) and tries to remove the directory.'If there is an error, the next line resets the error trap with On'Error Goto 0, and the RmDir is executed again (to create an error'for this example). The last RemDir statement will cause a run-time'error that is not trapped.Msg$ = NullOn Error Goto DirErrorFor X = 1 To 2

Msg = "Directory created"MkDir "TestDir"MbeMessageBox Msg

Next x

RmDir "TestDir"On Error Resume NextRmDir "TestDir"MbeMessageBox "No error trap: RmDir failed"

Page 95 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 96: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 96/139

  On Error Goto 0RmDir "TestDir"Exit Sub

DirError:If Err = 70 Then

Msg$ = "Directory exists! Error: " + Str$(Err)RmDir "TestDir"Resume Next

ElseMsg$ = "Unspecified error (remove directory)! " + Str$(Err)Resume Next

End IfEnd Sub

Open

Open filename$ [For mode] [Access accessmode] [lock] As [#] filenumber% _

[Len = reclen%]

Descr. The Open statement opens a file for a given mode, assigning the open file to the suppliedfilenumber.

The filename$ parameter is a string expression that contains a valid filename. filenumber is a number between 1 and 255. The FreeFile function can be used to determine an available file number.

The mode parameter determines the type of operations that can be performed on that file:

If mode is missing, Random is used.

The accessmode parameter determines what type of I/O operations can be performed on the file:

File

mode Description

InputOpens an existing file for sequential input (filename$ must exist). The value ofaccessmode, if specified, must be Read.

OutputOpen an existing or create a new file for sequential output, truncating its length to zero.The value of accessmode, if specified, must be Write.

AppendOpen an existing or create a new file for sequential output, positioning the file pointerat the end of the file. The value of accessmode, if specified, must be Read Write.

Binary

Open existing or create a new file for binary I/O. Existing binary files are never

truncated in length. The value of accessmode, if specified, determines how the file cansubsequently be accessed.

RandomOpen existing or create a new file for record I/O. Existing random files are truncatedonly if accessmode is Write. The reclen parameter determines the record length for I/Ooperations.

Access Description

Read Opens the file for reading only. This value is valid only for files opened in Binary,

Page 96 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 97: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 97/139

If accessmode is not specified, the following defaults are used:

The lock parameter determines what access rights are granted to other processes that attempt to openthe same file. If lock is not specified, the file is opened in compatibility mode (i.e., only the current

 process can access the file). The following table describes the values for lock:

If the file does not exist and lock is specified, the file is opened twice--once to create the file andagain to establish the correct sharing mode.

Files opened in Random mode are divided up into a sequence of records, each of the length specified by the reclen parameter. If this parameter is missing, then 128 used. For files opened for sequentialI/O, reclen specifies the size of the internal buffer when performing I/O. Larger buffers mean fasterfile access. For Binary files, reclen is ignored.

Example:

Sub Main()

'This example opens several files in various configurations.

Random or Input mode.

WriteOpens the file for writing only. Opening a file in Random mode with accessmode set toWrite truncates the file's length to 0. This value is valid only for files opened in Binary,Random or Output mode.

Read

Write

Opens the file for both reading and writing. This value is valid only for files opened in

Binary, Random or Append mode.

Filemode

Default value for accessmode

Input Read

Output Write

Append Read Write

Binary

When the file is initially opened, access is attempted three times in the followingorder:1. Read Write2. Write3. Read

Random Same as Binary files

Lock value Description

Shared Another process can both read this file and write to it. (Deny none)

Lock Read Another process can write to this file but not read it. (Deny read)

Lock Write Another process can read this file but not write to it. (Deny write)

Lock ReadWrite

Another process is prevented both from reading this file and from writing to it.(Exclusive)

Page 97 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 98: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 98/139

  Open "Test1.Dat" For Output Access Write Lock Write As #2CloseOpen "Test1.Dat" For Input Access Read Shared As #1CloseOpen "Test1.Dat" For Append Access Write Lock Read Write as #3CloseOpen "Test1.Dat" For Binary Access Read Write Shared As #4Close

Open "Test1.Dat" For Random Access Read Write Lock Read As #5CloseOpen "Test1.Dat" For Input Access Read Write Shared As #6CloseKill "Test1.Dat"

End Sub

Option Base

Option Base {0 | 1}

Descr. This statement sets the lower bound for array declarations. By default, the lower bound usedfor all array declarations is 0.

This statement must appear outside of any functions or subroutines.

Example:

Option Base 1Sub Main()

Dim a(10) Contains 10 elements (not 11).

End Sub

 Note, Option Base applies only to arrays that are dimensioned to fixed sizes at compile time. Whendynamic arrays (see Dim statement for explanation of dynamic arrays) are redimensioned by runtimefunctions, the lower bound is set to zero by default. Since this can cause confusion, Bentleyrecommends using the default Option Base 0. If you prefer Option Base 1, and want your dynamicarrays to also start at 1, you can use the Redim statement to force their lower bound to 1. In theexample below, the Option Base 1 statement has no effect on the lower boudn of the dynamic arrayfiles, but the Redim statement forces the lower bound to 1.

Example:

Option Base 1Sub Main ()`This example demonstrates how to force a dynamic array to have a lower`bound of 1 rather than 0. The Option Base statement is used only at`compile time, and has affects only fixed size arrays.

Dim files() as StringRedim files(1 to 1)FileList files, "*.*"If ArrayDims (files) > 0 Then

MbeMessageBox "First file is " + files(1)Else

MbeMesssageBox "No files found"

End IfEnd Sub

Page 98 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 99: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 99/139

Option Compare

Option Compare [Binary | Text]

Descr. The Option Compare statement controls how strings are compared.

When Option Compare is set to Binary, string comparisons are case-sensitive (i.e., `A' does notequal `a'). When it is set to Text, string comparisons are case-insensitive (i.e., `A' is equal to `a').

The default value for Option Compare is Binary.

Option Compare affects all string comparisons in any statements that follow it. Additionally, thesetting affects the default behavior of Instr, StrComp and the Like operator. The following tableshows the types of string comparisons affected by this setting:

Option Compare must appear outside the scope of all subroutines and functions. In other words, itcannot appear within a Sub or Function block.

Example:

'This example shows the use of Option Compare.

Option Compare BinarySub CompareBinary

A$ = "This String Contains UPPERCASE"B$ = "this string contains uppercase"If A = B Then

MbeMessageBox "The two strings were compared case-insensitive"Else

MbeMessageBox "The two strings were compared case-sensitive"End if

End SubOption Compare Text

Sub CompareTextA$ = "This String Contains UPPERCASE"B$ = "this string contains uppercase"If A = B Then

MbeMessageBox "The two strings were compared case-insensitive"Else

MbeMessageBox "The two strings were compared case-sensitive"End if

End SubSub Main()

CompareBinary 'Calls subroutine above.CompareText 'Calls subroutine above.

End Sub

Or

> < <>

<= >= Instr

StrComp Like

Page 99 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 100: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 100/139

 expression1 Or expression2

Descr. True if either expression1 or expression2 is TRUE; otherwise, FALSE.

If both operands are numeric, the result is the bitwise Or of the arguments.

If either operand is a floating-point number, both operands are first converted to Longs, then a bitwise Or is performed.

Example:

Sub Main()

'Uses the Or operator in a logical comparison.A$ = "First line"B$ = "Second line"

If (A = "First line") Or (B = "Another line") ThenMbeMessageBox "The comparison is True"Else

MbeMessageBox "The comparison is False"End If'Constructs a truth table for the Or statement.Msg$ = NullFor X% = True To False

For Y% = True To FalseZ = X Or YMsg = Msg + Format$(Abs(X),"0") + " Or "Msg = Msg + Format$(Abs(Y),"0") + " = "Msg = Msg + Format$(Z,"True/False") + crlf

Next yNext xMbeMessageBox Msg

End Sub

PI

PI 

Descr. 3.141592653589793238462643383279. PI can also be determined using the followingformula:

4 * Atn(1)

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example illustrates the use of the PI constant.Dia# = 5

Circ# = PI * DiaArea# = PI * ((Dia / 2) ^ 2)Msg$ = "Diameter: 5" + crlfMsg = Msg + "Circumference: " + Format$(Circ,"Standard") + crlf

Page 100 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 101: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 101/139

  Msg = Msg + "Area: " + Format$(Area,"Standard")MbeMessageBox Msg

End Sub

Pmt

Pmt#(Rate#, NPer#, Pv#, Fv#, Due%)

Descr. The Pmt function returns the payment for an annuity based on fixed, periodic payments and aconstant interest rate.

An annuity is a series of fixed payments made to an insurance company or other investmentcompany over a period of time. Examples of annuities are mortgages and monthly savings plans.

Pmt requires the following parameters:

Rate and NPer must be expressed in the same units. If Rate is expressed in months, then NPer mustalso be expressed in months.

Positive numbers represent cash received, whereas negative numbers represent cash paid out.

Example:

Sub Main()

'This example calculates the payment necessary to repay a $1,000.00`loan over 36 months at an annual rate of 10%. Payments are due at`the beginning of the period.X = Pmt((.1/12),36,1000.00,0,1)Msg$ = "The payment to amortize $1,000 over 36 months @ 10% is: "MbeMessageBox Msg + Format$(X,"Currency")

End Sub

PPmt

Parameter Description

RateA double-precision number representing the interest rate per period. If the periods aregiven in months, be sure to normalize annual rates by dividing them by 12.

 NPer A double-precision number representing the total number of payments in the annuity.

PvA double-precision number representing the present value of your annuity. In thecase of a loan, the present value would be the amount of the loan.

FvA double-precision number representing the future value of your annuity. In the caseof a loan, the future value would be 0.

DueParameter that indicates when payments are due for each payment period. A 0specifies payment at the end of each period, whereas a 1 specifies payment at the startof each period.

Page 101 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 102: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 102/139

 PPmt#(Rate#, Per#, NPer#, Pv#, Fv#, Due%)

Descr. The PPmt function calculates the principal payment for a given period of an annuity based onfixed, periodic payments and a constant interest rate.

An annuity is a series of fixed payments made to an insurance company or other investmentcompany over a period of time. Examples of annuities are mortgages and monthly savings plans.

PPmt requires the following parameters:

Rate and NPer must be in the same units to calculate correctly. If Rate is expressed in months, NPermust also be expressed in months.

 Negative values represent payments paid out, whereas positive values represent payments received.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example calculates the principal paid during each year on a`loan of $1,000.00 with an annual rate of 10%. The result is displayed`as a table containing the following information: payment, principal`payment, principal 'balance.

Pay = Pmt(.1,10,1000.00,0,1)Msg$ = "Amortization table for 1,000" + crlf + "at 10% annually for"Msg = Msg + " 10 years: " + crlf + crlfBal = 1000.00For Per = 1 to 10

Prn = PPmt(.1,Per,10,1000,0,0)Bal = Bal + PrnMsg = Msg + Format$(Pay,"Currency") + " " + Format$(Prn,"Currency")Msg = Msg + " " + Format$(Bal,"Currency") + crlf

Next PerMbeMessageBox Msg

End Sub

Print

Parameter Description

Rate a double-precision number representing the interest rate per period.

Pera double-precision number representing the number of payment periods. Per can beno less than 1 and no greater than NPer.

 NPer a double-precision number representing the total number of payments in the annuity.

Pva double-precision number representing the present value of annuity. In the case of aloan, the present value would be the amount of the loan.

Fva double-precision number representing the future value of your annuity. In the caseof a loan, the future value would be 0.

Dueindicates when payments are due. If 0, then payments are due at the end of each

 period; if 1, then payments are due at the start of each period.

Page 102 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 103: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 103/139

 Print [[{Spc(n) | Tab(n)}][expressionlist][{; | ,}]]

Descr. The Print statement prints data to an output device.

The actual output device depends on the platform on which BASIC is running.

Strings are written in their literal form, with no enclosing quotes.

Integers and Longs are written with an initial space reserved for the sign (space = positive).Additionally, there is a space following each number.

Each expression in expressionlist is separated with a comma `,' or semicolon `;'. A comma meansthat the next expression is output in the next print zone. A semicolon means that the next expressionis output immediately after the current expression. Print zones are defined every 14 spaces.

If the last expression in the list is not followed by a comma or a semicolon, a carriage return is printed to the file. If the last expression ends with a semicolon, no carriage return is printed. The next

Print statement will output information immediately following the expression. If the last expressionin the list ends with a comma, the file pointer is positioned at the start of the next print zone on thecurrent line.

The Tab and Spc functions provide additional control over the column position. Tab moves the file position to the specified column, whereas Spc outputs the specified number of spaces.

Example:

Sub Main()

'The next example opens a viewport and prints some data. Viewport.Openi% = 10s$ = "This is a test"Print "The value of i=";i%,"the value of s=";s$'Print the value of i% in print zone 1 and s$ in print zone 3.Print i%,,s$'Print the value of i% and s$ separated by 10 spaces.Print i%;Spc(10);s$'Print the value of i in column 1 and s$ in column 30.Print i%;Tab(30);s$'Print the value of i% and s$...Print i%;s$,Print 67

End Sub

Print#

Print filenumber%, [[{Spc(n) | Tab(n)}][expressionlist][{;|,}]]

Descr. Writes data to a sequential disk file.

filenumber is a number used to refer to the open file--the number passed to the Open statement.

Strings are written in their literal form, with no enclosing quotes.

Page 103 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 104: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 104/139

Integers and Longs are written with an initial space reserved for the sign (space = positive).Additionally, there is a space following each number.

Each expression in expressionlist is separated with a comma `,' or semicolon `;'. A comma meansthat the next expression is output in the next print zone. A semicolon means that the next expressionis output immediately after the current expression. Print zones are defined every 14 spaces.

If the last expression in the list is not followed by a comma or semicolon, then an end-of-line is printed to the file. If the last expression ends with a semicolon, no end of line is printed. The nextPrint statement will output information immediately following the expression. If the last expressionin the list ends with a comma, the file pointer is positioned at the start of the next print zone on thecurrent line.

The Write statement always outputs information ending with an end-of-line. Thus, if a Print statement is followed by a Write , the file pointer is positioned on a new line. Print can only be usedwith files that are opened in Output or Append mode.

The Tab and Spc functions provide additional control over the file position. Tab moves the file position to the specified column, whereas Spc outputs the specified number of spaces.

Example:

Sub Main()

'The next example opens a file and prints some data.Open "Test.Dat" For Output As #1i% = 10s$ = "This is a test"Print #1,"The value of i=";i%,"the value of s=";s$

'Print the value of i% in print zone 1 and s$ in print zone 3.Print #1,i%,,s$'Print the value of i% and s$ separated by 10 spaces.Print #1,i%;Spc(10);s$'Print the value of i in column 1 and s$ in column 30.Print #1,i%;Tab(30);s$'Print the value of i% and s$...Print #1,i%;s$,Print #1,67Close #1

End Sub

Private

Private name [(subscripts)] [As type] [, name [(subscripts)] [As type]]...

Descr. Declares a list of private variables and their corresponding types and sizes.

Private variables are global to every subroutine and function within the currently executing macro.

If a type-declaration character is used when specifying name (such as %, &, $ or !), the optional [Astype] expression is not allowed. For example, the following are allowed:

Private foo As IntegerPrivate foo%

Page 104 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 105: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 105/139

subscripts allows the declaration of arrays. This parameter uses the following syntax:

[lower To] upper [,[lower To] upper]...

The lower and upper parameters are integers specifying the lower and upper bounds of the array. Iflower is not specified, then the lower bound as specified by Option Base is used (or 0 if no OptionBase statement has been encountered). Up to 60 array dimensions are allowed.

The total size of an array (not counting space for strings) is limited to 64K.

Dynamic arrays are declared by not specifying any bounds:

Private a()

type specifies the data type of the item being declared. It can be any of the following data types:String, Integer, Long, Single, Double, object, application-defined object, application-defineddata type, or any user-defined data type.

If a variable is seen that has not been explicitly declared with either Dim, Public or Private, then itwill be implicitly declared local to the routine in which it is used.

See also Public.

Public

Public name [(subscripts)] [As type] [, name [(subscripts)] [As type]]...

Descr. Declares a list of public variables and their corresponding types and sizes.

Public variables are global to all Subs and Functions in all loaded macros.

If a type-declaration character is used when specifying name (such as %, &, $ or !), the optional [Astype] expression is not allowed. For example, the following are allowed:

Public foo As IntegerPublic foo%

subscripts allows the declaration of arrays. This parameter uses the following syntax:

[lower To] upper [,[lower To] upper]...

lower and upper are integers specifying the lower and upper bounds of the array. If lower is notspecified, then the lower bound as specified by Option Base is used (or 0 if no Option Base statement has been encountered). Up to 60 array dimensions are allowed.

The total size of an array (not counting space for strings) is limited to 64K.

Dynamic arrays are declared by not specifying any bounds:

Public a()

type specifies the type of the data item being declared. It can be any of the following data types:

Page 105 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 106: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 106/139

String, Integer, Long, Single, Double, object, application-defined object, application-defineddata type, or any user-defined data type.

If a variable is seen that has not been explicitly declared with either Dim, Public or Private, then itwill be implicitly declared local to the routine in which it is used.

For compatibility, the keyword Global is also supported--it has the same meaning as Public.

Example:

'This example uses a subroutine to calculate the area of 10 circles

'and displays the result in a dialog box. The variables R and Ar are`declared as Public variables so that they can be used in both Main`and Area.Public R#,Ar#Sub Area()

Ar = (R ^ 2) * PiEnd SubSub Main()

Msg$ = NullFor X = 1 To 10

R = XAreaMsg = Msg + Str$(R) + " : " + Str$(Ar) + crlf

Next xMbeMessageBox Msg

End Sub

Put

Put [#] filenumber% , [recordnumber%], variable

Descr. Writes data from the specified variable to a Random or Binary file.

variable is the name of any variable of any of the following types:

Variabletype

File storage description

Integer 2 bytes are written to the file.

Long 4 bytes are written to the file.

String

In Binary files, variable-length strings are written by first determining the specifiedstring variable's length, then writing that many bytes to the file.In Random files, variable-length strings are written by first writing a 2-byte length,then writing that many characters to the file.

Double 8 bytes are written to the file (IEEE format).

Single 4 bytes are written to the file (IEEE format).

User-Each member of a user-defined data type is written individually.In Binary files, variable-length strings within user-defined types are written by first

Page 106 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 107: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 107/139

The optional recordnumber parameter specifies which record is to be written to the file. For Binary files, this number represents the first byte to be written starting with the beginning of the file (thefirst byte is 1). For Random files, this number represents the record number starting with the

 beginning of the file (the first record is 1). This value ranges from 1 to 2147483647. If recordnumberis not specified, the next record is written to the file (if no records have been written yet, then thefirst record in the file is written). If recordnumber is not specified, the commas must still appear, asin the following example:

Put #1,,recvar

If recordlength is specified, it overrides any previous change in file position specified with the Seek  statement.

With Random files, a run-time error will occur if the length of the data being written exceeds therecord length (specified as the reclen parameter with the Open statement). If the length of the data

 being written is less than the record length, the entire record is written along with padding (whateverdata happens to be in the I/O buffer at that time). With Binary files, the data elements are writtencontiguously. The data elements are never separated with padding.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example opens a file for random write, then writes 10'records into the file with the values 10...50. Then the file'is closed and reopened in random mode for read, and the'records are read with the Get statement. The result is displayed'in a dialog box.Open "Test2.Dat" For Random Access Write As #1For X% = 1 To 10

Y% = X * 10

Put #1,X,YNext XClosePstr$ = ""Open "Test2.Dat" For Random Access Read As #1For Y = 1 To 5

Get #1,y,XPstr = Pstr + "Record " + Str$(Y) + ": " + Str$(X) + crlf

Next YMbeMessageBox PstrClose

End Sub

Pv

definedtypes

writing a 2-byte length followed by the string's content. This storage is differentthan variable-length strings outside of user-defined types.When writing user-defined types, the record length must be greater than or equal tothe combined size of each element within the data type.

Arrays Arrays cannot be written to a file using the Put statement.

Objects Object variables cannot be written to a file using the Put statement.

Page 107 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 108: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 108/139

 Pv#(Rate#, NPer#, Pmt#, Fv#, Due%)

Descr. The Pv function calculates the present value of an annuity based on future periodic, fixed payments and a constant interest rate.

Pv requires the following parameters:

Rate and NPer must be expressed in the same units. If Rate is expressed in months, then NPer mustalso be expressed in months.

Positive numbers represent cash received, whereas negative numbers represent cash paid out.

Example:

Sub Main()

'This example demonstrates the present value (the amount you'd have`to pay now) for a $100,000 annuity that pays an annual income`of $5,000 over 20 years at an annual interest rate of 10%.PVal = Pv(.1,20,-5000,100000,1)MbeMessageBox "The present value is: " & Format$(PVal,"Currency")

End Sub

Random

Random&(min&, max&)

Descr. Returns a random number greater than or equal to min and less than or equal to max.

A runtime error is generated if min is greater than max.

The expressions that appear in place of min and max will be rounded to the nearest whole number.

Example:

Const crlf = Chr$(13) + Chr$(10)

Parameter Description

RateA double-precision number representing the interest rate per period. When used withmonthly payments, be sure to normalize annual percentage rates by dividing them by12.

 NPer A double-precision number representing the total number of payments in the annuity.

Pmt A double-precision number representing the amount of each payment per period.

FvA double-precision number representing the future value of the annuity after the last

 payment has been made. In the case of a loan, the future value would be 0.

Due Number that determines when the payments are due for each payment period. A 0specifies payment at the end of each period, whereas a 1 specifies payment at the startof each period.

Page 108 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 109: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 109/139

 Sub Main()'This example uses the random number generator to generate ten'lottery numbers:Msg$ = NullRandomizeFor X = 1 To 10

Y = Random(0,100)Msg = Msg + Str$(Y) + crlf

Next xMbeMessageBox "Ten Numbers for the Lottery: " + crlf + Msg

End Sub

Randomize

Randomize [seed&]

Descr. Initializes the random number generator with a new seed.

If seed is not specified, then the current value of the system clock is used.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example sets the randomize seed to a random number between'100 and 1000, then generates ten random numbers for the lottery.RandomizeMsg$ = Null

For X = 1 To 10Y = Random(0,100)Msg = Msg + Str$(Y) + crlf

Next xMbeMessageBox "Ten Numbers for the Lottery: " + crlf + Msg

End Sub

Rate

Rate#(NPer#, Pmt#, PV#, FV#, Due%, Guess#)

Descr. This function returns the rate of interest for each period of an annuity.

An annuity is a series of fixed payments made to an insurance company or other investmentcompany over a period of time. Examples of annuities are mortgages and monthly savings plans.

Rate requires the following parameters:

Parameter Description

 NPer a double-precision number representing the total number of payments in the annuity.

Pmt a double-precision number representing the amount of each payment per period.

Page 109 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 110: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 110/139

Positive numbers represents cash received, while negative values represent cash paid out.

The value of Rate is found by iteration. It starts with the value of Guess, and cycles through thecalculation adjusting Guess until the result is accurate within 0.00001 percent. If a result cannot befound after 20 tries, Rate fails and the user must pick a better guess.

Example:

Sub Main()

'This example calculates the rate of interest necessary to save $10,000'by paying $550 each year for 10 years. The guess rate is 10%.R# = Rate(10,-550,000,10000,1,.1)MbeMessageBox "The Rate required is: " + Format$(R,"Percent")

End Sub

ReDim

Redim [Preserve] variablename (subscriptRange) [As type],...

Descr. This statement redimensions an array, specifying a new upper and lower bound for eachdimension of the array.

The variablename parameter specifies the name of an existing array (previously declared using theDim statement), or the name of a new array variable. If the array variable already exists, then it must

 be previously declared with the Dim statement with no dimensions, as shown in the followingexample:

Dim a$() 'dynamic array of strings (no dimensions yet)

Dynamic arrays can be redimensioned any number of times.

The subscriptRange parameter specifies the new upper and lower bounds for each dimension of thearray using the following syntax:

[lower% To] upper% [,[lower% To] upper%]...

If lower is not specified, then 0 is used. Note, the Option Base statement does not affect a dynamicarray when it is redimensioned.

PVa double-precision number representing the present value of your annuity. In a loansituation, the present value would be the amount of the loan.

FVa double-precision number representing that future value of the annuity after the last

 payment has been made. In the case of a loan, the future value would be zero.

Due

determines when the payments are due for each payment period. A 0 specifies

 payment at the end of each period while 1 indicates payment at the start of each period.

Guessa number you guess as the value the Rate function will return. The most commonguess is .1 (10 percent).

Page 110 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 111: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 111/139

The type parameter can be used to specify the array element type. Arrays can be declared using anyfundamental data type, user-defined data types, and objects.

Redimensioning an array erases all elements of that array unless the preserve keyword is specified.When this keyword is specified, existing data in the array is preserved where possible. If the numberof elements in an array dimension increased, the new elements are initialized to zero (or emptystring). If the number of elements in an array dimension is decreased, then the extra elements will bedeleted. If the preserve keyword is used, then the number of dimensions of the array must either be 0or the same as the new number of dimensions.

Example:

Sub Main()

'This example uses the FileList statement to redim and fill an array'with file name strings. A new array is then redimmed to hold the'number of elements found by FileList and the FileList array is'copied into it and partially displayed.

Dim FL$()FileList FL,"*.*"count = Ubound(FL)ReDim NL$(Lbound(FL) To Ubound(FL))For X = Lbound(FL) to count

NL(X) = FL(X)Next xMbeMessageBox "The last element of the new array is: " + NL(count)

End Sub

REM

REM text

Descr. Causes the compiler to skip all characters on that line.

Example:

Sub Main()

REM This line is a line of comments which serve to illustrate theREM workings of the code and insert comments to make it moreREM readable and maintainable in the future.

End Sub

Reset

Reset

Descr. Closes all open files, writing out all I/O buffers.

Example:

Sub Main()

Page 111 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 112: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 112/139

  'A file is opened for output, and closed with the Reset Statement'then deleted with the Kill statement.Open "Test.Dat" for output access write as # 1ResetKill "Test.Dat"If FileExists("Test.Dat") Then

MbeMessageBox "The file was not deleted"Else

MbeMessageBox "The file was deleted"End If

End Sub

Resume

Resume {[0] | Next | label}

Descr. Ends an error handler and continues execution.

The form Resume 0 (or simply Resume by itself) causes execution to continue with the statementthat caused the error.

The form Resume Next causes execution to continue with the statement following the statement thatcaused the error.

The form Resume label causes execution to continue at the specified label.

The Resume statement resets the error state. This means that, after executing this statement, newerrors can be generated and trapped as normal.

Example:

Sub Main()

'This example tries to create a new subdirectory in the current path.'If it is successful then it displays a message "Directory created"'Otherwise it executes the error trap and changes the message. After'performing this twice, the error trap is reset to "Resume Next" which'ignores the error (if any) and tries to remove the directory. If there'is an error the next line resets the error trap with "On Error Goto 0"'and the RmDir is executed again (to create an error for this example.)

'The lastRemDir statement will cause a run-time error which is not'trapped.Msg$ = NullOn Error Goto DirErrorFor X = 1 To 2

Msg = "Directory Created"MkDir "TestDir"MbeMessageBox Msg

Next xRmDir "TestDir"On Error Resume NextRmDir "TestDir"MbeMessageBox "No Error Trap: RmDir Failed"

RemoveError:On Error Goto 0RmDir "TestDir"Exit Sub

Page 112 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 113: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 113/139

 DirError:If Err = 70 Then

Msg$ = "Directory exists! Error: " + Str$(Err)RmDir "TestDir"Resume Next

ElseMsg$ = "Unspecified Error (Remove Directory)! " + Str$(Err)Resume RemoveError

End IfEnd Sub

Return

Return

Descr. Transfers execution control to the statement following the most recent Gosub. A runtimeerror results if a Return statement is encountered without a corresponding Gosub statement.

Example:

Sub Main()

'A subroutine is called and then execution is returned to the main'routine by the Return statement.If True Then Gosub SubTrueMbeMessageBox "The main routine continues here"Exit Sub

SubTrue:MbeMessageBox "This message is generated in the Subroutine"

ReturnEnd Sub

Right$

Right$(str$, NumChars$)

Descr. Returns the specified rightmost characters from a string.

If NumChars is greater than or equal to the length of the string, then the entire string is returned. If NumChars is 0, then an empty string is returned.

Example:

Sub Main()

'This example shows the Right$ function used in a routine to change'upper case names to lower case with an upper case first letter.Lname$ = "WILLIAMS"X = Len(Lname)Rest$ = Right$(Lname,X - 1)FL$ = Left$(Lname,1)Lname = Fl + LCase$(Rest)MbeMessageBox "The Converted name is: " + Lname

End Sub

Page 113 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 114: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 114/139

RmDir

RmDir dir$

Descr. Removes the specified directory.

Example:

Sub Main()

'This routine creates a directory and then deletes it with RmDirOn Error Goto ErrMakeMkDir("TEST01")On Error Goto ErrRemoveRmDir("Test01")

ErrMake:

MbeMessageBox "The directory could not be created"Exit SubErrRemove:

MbeMessageBox "The directory could not be removed"Exit Sub

End Sub

Rnd

Rnd![(number!)]

Descr. Returns a single precision random number between 0 and 1.

If number is omitted, the next random number is returned. Otherwise, the number parameter has thefollowing meaning:

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This routine generates a list of random numbers and displays themFor x = -1 To 8

y! = Rnd(1) * 100Msg$ = Msg + Str$(X) + " : " + Str$(y) + crlf

NextMbeMessageBox msg + "Last form: " +Str$(Rnd)

End Sub

RSet

number < 0 Always returns the same number

number = 0 Returns the last number generated

number > 0 Returns the next random number

Page 114 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 115: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 115/139

 RSet dest$ = source$

Descr. The RSet statement copies the source string source$ into the destination string dest$. Ifsource$ is shorter in length than dest$, then the string is right aligned within dest$ and the remainingcharacters are padded with spaces. If source$ is longer in length than dest$, then source$ is

truncated, copying only the leftmost number of characters that will fit in dest$.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example Replaces a 40 character string of asterisks (*) with'a RSet and LSet string and then displays the results.Dim Msg$, TmpStr$TmpStr = String$(40, "*")Msg = "Here are two strings that have been right" + crlf

Msg = Msg + "and left justified in a 40 character string"Msg = Msg + crlf + crlfRSet TmpStr = "Right->"Msg = Msg & TmpStr & crlfLSet TmpStr = "<-Left"Msg = Msg & TmpStr & crlfMbeMessageBox Msg

End Sub

RTrim$

RTrim$(str$)

Descr. Returns the string with the trailing spaces removed.

Example:

Const crlf = Chr$(13) + Chr$(10)

Sub Main()'This example displays a left justified string and it's RTrim result.

A$ = "This is a left justified string "B$ = RTrim$(A)MbeMessageBox A + "<=" + crlf + B + "<="

End Sub

Second

Second%(serial#)

Descr. Returns the second of the day encoded in the specified serial parameter. The value returned is between 0 and 59 inclusive.

Page 115 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 116: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 116/139

Example:

Sub Main()

'This example takes the current time and extracts the hour,'minute, and second and displays them as the current time.XT# = TimeValue(Time$())

XH# = Hour(XT)XM# = Minute(XT)XS# = Second(XT)MbeMessageBox "Current Time is: " + CStr(XH)+":"+CStr(XM)+":"+CStr(XS)

End Sub

Seek (function)

Seek&(filenumber%)

Descr. Returns the position of the file pointer in a file relative to the beginning of the file.

filenumber is a number that is used by the OS to refer to the open file--the number passed to theopen statement.

The value returned depends on the mode in which the file was opened:

The value returned is always between 1 and 2147483647 where the first byte (or first record) in thefile is 1.

Example:

Sub Main()

'This example opens a file for random write then writes ten'records into the file using the PUT statement. The file position`is displayed using the Seek Function, and the file is closed.Open "Test2.Dat" for random access write as #1

For X% = 1 to 10Y% = X * 10Put #1,X,Y

Next XY = Seek(1)

MbeMessageBox "The current file position is: " + Str$(Y)Close

End Sub

File Mode Returns

Input byte position for the next read

Output byte position for the next write

Append byte position for the next write

Random number of the next record to be written or read

Binary byte position for the next read or write

Page 116 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 117: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 117/139

Seek (statement)

Seek [#] filenumber%, position&

Descr. Sets the position of the file pointer within a given file so that the next read or write operationwill occur at the specified position.

The filenumber parameter is a number that is used by the OS to refer to the open file--the number passed to the open statement. filenumber should always be between 1 and 2147483647 where thefirst byte (or first record) in the file is 1.

The position parameter specifies the location within the file to position the file pointer. It is a number between 1 and 2147483647, where the first byte (or record number) in the file is 1. For files openedin either Binary, Output, Input or Append modes, position is the byte position within the file. ForRandom files, position is the record number.

A file can be extended by seeking beyond the end-of-file and writing data there.

Example:

Sub Main()

'This example opens a file for random write then writes ten'records into the file using the PUT statement. The file is'then re-opened for read and the ninth record is read using'the Seek and Get Functions.Open "Test2.Dat" For Random Access Write As #1

For X = 1 To 10Rec$ = "Record #" + Str$(X)Put #1,X,Rec$

Next XCloseOpen "Test2.Dat" For Random Access Read As #1Seek #1,9Get #1,,Rec$MbeMessageBox "The Ninth Record = " + Str$(X)Close

End Sub

Select...Case

Select Case testexpression[Case expressionlist[statement_block]]

[Case expressionlist[statement_block]]...

[Case Else[statement_block]]

End Select

Descr. This statement is used to execute a block of BASIC statements depending on the value of agiven expression.

Page 117 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 118: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 118/139

The Select Case statement uses the following arguments:

If the testexpression matches any of the expressions contained in expressionlist, then theaccompanying block of BASIC statements is executed.

The resultant type of expression must be the same as that of testexpression.

Multiple expression ranges can be used within a single Case clause. For example:

Case 1 To 10,12,15, Is > 40

Only the statement_block associated with the first matching expression will be executed.

A Select...End Select expression can also be represented with the If...Then expression. The use ofthe Select statement, however, may be more readable.

Example:

Sub Main()

'This example uses the select .. case statement to output the'current operating system.OpSystem% = Basic.OSSelect Case OpSystem%Case 2

S$ = "Microsoft Windows"Case 3 to 8

S$ = "Unix"Case 10

S$ = "Apple Macintosh"Case 12

S$ = "DOS"Case Else

S$ = "Other"End SelectMbeMessageBox "This version of BASIC runs on: "+ S$

End Sub

Set

Set object_var = object_expressionSet object_var = New object_type

Set object_var = Nothing

Descr. The Set statement assigns a value to an object variable.

testexpression Any numeric or string expression

statement_block Any group of BASIC statements

expressionlist

Any of the following:

expression [,expression]...expression to expressionis relational_operator expression

Page 118 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 119: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 119/139

The first syntax assigns the result of an expression to an object variable. This statement does notduplicate the object being assigned, but rather copies a reference of an existing object to an objectvariable.

The object_expression is an expression that evaluates to an object of the same type as the object_var.

With application-defined objects, Set performs additional processing. When the Set is performed,the application or extension that defines that object type is notified that a reference to an object is being made and destroyed. For example, the following statement informs the application orextension that a reference to object A is lost and a reference to object B is added:

Set A = B

In this way, the application can detect when an object is no longer being referenced and takeappropriate action, such as destroying the physical object.

In the second syntax, the object variable is being assigned to a new instance of an existing objecttype. This syntax is only valid for application-defined objects.

At runtime, the application or extension that defines that object type is notified that a new object is being created and assigned. The application should respond by creating a new physical object(within the appropriate context) and returning a reference to that object which is immediatelyassigned to the variable being declared.

When an object created using the New keyword goes out of scope (i.e., the Sub or Function inwhich the variable is declared ends), the application is notified. The application can choose anyappropriate action, such as destroying the physical object.

In the third syntax, the reserved keyword Nothing is used to make an object variable reference noobject. At a later time, the object variable can be compared to Nothing to test if the object variablehas been instantiated.

Example:

Sub Main()

dim Document as objectdim Page as objectset Document = GetObject("c:\resume.doc")set page = Document.ActivePage

MbeMessageBox page.nameEnd Sub

SetAttr

SetAttr filename$, attribute%

Descr. The SetAttr command changes the attributes of the specified file to the given attribute. Aruntime error results if the file cannot be found.

attribute can contain any combination of the following values:

Page 119 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 120: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 120/139

The attributes can be combined using the + operator or the bitwise OR operator.

Example:

Sub Main()

'This example creates a file and sets it's attributes to`Read-Only and System.Open "Test2.Dat" For Output Access Write As # 1CloseMbeMessageBox "Current Attribute: " + Str$(GetAttr("Test2.Dat"))SetAttr "Test2.Dat",ebReadOnly OR ebSystemMbeMessageBox "Attribute set to: " + Str$(GetAttr("Test2.Dat"))

End Sub

Sgn

Sgn%(number)

Descr. Returns a value indicating if a number is less than, greater than, or equal to zero.

Returns 1 if number is greater than 0.

Returns 0 if number is equal to 0.Returns -1 if number is less than 0.

The number parameter is a numeric expression of any type.

Example:

Sub Main()

'This example tests the product of two numbers and displays'a message based on the sign of the result.A% = -100

B% = 100C% = A * BSelect Case Sgn(C)

Case -1

Constant Value Includes...

ebNormal 0 Read-only, archive, subdir, none

ebReadOnly 1 Read-only files

ebHidden 2 Hidden files

ebSystem 4 System files

ebVolume 8 Volume label

ebDirectory 16 Sub-directories

ebArchive 32 Files that have changed since last backup

ebNone 64 Files with no attributes

Page 120 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 121: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 121/139

  MbeMessageBox "The Product is Negative " + Str$(Sgn(C))Case 0

MbeMessageBox "The Product is Zero" + Str$(Sgn(C))Case 1

MbeMessageBox "The Product is Positive" + Str$(Sgn(C))End Select

End Sub

Sin

Sin#(angle#)

Descr. Returns the sine of a given angle.

angle is given in radians.

Example:

Sub Main()

'Displays the Sine of PI/4 radians (45 degrees)C# = Sin(PI / 4)MbeMessageBox "The sine of 45 Degrees is: " + Str$(C)

End Sub

Sleep

Sleep milliseconds&

Descr. This statement causes a macro to pause for a specified number of milliseconds.

Example:

Sub Main()

'This example displays a message for two seconds.MbeWriteMessage "Waiting 2 seconds"

Sleep(2000)MbeWriteMessage

End Sub

Sln

Sln#(Cost#, Salvage#, Life#)

Descr. The Sln function returns the Straight-Line Depreciation of an asset, assuming constant benefit

from the asset.

The SLN of an asset is found by taking an estimate of its useful life in years, assigning values to

Page 121 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 122: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 122/139

each year, and adding up all the numbers.

The formula used to find the SLN of an asset is as follows:

(Cost - Salvage Value) / Useful Life

Sln requires the following parameters:

The unit of time used to express the useful life of the asset is the same unit of time used to express

the period for which the depreciation is returned.

Example:

Sub Main()

'This example calculates the straight line depreciation of an asset'which cost $10,000.00 and has a salvage value of $500.00 as scrap'after 10 years of service life.Dep# = Sln(10000.00,500.00,10)MbeMessageBox "The Annual depreciation is: " + Format$(Dep,"Currency")

End Sub

Space$

Space$(NumSpaces%)

Descr. Returns a string containing the specified number of spaces.

 NumSpaces must be between 0 and 32767.

Example:

Sub Main()

'This example returns a string of 10 spaces and displays it.Ln$ = Space$(10)MbeMessageBox "Value of LN: =>" + LN + "<="

End Sub

Spc

Spc(numspaces%)

Parameter Description

Cost This is a double-precision number representing the initial cost of the asset.

SalvageThis is a double-precision number representing the estimated value of the asset at theend of its useful life.

Life This number represents the length of the assets useful life.

Page 122 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 123: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 123/139

Descr. The Spc function prints out the specified number of spaces. Spc can only be used with thePrint and Print# statements.

numspaces specifies the number of spaces to be printed. It can be any value between 0 and 32767.

If a line width has been specified (using the Width statement), then the number of spaces is adjusted

as follows:numspaces% = numspaces% Mod width%

If the resultant number of spaces is greater than width - print_position, the number of spaces isrecalculated as follows:

numspaces% = numspaces% - (width% - print_position)

These calculations have the effect of never allowing the spaces to overflow the line length.Furthermore, with a large value for column% and a small line width, the file pointer will neveradvance more than one line.

Example:

'Displays 20 spaces between the arrows

Print "20 Spaces:-->"; Spc(20); "<--"

Sqr

Sqr#(number#)

Descr. Returns the square root of a given value.

number must be greater than or equal to 0.

Example:

Sub Main()

'This example calculates the square root of the numbers from 1 to 10'and displays them.crlf$ = Chr$(13) + Chr$(10)Msg$ = NullFor X = 1 To 10

SX# = Sqr(X)Msg = Msg + Format$(X,"Fixed") + " - " + Format$(SX,"Fixed") + crlf

Next xMbeMessageBox Msg

End Sub

Stop

Stop

Page 123 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 124: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 124/139

Descr. Suspends execution of the current macro, returning control to a debugger if one is present. If adebugger is not present, this command will have the same affect as end.

Example:

Sub Main()

'The stop statement can be used for debugging. Here it is used'to stop execution when Z is randomly set to zeroFor X = 1 To 10

Z = Random(0,10)If Z = 0 Then StopY = X / Z

Next xEnd Sub

Str$

Str$(number%)Str$(number&)Str$(number!)Str$(number#)

Descr. Returns a string representation of the given number. The result is returned in floating point `E'notation, if the result is very small or very large.

If number is negative, then the returned string will contain a leading minus sign. If number is positive, then the returned string will contain a leading space.

Singles are printed using only 7 significant digits. Doubles are printed using 15-16 significantdigits.

Example:

Sub Main()

'The Str$ function is used to display the value of a numeric variable.X# = 100.22MbeMessageBox Str$(X)

End Sub

StrComp

StrComp%(string1$, string2$ [, compare%])

Descr. Returns an Integer value indicating the result of comparing the two string arguments:

0 string1$ = string2$

1 string1$ > string2$

Page 124 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 125: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 125/139

The StrComp function compares two strings and returns an integer indicating the result of thecomparison. The comparison can be either case sensitive or case insensitive depending on the valueof the optional compare parameter:

If compare is not specified, then the current Option Compare setting is used. If no OptionCompare statement has been encountered, then Binary is used (i.e., string comparison is casesensitive).

Example:

Const crlf$ = Chr$(13) + Chr$(10)

Sub Main()'This example compares two strings and displays the results.'It illustrates that the function compares two strings to the'length of the shorter string in determining equivalency.Msg$ = NullA$ = "This string is UPPER and lower case"B$ = "This string is upper and lower case"C$ = "This string"D$ = "This string is upper and lower case characters"ABc = StrComp(A,B,0)Msg= Msg + "A and C (sensitive) : " + Format$(ABc,"True/False") + crlf

ABi = StrComp(A,B,1)Msg= Msg + "A and B (insensitive): " + Format$(ABi,"True/False") + crlfACi = StrComp(A,C,1)Msg= Msg + "A and C (insensitive): " + Format$(ACi,"True/False") + crlfBDi = StrComp(B,D,1)Msg= Msg + "B and D (sensitive) : " + Format$(BDi,"True/False") + crlfMbeMessageBox Msg

End Sub

String$

String$(number%, CharCode%)String$(number%, str$)

Descr. Returns a string of length number consisting of a repetition of the specified filler character.

If CharCode is specified, then the character with this ANSI value will be used as the filler character.

If str$ is specified, then the first character of this string is used as the filler character.

Example:

Sub Main()

'This example uses the string function to create a line of "=" signs

-1 string1$ < string2$

0 case sensitive comparison

1 case insensitive comparison

Page 125 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 126: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 126/139

  `the length of another string, and then displays the character string`underlined with the generated string.A$ = "This string will appear underlined"B$ = String$(Len(A),"=")MbeMessageBox A + crlf + B

End Sub

Sub...End Sub

Sub name[(parameter [As type]...)][statements]

End Sub

Descr. Declares a subroutine.

Parameters are passed to a subroutine by reference, meaning that any modifications to a passed

 parameter changes that variable in the caller. To avoid this, simply enclose variable names in parenthesis, as in the following example function calls:

UserSub 10,12,(j)

If a subroutine is not to receive a parameter by reference, then the optional ByVal keyword can beused:

Sub Test ByVal FileName As String[statements]

End Sub

A subroutine terminates when one of the following statements is encountered:

End SubExit Sub

The name of the subroutine must follow BASIC naming conventions. It cannot include typedeclaration characters.

Subroutines can be recursive.

Example:

Sub Main()

'This example uses a subroutine to calculate the area of a circleR! = 10PrintArea R

End SubSub PrintArea(R as single)

Area! = (R ^ 2) * PIMbeMessageBox "Area of circle with radius"+Str$(R) + " = " + Str$(Area)

End Sub

SYD

Page 126 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 127: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 127/139

 SYD#(Cost#, Salvage#, Life#, Period#)

Descr. This function returns the Sum of Years' Digits depreciation of an asset over a specific periodof time. The SYD of an asset is found by taking an estimate of its useful life in years, assigningvalues to each year, and adding up all the numbers.

The formula used to find the SYD of an asset is as follows:

(Cost - Salvage_Value) * Remaining_Useful_Life / SYD

SYD requires the following parameters:

Life and Period must be expressed in the same units. If Life is expressed in terms of months, thenPeriod must also be expressed in terms of months to receive accurate results.

Example:

Sub Main()

'An asset which cost $1,000.00 is depreciated over 10 years.`The salvage value is $100.00 and the Sum of the years digit`depreciation is shown for each year.For X = 1 To 10Dep# = SYD(1000,100,10,X)Msg$=Msg + "Year"+Str$(X)+" Dep: " + Format$(Dep,"Currency")+ Chr$(13)

Next xMbeMessageBox Msg

End Sub

Tab

Tab(column%)

Descr. The Tab function prints out the number of spaces necessary to reach a given column position.Tab can only be used with the Print and Print# statements.

column specifies the desired column position to advance to. It can be any value between 0 and 32767inclusive.

Rule 1: If the current print position is less than or equal to column, then the number of spaces iscalculated as:

Parameter Description

Cost This is a double-precision number representing the initial cost of the asset.

SalvageThis is a double-precision number representing the estimated value of the asset at theend of its useful life.

Life This number represents the length of the assets useful life.

PeriodThis number represents the period that the depreciation is to be calculated for. Itcannot exceed the life of the asset.

Page 127 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 128: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 128/139

  column - print_position

Rule 2: If the current print position is greater than column, then column-1 spaces are printed on thenext line.

If a line width is specified (using the Width statement), then the column position is adjusted asfollows before applying the above two rules:

column = column Mod width%

Tab is useful for making sure that output begins at a given column position, regardless of the lengthof the data already printed on that line.

Example:

Sub Main()

`This example prints three column headers and three numbers

`aligned below the column headers.Print "Column1"; Tab(10); "Column2"; Tab(20); "Column3"Print Tab(3); "1"; Tab(14); "2"; Tab(24); "3"

End Sub

Tan

Tan#(angle#)

Descr. Returns the tangent of an angle.

angle is given in radians.

Example:

Sub Main()

'This example computes tangent of PI/4 radians (45 degrees)C# = Tan(PI / 4)MbeMessageBox "The Tangent of 45 Degrees is: " + Str$(C)

End Sub

Time$

Time$[()]Time$ = newtime$

Descr. As a function, Time$ returns the system time as an 8 character string. As a statement, Time$ sets the system time to the time contained in the specified string.

The format of the time string is HH:MM:SS. A 24 hour clock is used.

Example:

Page 128 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 129: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 129/139

  This example illustrates use as a function.

Sub Main()'Returns the system time and displays it in a dialog boxTi$ = Time$Msg$ = "Time was: " + Ti + crlfTime$ = "10:30:54"Msg = Msg + "Time set to: " + Time$ + crlfTime$ = TiMsg = Msg + "Time restored to: " + Time$MbeMessageBox Msg

End Sub

Example:

This example illustrates use as a statement.

Sub Main()'Returns the system time and displays it in a dialog boxTi$ = Time$

Msg$ = "Time was: " + Ti + crlfTime$ = "10:30:54"Msg = Msg + "Time set to: " + Time$ + crlfTime$ = TiMsg = Msg + "Time restored to: " + Time$MbeMessageBox Msg

End Sub

Timer

Timer&

Descr. Returns the number of seconds that have elapsed since midnight.

Example:

Sub Main()

'Displays the elapsed time between execution start and the`time you clicked the Ok button on the first messageA& = Timer

MbeMessageBox "Click the Ok button Please"B& = Timer - AMbeMessageBox "The elapsed Time was: " + Str$(B) + " seconds"

End Sub

TimeSerial

TimeSerial#(hour%, minute%, second%)

Descr. Returns a double-precision number representing the given time with a date of zero. A Date ofzero is equal to Dec 30, 1899

Page 129 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 130: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 130/139

Example:

Sub Main()

T1# = TimeSerial(10,22,30)T2# = TimeSerial(10,35,27)Tdif# = Abs (T1 - T2)

MbeMessageBox "The Difference is: " + Format$(Tdif, "hh:mm:ss")End Sub

TimeValue

TimeValue#(time_string$)

Descr. Returns a double-precision number representing the time contained in the specified stringargument.

This function interprets the passed time_string$ parameter looking for a valid time specification.

The time_string$ parameter can contain valid time items separated by time separators such as colon`:' or period `.'.

Time strings can contain an optional date specification, but this is not used in the formation of thereturned value.

If a particular time item is missing, then the missing time items are set to zero. For example, thestring "10 pm" would be interpreted as "22:00:00".

Example:

Sub Main()

'This example calculates the TimeValue of the current time and'Displays it in a dialog box.T1$ = "10:15"T2# = TimeValue(T1$)MbeMessageBox "The Timevalue of " + T1 + " is: " + Str$(T1)

End Sub

Trim$

Trim$(str$)

Descr. Returns the a copy of the passed string expression (str$) with leading and trailing spacesremoved.

Example:

const crlf$ = chr$(13) + chr$(10)

Sub Main()

Page 130 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 131: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 131/139

  'This example uses the Trim$ function to extract the non-blank part'of a string and display it:Tx$ = " This is Text "Te$ = Trim$(Tx)MbeMessageBox "Orig =>" + Tx + "<=" + crlf + "Trimmed =>" + Te + "<="

End Sub

True

Descr. -1, used in conditionals and boolean expressions

Example:

Sub Main()

'This example sets variable a to True and then tests to see if

'(1) A is True; (2) if the True constant = -1; and (3) if A is'equal to -1 (True).a = Trueif ((A =True) and (True = -1) and (A = -1)) then

MbeMessageBox "A is True"Else

MbeMessageBox "A is False"End If

End Sub

Type

Type usernamevariable As typevariable As typevariable As type:

End Type

Descr. The Type statement creates a structure definition which can then be used with the Dim statement to declare variables of that type. The username field specifies the name of the structurethat is used later with the Dim statement.

Within a structure definition appear field descriptions in the format:

variable As type

where variable is the name of a field of the structure, and type is the data type for that variable. Anyfundamental data type or previously declared user-defined data type can be used within the structuredefinition (structures within structures are allowed). Only fixed arrays can appear within structuredefinitions.

Type can only appear outside of subroutine and function declarations.

Example:

Page 131 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 132: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 132/139

'This example displays the use of the Type statement to create a structure

'representing the parts of a circle and assign values to them.Type Circ

Msg As StringRad As IntegerDia As IntegerAre As DoubleCir As Double

End TypeSub Main()

Dim Circle As CircCircle.Rad = 5Circle.Dia = Circle.Rad * 2Circle.Are = Circle.Rad ^ 2 * PiCircle.Cir = Circle.Dia * PiCircle.Msg = "The Area of the Circle is: " + Str$(Circle.Are)MbeMessageBox Circle.Msg

End Sub

UBound

UBound%(ArrayVariable() [, dimension%])

Descr. Returns the upper bound of the specified dimension of the specified array variable.

The first dimension (1) is assumed if dimension is not specified.

Example:

Sub Main()

'This example dimensions two arrays and displays their upper boundsDim A(5 To 12)Dim B(2 To 100, 9 To 20)UBa = UBound(A)UBb = UBound(B,2)MbeMessageBox "Upper Bnd A: " + Str$(UBa) + " Upper Bnd B: " + Str$(UBb)'This example uses Lbound and Ubound to dimension a dynamic array to'hold a copy of an array redimmed by the FileList statement.Dim FL$()FileList FL,"*.*"count = Ubound(FL)Redim NL$(Lbound(FL) To Ubound(FL))For X = 1 To count

NL(X) = FL(X)Next xMbeMessageBox "The last element of the new array is: " + NL(count)

End Sub

UCase$

UCase$(str$)

Descr. Returns the upper case equivalent of the specified string.

Page 132 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 133: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 133/139

Example:

Sub Main()

'This example uses the UCase$ function to change a string from lower'to upper case.A1$ = "This string was lower case"

A2$ = UCase$(A1)MbeMessageBox A2End Sub

UnLock

Unlock [#] filenumber% [,{record& | [start&] To end&}]

Descr. The Unlock  statement unlocks a section of the specified file, allowing other processes access

to that section of the file.

The filenumber parameter is a number that is used to refer to the open file--the number passed to theopen statement.

For sequential files, the record, start and end parameters are ignored--the entire file is unlocked.

The section of the file is specified using one of the following:

The unlock range must be the same as that used by the Lock  statement.

Example:

const crlf$ = chr$(13) + chr$(10)

Sub Main()'This example creates Test2.DAT and fills it with 10 string variable'records. These are displayed in a dialog box. The file is then'reopened for read/write and each record is Locked, modified,'rewritten and unlocked. The new records are then displayed in a'dialog box.A$ = "This is record number: "B$ = "0"

Rec$ = ""Msg$ = ""Open "Test2.Dat" for random access write shared as #1For x% = 1 To 10

Syntax Description

<none> unlock the entire file (no record specification is given)

record unlock the specified record number (for Random files) or byte (for Binary files)

to endunlock from the beginning of the file to the specified record (for Random files) or byte(for Binary files)

start toend

unlock the specified range of records (for Random files) or bytes (for Binary files)

Page 133 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 134: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 134/139

  Rec = A + Str$(x)Lock #1,xPut #1,,RecUnlock #1,xMsg = Msg + Rec + crlf

Next xCloseMbeMessageBox "The Records are: " + crlf + Msg

Msg = ""Open "Test2.Dat" For Random Access Read Write Shared As # 1For x = 1 to 10

Rec = Mid$(Rec,1,23) + Str$(11-x)Lock #1,x 'lock it for our usePut #1,x,Rec 'nobody's changed itUnLock #1,xMsg = Msg + Rec + crlf

Next xMbeMessageBox "The Records are: " + crlf + Msgclose

End Sub

Val

 Val#(number$)

Descr. Converts a given string expression to a number.

The number$ parameter can contain any of the following:

Leading minus sign (for non hex or octal numbers only) Hexadecimal number in the format: &H<hex digits> Octal number in the format: &O<octal digits> Floating point number, which can contain a decimal point and optional exponent

Spaces, tabs and linefeeds are ignored.

If number$ does not contain a number, then 0 is returned.

The Val function continues to read characters from the string up to the first non-numeric character.

Val always returns a double-precision floating point value. This value is forced to the data type ofthe assigned variable.

Example:

Sub Main()

'This example inputs a number string from an MbeInputBox and converts`it to a number variable.A$ = MbeInputBox$("Input a Number String")B# = Val(A)MbeMessageBox "The converted values is: " + Str$(B)

End Sub'The following table shows valid strings and their numeric equivalent:' "1 2 3" 123' "12.3" 12.3

Page 134 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 135: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 135/139

 ' "&HFFFF" -1' "&O77" 63' "12.345E-02" .12345

Weekday

 Weekday%(serial#)

Descr. Returns the day of the week specified by the given date/time serial value. Sunday is 1,monday is 2, and so on.

Example:

Sub Main()

'This example gets a date in an input box and displays

'the day of the week and it's name for the date entered.Dim A$(7)A(1) = "SUNDAY"A(2) = "MONDAY"A(3) = "TUESDAY"A(4) = "WEDNESDAY"A(5) = "THURSDAY"A(6) = "FRIDAY"A(7) = "SATURDAY"Bd$ = MbeInputBox$("Please Enter Your Birthday")Dt = DateValue(Bd)Dw = WeekDay(Dt)MbeMessageBox "You were born on " + Str$(Dw) + ", which was a " + A(Dw)

End Sub

While...Wend

 While condition[statements]

 Wend

Descr. Repeats a statement or group of statements while a condition is TRUE.

Example:

Sub Main()

'This example executes a While loop until the random number'generator returns a value of 1X% = 0Count% = 0

 While X <> 1 And Count < 500X = Rnd(1)Count = Count + 1

 WendMbeMessageBox "The loop executed " + Str$(count) + " times."End Sub

Page 135 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 136: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 136/139

Width#

 Width #filenumber%, newwidth%

Descr. The Width statement specifies the line width for sequential files opened in either Output orAppend modes.

filenumber is a number that is used to refer to the open file--the number passed to the Open statement.

When a file is initially opened, there is no limit to line length. This command forces all subsequentoutput to the specified file to use the specified value as the maximum line length.

newwidth can be any integer from 0 to 255 inclusive. If newwidth is zero, no maximum line length isused.

Width affects output in the following manner: if the column position is greater than 1 and the lengthof the text to be written to the file causes the column position to exceed the current line width, thenthe data is written on the next line.

Width also affects output of the Print command when used with Tab and Spc functions.

Example:

Sub Main()

'See Print statement'This statement sets the maximum line width for file number 1 to 80'columns

 Width #1,80End Sub

Word$

 Word$(text$, first%[, last%])

Descr. Returns a single word or sequence of words between first and last.

This function extracts words from a text source.

The first parameter specifies the first word in the sequence to return. If last is not specified, then onlythat word is returned. If last is specified, then all words between first and last will be returned,including all spaces, tabs and end-of-lines that occur between those words.

Words are separated by any non-alphanumeric characters such as spaces, tabs, end-of-lines and punctuation.

If first is greater than the number of words in text$, then an empty string is returned.

If last is greater than the number of words in text$, then all words from first to the end of text are

Page 136 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 137: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 137/139

returned.

Example:

Sub Main()

'This example extracts two words from the string.

A$ = "My last name is Williams, Stuart is my surname."C$ = Word$(A,5,6)MbeMessageBox "The extracted name is: " + C

End Sub

WordCount

WordCount%(text$)

Descr. Returns the number of words in the specified text.

Words are separated by spaces, tabs and end-of-lines.

Example:

Sub Main()

'This example counts the number of words in a particular stringA$ = "My last name is Williams, Stuart is my surname."D! = WordCount(A)

MbeMessageBox "The String has " + Str$(D) + " words"End Sub

Write #

 Write [#]filenumber% [, expressionlist]

Descr. This statement writes a list of expressions to a given sequential file.

The file referenced by filenumber must be opened in either Output or Append mode. filenumber is anumber that is used to refer to the open file--the number passed to the Open statement.

Write outputs data items separated with commas. Strings are output enclosed within quotationmarks. After writing each expression in the list, Write outputs an end-of-line.

Write can only be used with files opened in Output or Append modes.

Example:

const crlf$ = chr$(13) + chr$(10)

Sub Main()'This example opens a file for sequential write then writes ten'records into the file with the values 10..100. Then the file

Page 137 of 139A to Z Reference

12/18/2006file://C:\Documents and Settings\thiha.aung\Local Settings\Temp\~hh56CE.htm

Page 138: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 138/139

Page 139: Basic Help Microstation

7/25/2019 Basic Help Microstation

http://slidepdf.com/reader/full/basic-help-microstation 139/139

  Next xMbeMessageBox Msg

End Sub

Year

Year%(serial#)

Descr. Returns the year of the date encoded in the specified serial parameter. The value returned is(100 <= serial <= 9999) inclusive.

Example:

Sub Main()

'This example returns the current Year in a dialog box.

Dim TDay as LongTdate$ = Date$TDay! = Year(DateValue(Tdate))MbeMessageBox "The current Year is: " + Str$(TDay)

End Sub

Page 139 of 139A to Z Reference