LMD ScriptPack Guide


Expressions


NativeVB language supports a variety set of expressions to allow script program to assign variables, call procedures and functions, accessing objects properties (including indexed properties), perform logical and math operations and more.

 

Literals

 

NativeVB supports Integer, floating-point, string and date literals, as well as Null, Empty, Nothing, True and False keywords. Here are some examples:

 

= 7
= -7
= 7.0
= +0.25E+10
= "Some string"

 

Integers in hexadecimal form are also supported:

 

= &A23BD7

 

String literals use double-quotes syntax, including the possibility to escape the quote char:

 

= "This is a string containing a single "" symbol"
= "This is a " & Chr(13) & Chr(10) & "two line string"

 

Date literals use # symbol to quote literal content. Date literals consist of date and time portions split by any valid white space. Either the date or time portions are optional, but al least one, of course, should be specified. The order of date and time portions are not important, you can write a date first, and then a time, or a time first, and then a date. Time format is hh:mm:ss; seconds is optional. Valid time delimiters are ":" and ".". "AM" and "PM" can be also specified in a time part. Date format is yyyy-mm-dd; year is optional, and if omit - will be replaced with current year. Valid date delimiters are "-", "/", "," and any white space. Here are some date literal examples:

 

dt = #2000-10-01 12:00#
dt = #2000/10 01 11:00.03 PM#
t  = #12:33:00#
d  = #1999-01-01#

 

The Nothing is used to denote no-object value. It is represented as a Variant with VType = varDispatch and VDispatch = nil;

The Empty is used to denote not yet assigned (or empty) variable. It is represented as a Variant with VType = varEmpty.

The Null is used to denote database NULL value, which has the meaning of unknown/unspecified value; represented as a Variant with VType = varNull.

 

Operators

 

The following operators are supported by NativeVB language:

 

Imp

Logical/bitwise implication

Eqv

Logical/bitwise equivalence

>

Greater than

<

Less than

>=

Greater or equal

<=

Less or equal

<>

Not equal

=

Equal

Is [Not]

Equivalent to "=" or "<>" operators.

+

Addition.

&

String concatenation

-

Substraction

*

Multiplication

/

Division

\

Integer division

Mod

Modulus

Or

Logical or. "Incomplite Boolean eval" logic is used.

Xor

Logical/bitwise xor

And

Logical and. "Incomplite Boolean eval" logic is used.

Not

Unary logical not

TypeOf Is

Value is of type. Used with imported from Delphi class and record types to test whether the object or record instance is of specified type; for example:

If TypeOf obj Is TButton Then

If TypeOf rec Is TPoint Then

 

Incomplite Boolean evaluation

 

The And and Or operators use incomplite Boolean evaluation logic, just like in Delphi. That is, the second operand is evaluated only when necessary. The following examples demonstrate the advantage of this evaluation strategy:

 

If (obj <> Nothing) And (obj.Width < 100) Then
  DoSomething
End If
 
If (obj = Nothing) Or (obj.Width >= 100) Then
  DoSomething
End If

 

In both cases obj.Width will be evaluated only if obj is not equal to Nothing. In both cases no error is possible, because when the obj is Nothing, the second part of the expression is not evaluated.

 

Calling object methods and accessing properties

 

NativeVB uses MS VBScript like syntax to call subs/function as well as object methods/properties. Parameters in sub call should be specified after a sub name without brackets:

 

MySub 5, 7

 

While parameters of function and indexed properties used in expressions should be specified in round brackets:

 

= MyFunc(5, 7)
= obj.MyMethod(3, 4)
= Application.MainForm.Caption
= Memo.Lines.Items(5) 'Indexed property

 

It is also possible to use classic Call statement to call subs/functions and object methods:

 

Call MyFunc(5, 7)
Call obj.MyMethod

 

Event handlers

 

NativeVB supports creating a references to procedures written in script-code and assigning these references to events of objects. This can be done using GetRef intrinsic function:

 

Sub Button1Click(Sender)
  MsgBox("Hello from script")
End Sub
 
Button1.OnClick = GetRef("Button1Click")

 

The global code from the above example assigns a procedure written in script-code to the OnClick button's event. After assignment, clicking on the button will execute Button1Click procedure.