0

我无法弄清楚为什么下面的代码不起作用。第一个列表框显示除文本框之外的所有控件。当然,MsgBox 什么也没做——因为它只是在寻找文本框。为什么它不识别文本框?顺便说一句,我已经更改了一些文本框的名称,因为我有很多。如果我更改了名称,它是否无法识别它是什么类型的控件?

    Dim ctl As Control
    For Each ctl In Me.Controls
        ListBox1.Items.Add(ctl.Name)
        If TypeOf ctl Is TextBox Then
            MsgBox(ctl.Name)
            'validate that it is numeric
            If ctl.Text = "" Then
                'if not show error and exit sub
                MessageBox.Show("Please fill all blanks.")
                Exit Sub
            End If
        End If
    Next

我很感激帮助。

4

0 回答 0