VB中For Each...Next的运用实例,,,希望大虾们分享一下

解决方案 »

  1.   

    Option ExplicitPrivate Sub Form_Load()
        Dim ctl1 As Control
        For Each ctl1 In Me.Controls
            Debug.Print ctl1.Name
        Next ctl1End Sub
      

  2.   

    Option ExplicitPrivate Sub Form_Load()
        Dim ctl1 As Control
        For Each ctl1 In Me.Controls
            Debug.Print ctl1.Name
        Next ctl1End Sub
    就这样,很标准的
      

  3.   

    MSDN就有现成的实例:
    For Each...Next 语句示例
    本示例使用 For Each...Next 语句搜寻集合中的所有成员的 Text 属性,查找“Hello”字符串。示例中,MyObject 是面向文本的对象,并且是 MyCollection 集合的成员,这两个名字只是为示范目的而使用的通用名称而已。Dim Found, MyObject, MyCollection
    Found = False   ' 设置变量初始值。
    For Each MyObject In MyCollection   ' 对每个成员作一次迭代。
       If MyObject.Text = "Hello" Then   ' 如果 Text 属性值等于“Hello”。
          Found = True   ' 将变量 Found 的值设成 True。
          Exit For   ' 退出循环。
       End If
    Next