Constants vs. Variables

上一篇 / 下一篇  2010-03-22 20:33:33 / 个人分类:VBScript

Compareing to Variable,there are several advantages by using a constant

1 The script. is easier to read

2 The script. is easier to revise

3 The script. is easier to reuse

 

Wrong example for variable

Option Explicit
On Error Resume Next

Dim total
Dim FirstValue
Dim SecondValue

FirstValue = 1
SecondValue = 3
Total = FirstValue + SecondValue

WScript.Echo " the total of " & FirstValue & " and " & _
  SecondValue & " Is " & (total)
FirstValue = Total
WScript.Echo " the total of " & FirstValue & " and " & _
  SecondValue & " Is " & (Total)

 

Executing the scripting The result is wrong like below:

C:\script.vbs H:CScript

Microsogt <R> Windows Script. Host Version 5.7

Copyright <C> Microsoft Corporation. All right reserved.

the total of 1 and 3 Is 4

the total of 4 and 3 Is 4

 

 

 

From
Microsoft® VBScript. Step by Step
By Ed Wilson


TAG:

 

评分:0

我来说两句

Open Toolbar