以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  判断窗口下的所有控件的.Value都不为空  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=154119)

--  作者:lovepisss
--  发布时间:2020/9/4 1:15:00
--  判断窗口下的所有控件的.Value都不为空
请问如何简单的判断窗口下的所有控件的.Value都不为空?
我的做法:
With Forms("t_x_新增购置计划")
    If .Controls("TextBox序号").Value Is Nothing OrElse .Controls("NumericComboBox购置计划").Value Is Nothing OrElse .Controls("TextBox记录人").Value Is Nothing OrElse .Controls("DateTimePicker记录时间").Value Is Nothing Then
...
End With

--  作者:有点蓝
--  发布时间:2020/9/4 9:40:00
--  
窗口:http://www.foxtable.com/webhelp/topics/1849.htm
--  作者:WELOVEFOX
--  发布时间:2020/9/4 9:48:00
--  
For Each c As WinForm.Control In e.Form.Controls
    If Typeof c Is WinForm.TextBox Then \'判断控件是否是文本框
        Dim t As WinForm.TextBox = c \'使用特定类型的变量引用控件
If        t.Value = Nothing Then
MessageBox.Show("文本控件不能为空!")
t.Select()
Return
End If
    End If
Next


For Each c As WinForm.Control In e.Form.Controls
    If Typeof c Is WinForm.ComboBox Then \'判断控件是否是文本框
        Dim t As WinForm.ComboBox = c \'使用特定类型的变量引用控件
If        t.Value = Nothing Then
MessageBox.Show("组合框不能为空!")
t.Select()
Return
End If
    End If
Next

For Each c As WinForm.Control In e.Form.Controls
    If Typeof c Is WinForm.DateTimePicker Then \'判断控件是否是文本框
        Dim t As WinForm.DateTimePicker = c \'使用特定类型的变量引用控件
If        t.Value = Nothing Then
MessageBox.Show("日期框不能为空!")
t.Select()
Return
End If
    End If
Next
[此贴子已经被作者于2020/9/4 9:48:38编辑过]

--  作者:有点蓝
--  发布时间:2020/9/4 10:10:00
--  
合并为一段代码即可

For Each c As object  In e.Form.Controls
    If Typeof c Is WinForm.TextBox OrElse Typeof c Is WinForm.ComboBox OrElse Typeof c Is WinForm.DateTimePicker  Then \'判断控件是否是文本框
        If c.Value = Nothing Then
            MessageBox.Show(c.name & "控件不能为空!")
            c.Select()
            Return
        End If
    End If
Next

--  作者:lovepisss
--  发布时间:2020/9/4 12:14:00
--  回复:(有点蓝)窗口:http://www.foxtable.com/webh...
谢谢蓝大!
--  作者:lovepisss
--  发布时间:2020/9/4 12:14:00
--  回复:(WELOVEFOX)For Each c As WinForm.Control I...
谢谢大佬
--  作者:lovepisss
--  发布时间:2020/9/4 12:39:00
--  回复:(有点蓝)窗口:http://www.foxtable.com/webh...
蓝大,我看了帮助页,里面提到
如果我希望清除窗口中所有文本框的内容,…,但是遍历控件的时候,只能使用WinForm.Control类型的变量,
教学代码如下
For Each c As WinForm.Control In e.Form.Controls
    If
 Typeof c Is WinForm.TextBox Then \'判断控件是否是文本框
        
Dim t As WinForm.TextBox = c \'使用特定类型的变量引用控件
        t.Value = 
Nothing
    End
 If
Next

请问为什么不可以写成
For Each c As WinForm.TextBox In e.Form.Controls

--  作者:有点蓝
--  发布时间:2020/9/4 13:36:00
--  
因为有些控件可能不是WinForm.TextBox