Docsity

VBScript Variables, Operators, Decision Making, and Loops, Slides of Fundamentals of E-Commerce

Partial preview of the text

Download VBScript Variables, Operators, Decision Making, and Loops and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

Declaration - VIII

Some VBScript variable conversion functions •^

CDATE() – Returns an expression that has beenconverted to a Variant of subtype Date.

-^

CINT() - Returns an expression that has beenconverted to a Variant of subtype Integer.

-^

CSTR() - Returns an expression that has beenconverted to a Variant of subtype String.

Operators and Inequality - I

•^

VBScript uses operators just like algebra.^ –

  • is multiply

\ is integer divide

^ is power to (e.g. 3^2 is 3 squared.)

•^

Like algebra, VBScript inequalities work asexpected, e.g., compare two values or uselogical operators (and, or) to test multipleconditions. (more about this next)

Decision - II

•^

IF…THEN may be used to test ranges by using morecomplex inequalities.

-^

When using AND, both sides in () must be true.

If (I>=1) and (I<=9) then '1-9 Inclusive

•^

When using OR operator, indicates that theinequality is true if the cows are home or the sun isdown.

If (Cows = Home) or (Sun = Down) Then

Decision - III

•^

For more complex tests on a single variable, theSELECT CASE statement is preferred.

-^

Syntax:^ Select Case

myVarToBeTested

Case

Value

,^ Value

:

Case

Lower

TO

Upper

:

Case

Inequality

:

Case Else End Select

Loops - I

•^

Loops allow the enclosed block of code to berepeated.

-^

There are two kinds: WHILE…WEND and FOR…NEXT.

-^

While loops until some condition is met. It is good foriterating datasets and files.

-^

For loops for a fixed duration. They are good forcounting or enumerating a known number of times.

Loops –

•^

For Loop Syntax For

myVar

Start

to

Stop

[Step

Value

]

Loop Body (block of code to be repeated) Next •^

Alternately you can use the alternate syntax For Each

myVar

in

myEnumeration

Loop Body Next

Loops - 4

•^

The FOR loop can count backward by using theoptional STEP syntax:

For

I

= 10 To 1 Step –

•^

Step can be any reasonable value

For X = 2 to 4.2 Step 0.

•^

If the loop is impossible, (never iterates) thenthe code in the loop never executes

For X = 10 to 2

Loops - 5

•^

The WHILE…WEND loop can be used to loop basedon some inequality.

-^

As long as the condition evaluates to true, the blockof code inside is executed repeatedly. At the top ofthe loop, checks to see if the condition is still true, ifnot it exits the loop. I = 6While (I > 5)

I = I – 1 Wend