You need to be logged in to view this content. Please login or become a member.

<<  Prev   |   Index   |   Next  >>

Description

In this lesson we teach you how to use If – Then – Else statements to control which code is run under which conditions.

Notes

If you want to test the object type you can use the TypeOf keyword:

If TypeOf swApp Is SldWorks.SldWorks Then MsgBox "This is an ISldWorks object."

This will be particularly useful when programming with the SolidWorks API if you need to test for an object’s type.

Using Select Case to test for a condition is faster than using several If – Then statements in a row. This is because when using Select Case, the compiler jumps directly to the outcome of the evaluated expression.

Select Case is also limited to evaluating one condition, whereas with ElseIf, multiple conditions can be tested.

Lesson Files

Lesson 1.4 – select case code
Code snippets

Homework

Lesson 1.4 homework solution