Statements

Old Content - visit altium.com/documentation

Parent page: VBScript

VBScript Statements

This section of the VBScript reference includes VBScript:
Conditional Statements
Expressions and Operators

Conditional Statements

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:

If Condition Then
  'code
Else If AnotherCondition Then
  'code
Else
  'code
End If

The For loop

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

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

The Exit For

The Exit For statement exits a For loop prematurely.

For counter = start to end
  if condition then Exit For
Next

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:

For Each ObjectVar in Collection
  ' block of code here
Next

The Do loop

The Do Loop has several loop variations.

Do while until condition
  ' code block
Loop

...and;

Do
  ' code block
Loop while until condition

...and;

Do
  ' code block
Loop

The While...WEnd loop

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

While until condition
  ' code block
WEnd

The Select Case statement

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

Select case payment
  case "Cash"
    msgbox "pay cash"
  case "MasterCard"
    msgbox "pay by Mastercard"
  case Else
    msgbox "Unknown payment method"
end select

Expressions and Operators

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 to 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 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

 

&

 

You are reporting an issue with the following selected text and/or image within the active document:
ALTIUM DESIGNER FREE TRIAL
Altium Designer Free Trial
Let’s get started. First off, are you or your organization already using Altium Designer?

If would like to speak with a representative, please contact your local Altium office.
Copyright © 2019 Altium Limited

In that case, why do you need an evaluation license?

If would like to speak with a representative, please contact your local Altium office.
Copyright © 2019 Altium Limited

Got it. You actually don’t need an evaluation license for that.

Click the button below to download the latest Altium Designer installer.

Download Altium Designer Installer

If would like to speak with a representative, please contact your local Altium office.
Copyright © 2019 Altium Limited

Please fill out the form below to get a quote for a new seat of Altium Designer.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.

If you are on Altium Subscription, you don’t need an evaluation license.

If you are not an active Altium Subscription member, please fill out the form below to get your free trial.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.

Why are you looking to evaluate Altium Designer?

If would like to speak with a representative, please contact your local Altium office.
Copyright © 2019 Altium Limited

You came to the right place! Please fill out the form below to get your free trial started.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.

Sounds exciting! Did you know we offer special discounted student licenses? For more information, click here.

In the meantime, feel free to request a free trial by filling out the form below.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.

Got it. You can download a free Altium Designer Viewer license which is valid for a 6 months.

Please fill out the form below to request one.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.

That’s great! Making things is awesome. We have the perfect program for you.

Upverter is a free community-driven platform designed specifically to meet the needs of makers like you.

Click here to give it a try!

If would like to speak with a representative, please contact your local Altium office.
Copyright © 2019 Altium Limited

Got it. You can download a free Altium Designer Viewer license which is valid for a 6 months.

Please fill out the form below to request one.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.