VB实例编程:VB中的控件结构概述_第2页

考试站(www.examzz.com)   【考试站:中国教育考试第一门户】   2011年11月10日

  在执行 For 循环时,Visual Basic
  1. 设置 counter 等于 start。
  2. 测试 counter 是否大于 end。若是的话,则 Visual Basic 退出循环。 (若 increment 为负,则 Visual Basic 测试 counter 是否小于 end。)
  3. 执行语句。
  4. counter 增加一,或者增加 increment(如果已指定的话)。
  5. 重复步骤 2 到步骤 4。
  以下代码打印出所有有效的屏幕字体名:
  Private Sub Form_Click ()
  Dim I As Integer
  For i = 0 To Screen.FontCount
  Print Screen.Fonts (i)
  Next
  End Sub
  在 VCR 示例应用程序中,HighlightButton 过程使用 For...Next 循环,一步步经过 VCR 窗体的控件集合,并显示适当的 Shape 控件:
  Sub HighlightButton (MyControl As Variant)
  Dim i As Integer
  For i = 0 To frmVCR.Controls.Count - 1
  If TypeOf frmVCR.Controls (i) Is Shape Then
  If frmVCR.Controls (i).Name = MyControl Then
  frmVCR.Controls (i).Visible = True
  Else
  frmVCR.Controls (i).Visible = False
  End If
  End If
  Next
  End Sub
  For Each...Next
  For Each...Next 循环与 For...Next 循环类似,但它对数组或对象集合中的每一个元素重复一组语句,而不是重复语句一定的次数。如果不知道一个集合有多少元素, For Each...Next 循环非常有用。

 


首页 1 2 尾页

相关文章