Global 定义全局变量
🎯功能
定义全局变量, 作用范围是同个脚本内多条线程有效, 停止脚本后清除.
📜语法
Global 变量名
📥参数
参数 | 数据类型 | 解释 |
---|---|---|
变量名 | 标识符 | 任意有效标识符 |
📤返回
无
💡示例
Dim a
Global env_a, env_b(1)
a = "普通变量"
env_a = "环境变量"
env_b(0) = "环境数组0"
env_b(1) = "环境数组1"
TracePrint "主线程中a = " & a
TracePrint "主线程中env_a = " & env_a
TracePrint "主线程中env_b(0) = " & env_b(0)
TracePrint "主线程中env_b(1) = " & env_b(1)
BeginThread 线程取值
Delay 1000
TracePrint "修改后主线程中a = " & a
TracePrint "修改后主线程中env_a = " & env_a
TracePrint "修改后主线程中env_b(0) = " & env_b(0)
TracePrint "修改后主线程中env_b(1) = " & env_b(1)
Sub 线程取值()
TracePrint "子线程中a = " & a
TracePrint "子线程中env_a = " & env_a
TracePrint "子线程中env_b(0) = " & env_b(0)
TracePrint "子线程中env_b(1) = " & env_b(1)
TracePrint "子线程修改值"
a = "修改后a"
env_a = "修改后环境a"
env_b(0) = "修改后环境数组0"
env_b(1) = "修改后环境数组1"
TracePrint "修改后子线程中a = " & a
TracePrint "修改后子线程中env_a = " & env_a
TracePrint "修改后子线程中env_b(0) = " & env_b(0)
TracePrint "修改后子线程中env_b(1) = " & env_b(1)
End Sub