VBScript 中的结束语158
VBScript是一种基于Visual Basic的轻量级脚本语言,广泛应用于网页和自动化任务。在VBScript中,使用不同的结束语来标识代码块并控制脚本的流。以下是VBScript中常用的结束语及其用途:
1. End If
结束If语句块。它指示脚本解释器If语句块已结束,并应继续执行代码的其余部分。If condition Then
' 执行代码
End If
2. End Select
结束Select Case语句块。它指示脚本解释器Select Case语句块已结束,并应继续执行代码的其余部分。Select Case value
Case 1
' 执行代码
Case 2
' 执行代码
End Select
3. End Sub
结束子例程。它指示脚本解释器子例程已结束,并应将执行控制权返回到调用代码。Sub MySubroutine()
' 执行代码
End Sub
4. End Function
结束函数。它指示脚本解释器函数已结束,并应将执行控制权返回到调用代码,并提供函数的返回值。Function MyFunction()
' 执行代码
MyFunction = result
End Function
5. End With
结束With语句块。它指示脚本解释器With语句块已结束,并应继续执行代码的其余部分。With object
' 执行代码
End With
6. Exit Sub
立即退出子例程。它使脚本解释器立即跳出子例程,并将执行控制权返回到调用代码。Sub MySubroutine()
' 执行代码
If condition Then Exit Sub
' 执行更多代码
End Sub
7. Exit Function
立即退出函数。它使脚本解释器立即跳出函数,并将执行控制权返回到调用代码,并提供函数的返回值。Function MyFunction()
' 执行代码
If condition Then Exit Function
' 执行更多代码
MyFunction = result
End Function
8. Exit For
立即结束For循环。它使脚本解释器立即跳出For循环,并将执行控制权传递到循环块之后的下一行代码。For i = 1 To 10
' 执行代码
If condition Then Exit For
Next
9. Exit Do
立即结束Do循环。它使脚本解释器立即跳出Do循环,并将执行控制权传递到循环块之后的下一行代码。Do
' 执行代码
If condition Then Exit Do
Loop
10. Exit While
立即结束While循环。它使脚本解释器立即跳出While循环,并将执行控制权传递到循环块之后的下一行代码。While condition
' 执行代码
If condition Then Exit While
Wend
11. Continue For
跳过For循环的当前迭代。它使脚本解释器跳过For循环的当前迭代,并继续执行循环的下一迭代。For i = 1 To 10
' 执行代码
If condition Then Continue For
Next
12. Continue Do
跳过Do循环的当前迭代。它使脚本解释器跳过Do循环的当前迭代,并继续执行循环的下一迭代。Do
' 执行代码
If condition Then Continue Do
Loop
13. Continue While
跳过While循环的当前迭代。它使脚本解释器跳过While循环的当前迭代,并继续执行循环的下一迭代。While condition
' 执行代码
If condition Then Continue While
Wend
14. Resume Next
恢复执行。它使脚本解释器从发生错误的行后继续执行代码。On Error Resume Next
' 执行代码
If 0 Then
' 处理错误
End If
15. Resume Label
恢复执行到指定的标签。它使脚本解释器从指定的标签继续执行代码。On Error GoTo ErrorHandler
' 执行代码
ErrorHandler:
' 处理错误
Resume MyLabel
' 执行更多代码
MyLabel:
' 执行更多代码
2025-01-20
Windows下脚本编程实例
https://jb123.cn/jiaobenbiancheng/32614.html
深入浅出理解 Perl 中的 open 函数
https://jb123.cn/perl/32613.html
物理编程脚本:从零到精通
https://jb123.cn/jiaobenbiancheng/32612.html
Python编程小熊:初学者指南
https://jb123.cn/python/32611.html
Perl locate 命令:在文件中快速定位模式
https://jb123.cn/perl/32610.html
热门文章
VBScript SUB 关闭画面
https://jb123.cn/vbscript/16838.html
VBScript 中的 OpenDocument 函数:打开和处理文档
https://jb123.cn/vbscript/20453.html
[vbscript空格]:深入探讨在 VBScript 中移除字符串中的空格
https://jb123.cn/vbscript/1028.html
VBScript 基础:全面指南
https://jb123.cn/vbscript/924.html
IE 中的 VBScript:过时但仍然有用
https://jb123.cn/vbscript/335.html