标题:For each Next 循环问题
只看楼主
Mountisky
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-7-17
结帖率:100%
 问题点数:0 回复次数:3 
For each Next 循环问题
程序代码:
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim ctl1 As Control
        Dim i As Integer = 4
        Dim a(i) As String
        For Each ctl1 In Me.Controls
            If Mid(ctl1.Name, 1, 2) = "Bu" Then
                For i = 1 To 4
                    a(i) = ctl1.Name
                    ' i = i + 1
                    TextBox1.Text = TextBox1.Text & vbCrLf & "a" & i & "=" & a(i)
                Next
            End If
        Next ctl1
    End Sub


我希望输出的结果是
a1=button1,
a2=button2,
a3=button3…
实际的输出结果是这个样子的,我不知道到底哪里出了问题,
我希望遍历集合,把符合条件的,一个一个的输出到一个数组里面,

搜索更多相关主题的帖子: For Next 循环 Dim 输出 
2017-10-22 14:07
xyxcc177
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:26
帖 子:197
专家分:1249
注 册:2017-7-8
得分:0 
在net中,最后添加上去的控件的index的值是0
2017-10-22 19:37
wmf2014
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:216
帖 子:2039
专家分:11273
注 册:2014-12-6
得分:0 
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim ctl1 As Control
        Dim i As Integer = 4
        Dim a(i) As String
        i=1
        For Each ctl1 In Me.Controls
            If Mid(ctl1.Name, 1, 2) = "Bu" Then
               if i<5 then
                    a(i) = ctl1.Name
                    TextBox1.Text = TextBox1.Text & vbCrLf & "a" & i & "=" & a(i)
                    i = i + 1
                end if
            End If
        Next ctl1
    End Sub

能编个毛线衣吗?
2017-10-23 11:41
紫金山
Rank: 1
等 级:新手上路
帖 子:6
专家分:7
注 册:2017-6-20
得分:0 
回复 3楼 wmf2014
谢谢,万谢,问题基本解决,我研究了下,好像是遍历先把最后一个找出来进行赋值。顺序刚好是反的。
2017-10-26 09:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-481654-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.090316 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved