1 / 13

Vbscript 语法

Vbscript 语法. 循环语句:. Do...Loop While...Wend For...Next For Each In. 循环语句. 1 、 Do...Loop. 例 1. Sub ChkFirstWhile() Dim counter, myNum counter = 0 myNum = 20 Do While myNum > 10 myNum = myNum – 1

cai
Download Presentation

Vbscript 语法

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Vbscript语法 循环语句: Do...Loop While...Wend For...Next For Each In

  2. 循环语句 1、 Do...Loop 例1. Sub ChkFirstWhile() Dim counter, myNum counter = 0 myNum = 20 Do While myNum > 10 myNum = myNum – 1 counter = counter + 1 Loop MsgBox "循环重复了 " & counter & " 次。 " End Sub

  3. 循环语句 1、 Do...Loop 例2. Sub ChkLastWhile() Dim counter, myNum counter = 0 myNum = 9 Do myNum = myNum – 1 counter = counter + 1 LoopWhile myNum > 10 MsgBox "循环重复了 " & counter & " 次。 " End Sub

  4. 循环语句 1、 Do...Loop 例3. Sub ChkFirstUntil() Dim counter, myNum counter = 0 myNum = 20 DoUntil myNum = 10 myNum = myNum - 1 counter = counter + 1 Loop MsgBox "循环重复了 " & counter & " 次。" End Sub

  5. 循环语句 1、 Do...Loop 例4. Sub ChkLastUntil() Dim counter, myNum counter = 0 myNum = 1 Do myNum = myNum + 1 counter = counter + 1 LoopUntil myNum = 10 MsgBox "循环重复了 " & counter & " 次。 " End Sub

  6. 循环语句 1、 Do...Loop 例5. Sub ExitExample() Dim counter, myNum counter = 0 myNum = 9 Do Until myNum = 10 myNum = myNum – 1 counter = counter + 1 If myNum < 10 Then Exit Do end if Loop MsgBox "循环重复了 " & counter & " 次。 " End Sub

  7. 2、While...Wend 例子: <script language=vbscript> Dim Counter Counter = 0 ‘初始化变量。 While Counter < 20 ‘ 测试计数器的值。 Counter = Counter + 1 ‘ 增加计数器。 msgbox( Counter) Wend ‘ 计数器大于 19 时终止循环。 </script>

  8. 3、For...Next 语句 语法: Forcounter=startToend [Stepstep][statements][Exit For][statements]Next

  9. 3、For...Next 语句 例1: Sub DoMyProc50Times() Dim x ,y For x = 1 To 50 y=y+x Next msgbox(y) End Sub

  10. For...Next 语句 例2: Sub TwosTotal() Dim j, total Total=0 For j = 2 To 10 Step 2 total = total + j Next MsgBox "总和为 " & total & "。" End Sub 例3 Sub NewTotal() Dim myNum, total For myNum = 16 To 2 Step -2 total = total + myNum Next MsgBox "总和为 " & total & "。" End Sub

  11. For...Next 语句 例4: Sub TwosTotal() Dim j, total For j = 2 To 10 Step 2 total = total + j If j=8 then Exit for End if Next MsgBox "总和为 " & total & "。" End Sub

  12. For Each...Next 语法: For Each element In group[statements][Exit For][statements]Next [element]

  13. For Each in...Next 例题 <SCRIPT LANGUAGE = "VBScript"> Sub Addtion() Dim MyArray(100), i, AnyElement, Sum sum = 0 For i = 0 To 100 MyArray(i) = 2 * i Next For Each AnyElement In MyArray Sum = Sum + AnyElement Next MsgBox "2+4+…+200=" & Sum & "。“ End Sub </SCRIPT> Foreachin.asp

More Related