有没有办法同时求出几个变量的长度?

Is there a way to find the length of several variables at the same time?

我试图在按下按钮时检测空文本框。为此,我对每个变量使用 if 语句,如下所示:

If Len(variable.Text) = 0 Then 
   Messagebox.Show("please fill in all fields.")
End If 

有没有更有效的方法可以检测所有文本框中的字符串长度是否同时为零?或者,如果有人想提出一种更好的方法,我们也将不胜感激。谢谢。

这就是要走的路。 (:

如果你想检查是否所有的文本框都是空的(或者换句话说:是否可以让一些文本框为空)你可以使用这样的东西:

'if some textboxes can be empty
IF a="" AND b="" AND c="" Then Messagebox.Show("please fill in all fields.")

'if no textbox can be empty
IF a="" OR b="" OR c="" Then Messagebox.Show("please fill in all fields.")

假设文本框的格式与验证按钮的格式相同,就可以了

Dim ctrl As Control
For Each ctrl In Me.Controls ' panelname.controls etc
    If (ctrl.GetType() Is GetType(TextBox)) Then
        If Trim(ctrl.Text) = "" Then
            MessageBox.Show("please fill in all fields.")
            Exit Sub
        End If
    End If
Next

Dim ctrl As Control
Dim count As Integer
count = 0
For Each ctrl In Me.Controls ' panelname.controls etc
    If (ctrl.GetType() Is GetType(TextBox)) Then
        If Trim(ctrl.Text) = "" Then count += 1
        'you can add exceptions by textbox name also by getting ctrl.Name
    End If
Next
If count > 0 Then
    MessageBox.Show("please fill in all fields.")
End If