Grammar
Op is one of asignment operators: '=', '+=', '-=', '*=', '/=', '&=', '~=', '^='. The reduced modifier is used to avoid a memory leak. The reduced assignment[Reduced][TerminalOf] Expr1 Op [AddressOf [TerminalOf]] Expr2meansreduced A = Eif A is array and E is element of A. Otherwise it means:Dim temp = E E = NULL delete A A = tempdelete A A = EThe TerminalOf at the left part of the assignment statement should be used only when Expr1 is alias and AddressOf is presented at the right part of the statement. (Because TerminalOf Expr1 = Expr2 produces the same assignment as Expr1 = Expr2 in all another cases). When AddressOf is presented at the right part, the use of TerminalOf in the left part allows you to assign alias of Expr2 to terminal of Expr1. For example:
It producesDim A[10], B, C, P B = 300 C = 500 P = AddressOf A(5) TerminalOf P = AddressOf B MsgBox P MsgBox A[5] P = AddressOf C MsgBox A[5] MsgBox PThe TerminalOf at the left part of the assignment statement should be used only when Expr2 is an alias. In this case, the use of TerminalOf allows you to assign Expr1 as alias of terminal of Expr2. For example300 300 300 500This example illustrates how the search of most general unifier works (mechanical theorem proving). T1 and T2 represent terms, P1 and P2 are parameters of T1 and T2 accordingly. The last statementDim P1 = "X" Dim P2 = "Y" Dim T1 = ["R", ["F", AddressOf P1]] Dim T2 = ["R", AddressOf P2] Dim Q1 = AddressOf T1[1] Dim Q2 = AddressOf T2[1] TerminalOf Q2 = AddressOf TerminalOf Q1changes parameters, not source terms.TerminalOf Q2 = AddressOf TerminalOf Q1See Also
- Dim Statements
/ul>
Declares the name of a class, as well as a definition of the variables, properties, and methods that comprise the class.Grammar
ClassStmt -> Class Ident [Inherits AncestorClass] MemberStatement /... End Class MemberStatement -> DimStmt | SubStmt | PropertyStmt |Arguments
IdentName of the classAncestorClassOptional. Name of the ancestor class.MemberStatementAll constructors must have name New.One or more statements that define the variables, properties, and methods of the class.Example
class Point Dim X As Integer, Y As Integer Sub New(X As Integer, Y As Integer) Me.X = X Me.Y = Y End Sub End Class Class Circle Inherits Point Dim R Sub New(X As Integer, Y As Integer, R As Integer) MyBase.New(X, Y) Me.R = R End Sub End Class Dim P As Point = new Point(3, 5), C As Circle = new Circle(3, 5, 7) print P, CSee Also
Destroys variable or its terminalGrammar
DeleteStmt -> Delete [TerminalOf] Expression
Declares a variable.Grammar
DimStmt -> [Shared] Dim Variable ['(' Subscripts ')'] [ = Value ] /,... Subscripts -> Upperbound /','...Arguments
VariableThe name of the variable being declared.ValueThe initial value assigned to the variable.SubscriptsDimensions of an array variable.UpperboundUpper bound. The lower bound of an array is always zero.SharedUse the dim statement to declare variables. These variables can be assigned values at declaration or later in your script.Optional. The class keyword specifies a static (shared) field of a class. Can be used only inside of a class body.Example 1
Dim A(30, 4) Dim X = [10, 20, 30] Dim Y Dim Z = New TObject()You can use the dim statement inside of a class body. In such case the statement declares a field of a class instance or a static (shared) field of the class.Example 2
Class MyClass Dim A(10, 2) Dim X Dim Y = [100, 200, 300] Shared Dim Z = 5 End ClassSee Also
Repeats a block of statements while a condition is True or until a condition becomes True.Grammar
DoStmt -> DoStmt1 | DoStmt2 DoStmt1 -> Do [{While | Until} Condition] [Statements] [Exit Do] [Statements] Loop DoStmt2 -> Do [Statements] [Exit Do] [Statements] Loop [{While | Until} Condition]Arguments
ConditionA Boolean expression. If condition is null or undefined, condition is treated as false.StatementsOne or more statements that are repeated while or until condition is True.Example 1
Dim x As Integer = 10 Do print x If x = 5 Then Exit Do End If x = x - 1 Loop Until x = 0Example 2
Dim x As Integer = 10 Do While x > 0 print x x = x - 1 If x = 5 Then Exit Do End If LoopSee Also
Creates enumeration typeGrammar
EnumStmt -> Enum TypeName Ident { = Number } .............. End EnumExample
Enum E A B = 10 C End Enum Dim X As E print X.A print X.B print X.C
Exits a block of Do...Loop, For...Next, Function, or Sub code.Grammar
ExitStmt -> Exit Do | Exit For | Exit Function | Exit Property | Exit Sub |Arguments
Exit DoProvides a way to exit a Do...Loop statement.Exit ForProvides a way to exit a For loop.Exit FunctionImmediately exits the Function procedure in which it appears.Exit PropertyImmediately exits the Property procedure in which it appears.Exit SubImmediately exits the Sub procedure in which it appears.Example 1
x = 10 Do While x > 0 print x x = x - 1 If x = 5 Then Exit Do End If LoopExample 2
For i = 5 to 1 Step -1 If i = 2 Then Exit For End If print i NextSee Also
Repeats a group of statements a specified number of times.Grammar
For-NextStmt -> For Counter = InitialValue To FinalValue [Step StepValue] [Statements] [Exit For] [Statements] Next [ NextExpressionList ] NextExpressionList -> Counter/','...Arguments
CounterNumeric variable used as a loop counter. The variable can't be an array element or an element of a user-defined type.InitialValueInitial value of Counter.FinalValueFinal value of Counter.StepValueAmount Counter is changed each time through the loop. If not specified, StepValue defaults to one.StatementsOne or more statements between For and Next that are executed the specified number of times.Example 1
For i = 5 to 1 Step -1 If i = 2 Then Exit For End If print i NextA Next statement with one or more variables will, from left to right, close the For loops that match each variable. If a variable closes a For loop that is not the most nested loop at that point, a compile-time error results.Example 2
Dim I, J For I = 1 To 2 For J = 1 to 3 print I, " ", J Next J, ISee Also
Declares the name, arguments, and code that form the body of a function.Grammar
FunctionStmt -> [Shared] Function Ident ['(' FormalParam/','... ')'] ';' Statements End Function FormalParam -> [ByRef] ParameterArguments
IdentName of function.ParameterRepresents formal parameter of function. The ByRef keyword indicates that the argument is passed by reference.StatementsOne or more statements separated by colons.SharedOptional. The shared keyword specifies a static (shared) method of a class. Can be used only inside of a class body.Example 1
Function Fact(N) If N = 1 Then return 1 Else return N * Fact(N - 1) End If End FunctionYou can use the function statement inside of a class body. In such case the statement declares a method of the class.Example 2
Class MyClass Dim Z = "abc" Sub New() End Sub Function DoubleZ() return Z + Z End Function Shared Function Hello() return "Hello " + ClassName End Function End ClassSee Also
Conditionally executes a group of statements, depending on the value of an expression.Grammar
IFStmt -> If Condition Then Statements [ElseIf Condition-n Then ElseifStatements] /... [Else ElseStatements] End IfArguments
ConditionA Boolean expression. If condition is null or undefined, condition is treated as false.Condition-nThe same as Condition.StatementsOne or more statements separated by colons; executed if Condition is True.ElseifStatementsOne or more statements executed if the associated Condition-n is True.ElseStatementsOne or more statements executed if no previous Condition or Condition-n expression is True.Example 1
If y = 6 Then z = 17 End IfExample 2
If x > 0 Then s = 1 ElseIf x < 0 Then s = -1 Else s = 0 End IfSee Also
Imports statements are provided to facilitate the use of namespaces.Grammar
ImportsStmt -> imports NamespaceName, /','... ';'Example
Imports StdCtrls, Forms Dim F = new TForm(NULL), B = new TButton(F) F.Show B.Parent = F B.OnClick = AddressOf AHandler B.Caption = "Click Me" Function AHandler(Sender) print "You have clicked the button" End FunctionSee Also
- Namespace Statements
/ul>
Programs are organized using namespaces. You can consider the namespace as a class which contains only static (shared) members.Grammar
NamespaceStmt -> Namespace Statements End NamespaceArguments
StatementsOne or more statements separated by colons.Example
Namespace Shapes Dim ShapeCount, ShapeList[100] Sub RegisterShape(S) ShapeCount += 1 ShapeList[ShapeCount] = S End Sub Class Point Dim X, Y Sub New(X, Y) Me.X = X Me.Y = Y RegisterShape(Me) End Sub End Class Class Square Dim X1, Y1, X2, Y2 Sub New(X1, Y1, X2, Y2) Me.X1 = X1 Me.Y1 = Y1 Me.X2 = X2 Me.Y2 = Y2 RegisterShape(Me) End Sub End Class End Namespace Dim P = Shapes.Point(3, 5) print PSee Also
- Imports Statements
/ul>
Prints value of an expression.Grammar
PrintStmt -> print Expression /','...Example
print 4 * 100 div 7
Executes one of several groups of statements, depending on the value of an expression.Grammar
Select Case TestExpression [Case ExpressionList [Statements]] /... [Case Else ExpressionList [ElseStatements]] End SelectArguments
TestExpressionAny numeric or string expression.ExpressionListDelimited list of one or more expressions.StatementsOne or more statements executed if testexpression matches any part of ExpressionList.ElseStatementsIf TestExpression matches any Case ExpressionList expression, the statements following that Case clause are executed up to the next Case clause, or for the last clause, up to End Select. Control then passes to the statement following End Select. If TestExpression matches an ExpressionList expression in more than one Case clause, only the statements following the first match are executed. The Case Else clause is used to indicate the ElseStatements to be executed if no match is found between the TestExpression and an expressionlist in any of the other Case selections. Although not required, it is a good idea to have a Case Else statement in your Select Case block to handle unforeseen TestExpression values. If no Case ExpressionList matches TestExpression and there is no Case Else statement, execution continues at the statement following End Select.One or more statements executed if testexpression doesn't match any of the Case clauses.Example
Dim x = 10 Select Case x Case 1 print "one" Case 2 print "two" Case 3 print "three" Case Else print "else" End SelectSee Also
- If Statements
/ul>
Declares the name, arguments, and code that form the body of a procedure.Grammar
SubStmt -> [Shared] procedure Ident ['(' FormalParam/','... ')'] ';' Statements End Sub FormalParam -> [ByRef] ParameterArguments
IdentName of procedure.ParameterRepresents formal parameter of procedure. The ByRef keyword indicates that the argument is passed by reference.StatementsOne or more statements separated by colons.SharedOptional. The class keyword specifies a static (shared) method of a class. Can be used only inside of a class body.Example 1
Sub Hanoi(N, X, Y, Z) If N > 0 Then Hanoi N - 1, X, Z, Y print "Transfer a ring from " + X + " to " + Y Hanoi N - 1, Z, Y, X End If End SubYou can use the sub statement inside of a class body. In such case the statement declares a method of the class.Example 2
Class MyClass Dim Z = "abc" Sub New() End Sub Sub PrintZ() print Z End Sub Shared Sub PrintHello() print "Hello " End Sub End ClassSee Also
A property, like a field, defines an attribute of an object. But while a field is merely a storage location whose contents can be examined and changed, a property associates specific actions with reading or modifying its data. Properties provide control over access to an object’s attributes, and they allow attributes to be computed.Grammar
PropertyStmt -> [Default] property Ident [ParamList] [ Get Statements End Get ] [ Set Statements End Set ] End Property ParamList -> '(' Param/','... ')'Arguments
IdentName of propertyOptionalOptional. Parameter of indexed property.StatementsOne or more statements separated by colons.DefaultOptional. Specifies an indexed property which is array property. A class can have only one default property.Example
Class AClass Dim fZ = [10, 20, 30, 40, 50] Sub New() End Sub Default Property Z(I) Get return fZ(I) End Get Set fZ(I) = Value End Set End Property End Class Dim X = new AClass() X(1) = 90 print XSee Also
- Class Statements
/ul>
Declares the name of a structure type, as well as a definition of the variables, properties, and methods that comprise the structure.Grammar
StructureStmt -> Structure Ident [Inherits Ancestor] MemberStatement /... End Structure MemberStatement -> DimStmt | SubStmt | PropertyStmt |Arguments
IdentName of structureAncestorOptional. Name of ancestor structure type.MemberStatementOne or more statements that define the variables, properties, and methods of the structure.Example
Structure RandomPoint Dim X As Integer = rnd(0, 100) Dim Y As Integer = rnd(0, 100) End Structure Structure RandomCircle Dim R As Integer = rnd(0, 100) End Structure Dim C As RandomCircle print CSee Also
- Class Statements
/ul>
Generates an error condition that can be handled by a try...except or try...finally statement.See Also
Exceptions are handled within try...catch statements.Grammar
TryExceptStmt -> Try TryStatements Catch [Expression] [CatchStatements] End TryArguments
TryStatementsRequired. Statements where an error can occur.ExpressionOptional. Represents an exception object.CatchStatementsThe TryStatements contain code where an error can occur, while CatchStatements contain the code to handle any error that does occur. If an error occurs in the TryStatements, program control is passed to CatchStatements for processing. The initial value of exception is the value of the error that occurred in TryStatements. If no error occurs, CatchStatements are never executed.Optional. Statements to handle errors occurring in the associated TryStatements.Example
Try Try Throw 100 Catch E print "catch" print E End Try Finally print "finally" End TrySee Also
Sometimes you want to ensure that specific parts of an operation are completed, whether or not the operation is interrupted by an exception. In these situations, you can use a try...finally statement.Grammar
TryFinallyStmt -> Try TryStatements Finally FinallyStatements End TryArguments
TryStatementsA sequence of statements (delimited by colons).FinallyStatementsThe try-finally statement executes the statements in TryStatements (the try clause). If TryStatements finishes without raising exceptions, FinallyStatements (the finally clause) is executed. If an exception is raised during execution of TryStatements, control is transferred to FinallyStatements; once FinallyStatements finishes executing, the exception is re-raised. If an exception is raised but not handled in the finally clause, that exception is propagated out of the try...finally statement, and any exception already raised in the try clause is lost. The finally clause should therefore handle all locally raised exceptions, so as not to disturb propagation of other exceptions.Optional. Statements that are unconditionally executed after all other error processing has occurred.Example
Try Try Throw 100 Catch E print "catch" print E End Try Finally print "finally" End TrySee Also
The while statement executes its constituent statement repeatedly, testing Condition expression before each iteration. As long as Condition returns True, execution continues.Grammar
WhileStmt -> While Condition Statement /... End WhileArguments
ConditionA Boolean expression. If condition is undefined, condition is treated as false.StatementAny statementExample
Dim i = 0 While i <= 5 Print i i = i + 1 End WhileSee Also
The with statement is a shorthand for referencing the the fields, properties, and methods of an object.Grammar
WithStmt -> With Obj /','... Statement /... End WithArguments
ObjA variable reference denoting an object.StatementAny statementExample
With Form1 .Caption = "My Form" .Height = 200 .Width = 300 End WithSee Also
- Class Statements
/ul>