Statements

Nexus message

This documentation page references Altium NEXUS/NEXUS Client (part of the deployed NEXUS solution), which has been discontinued. All your PCB design, data management and collaboration needs can now be delivered by Altium Designer and a connected Altium 365 Workspace. Check out the FAQs page for more information.

 

Parent page: VBScript

Conditional Statements Copy Link Copied

The main conditional statements supported by VBScript are:

  • If...Then
  • For Next Loop
  • Exit For
  • For Each Next
  • Do Loop
  • While...WEnd
  • Select Case

Care needs to be taken to code scripts that avoid infinite loops — that is, ensuring that the conditions will eventually be met.

The If...Then Statement

The syntax is:

1If Condition Then
2  'code
3Else If AnotherCondition Then
4  'code
5Else
6  'code
7End If

The For Loop

The For Next statement repeatedly loops through a block of code. The basic syntax is:

1For counter = start to end
2  ' block of code here
3Next

The Exit For

The Exit For statement exits a For loop prematurely.

1For counter = start to end
2  if condition then Exit For
3Next

The For Each Loop

The For Each loop is a variation on the For loop which is designed to iterate through a collection of objects as well as elements in an array. The basic syntax is:

1For Each ObjectVar in Collection
2  ' block of code here
3Next

The Do Loop

The Do Loop has several loop variations.

1Do while until condition
2  ' code block
3Loop

...and;

1Do
2  ' code block
3Loop while until condition

...and;

1Do
2  ' code block
3Loop

The While...WEnd Loop

The While WEnd statement repeatedly loops through a block of code. The basic syntax is:

1While until condition
2  ' code block
3WEnd

The Select Case Statement

You can use the SELECT statement if you want to select one of many blocks of code to execute:

1Select case payment
2  case "Cash"
3    msgbox "pay cash"
4  case "MasterCard"
5    msgbox "pay by Mastercard"
6  case Else
7    msgbox "Unknown payment method"
8end select

Expressions and Operators Copy Link Copied

An expression is a valid combination of constants, variables, literal values, operators, and function results. Expressions are used to determine the value to assign to a variable, to compute the parameter of a function, or to test for a condition. Expressions can include function calls.

VBScript has a number of logical, arithmetic, Boolean and relational operators. Since these operators are grouped by the order of precedence which is different from the precedence orders used by Basic, C, etc. For example, the AND and OR operators have precedence compared to the relational one.

Arithmetic Operators

+

Addition

-

Subtraction

*

Multiplication

/

Division

\

Division with an integer result

^

Exponentiation

Mod

Modulo

Comparison Operators (Lowest Precedence)

=

Test whether equal or not.

<>

Test whether not equal or not.

<

Test whether less than or not.

>

Test whether greater than or not.

<=

Test whether less than or equal to or not.

>=

Test whether greater than or equal to or not.

Is

Compares two object reference variables.

String Operators

&

Concatenation

Logical Operators

Not

Logical NOT

And

Logical AND

Or

Logical OR

XOR

 

Eqv

 

Imp

 

&

 

If you find an issue, select the text/image and pressCtrl + Enterto send us your feedback.