O'Reilly logo

Microsoft® Windows® Scripting Self-Paced Learning Guide by Ed Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

If...Then

If...Then is one of those programming staples (like fried chicken and mashed potatoes are staples in the southern United States). What’s nice about If...Then is that it makes sense. We use this kind of logic all the time.

The basic operation is diagrammed here:

If

condition

Then

action

If

store is open

Then

buy chicken

The real power of If...Then comes into play when combined with tools such as those we looked at in Chapter 2. If...Then is rarely used by itself. Although you could have a script such as this one, you wouldn’t find it extremely valuable:

Const a = 2
Const b = 3
Const c = 5
If a + b = c Then
    WScript.Echo(c)
End If

In this script are defined three constants: a, b, and c. We then sum the numbers and evaluate the result by using the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required