如何判断text内的内容为空?
有text1,text2,text3,text4,text5....text16。应该有两种方法判断,一种是一个一个列举,if text1.text="" and text2.text="" ..then关于这种方法,我要问的是换行时应改怎么写代码。第二种方法是有数组循环判断,呵呵,但是我不会写代码,有没有高人讲解一些这两种方法?
2008-11-27 13:18
2008-11-27 13:48
2008-11-27 13:49
2008-11-27 13:55
程序代码:
Private Sub Command1_Click()
Dim i As Long
Dim j As String
Dim o As Long
Dim yn As Boolean
For i = 0 To Me.Controls.Count - 1 'me 代表当前窗口
If InStr(1, Me.Controls(i).Name, "Text") > 0 Then '此处是你的text 控件的前缀,判断是否含 前缀
j = Mid(Me.Controls(i).Name, 5) '取除去前缀的部分
If IsNumeric(j) Then '是否是数字
o = CLng(j)
If o >= 1 And o <= 16 Then '此处是你的 text 的最大编号及最小编号
If Me.Controls(i).Text = "" Then '判断是否为空,这里还少写了一个判断,就是判断控件类型的,你要自己加就在最上面一层加上去
yn = True
Exit For
End If
End If
End If
End If
Next i
If yn Then
MsgBox Me.Controls(i).Name & " 内容为空!", vbCritical
Else
MsgBox "Text1 到 Text16 的内容均不为空!", vbInformation
End If
End Sub

2008-11-27 16:59
程序代码:
Private Sub Command2_Click()
'空一格,一个下划线,表示下一行将继续本行
If Text1.Text = "" _
Or Text2.Text = "" _
Or Text3.Text = "" _
Or Text4.Text = "" _
Or Text5.Text = "" _
Or Text6.Text = "" _
Or Text7.Text = "" _
Or Text8.Text = "" _
Or Text9.Text = "" _
Or Text10.Text = "" _
Or Text11.Text = "" _
Or Text12.Text = "" _
Or Text13.Text = "" _
Or Text14.Text = "" _
Or Text15.Text = "" _
Or Text16.Text = "" _
Then
MsgBox "有个text 内容为空", vbCritical
Else
MsgBox "Text1 到 Text16 的内容均不为空!", vbInformation
End If
End Sub

2008-11-27 17:03
2008-11-27 17:28
2008-11-27 21:04
2008-11-28 08:01

2008-11-28 09:28