找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 5307|回复: 0

Global scope

[复制链接]

96

主题

158

回帖

4

精华

核心会员

积分
6513
发表于 2012-6-6 07:49:15 | 显示全部楼层 |阅读模式

'demonstrates the use of global variables and constants in a WSH scri

Option Explicit

'any variable or constant declared here will be available to
'all scripts in the document
Dim lngMyVar
Const my_Const=5

GetUserInput(  )
'use lngMyVar in unrelated procedures just to check whether it's global
MySecondProcedure
IncrementValue
MySecondProcedure
MultiplyConstant
MySecondProcedure

Sub GetUserInput(  )

   'lngMyVar does not need to be declared here - it's global
   lngMyVar = InputBox("Enter a Number: ", "Script-Level", 0)


End Sub

Sub MySecondProcedure(  )
   'display the value of lngMyVar
   MsgBox "lngMyVar: " & lngMyVar
End Sub

Sub IncrementValue

   'let's add the value of the global constant to lngMyVar
   lngMyVar = lngMyVar + my_Const

End Sub

Sub MultiplyConstant

   lngMyVar = lngMyVar + (my_Const * 2)

End Sub
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表