如果你是要判断窗体中几个特定的文本框的话,建议使用控件数组; 如果你是要判断窗体中所有的文本框的话,建议使用如下方法: Private Sub Command1_Click() Dim ctl As Control Dim blnChoice As Boolean Dim strContent As String blnChoice = True ' 用以判断文本控件中的内容是否相同 strContent = "" ' 用以保存文本控件中的内容 For Each ctl In Me If TypeOf ctl Is TextBox Then If strContent = "" Then strContent = ctl.Text Else If strContent <> ctl.Text Then blnChoice = False ' 不同则退出循环 Exit For End If End If End If Next ctl MsgBox IIf(blnChoice, "相同", "不同") End Sub
如果你是要判断窗体中所有的文本框的话,建议使用如下方法:
Private Sub Command1_Click()
Dim ctl As Control
Dim blnChoice As Boolean
Dim strContent As String
blnChoice = True ' 用以判断文本控件中的内容是否相同
strContent = "" ' 用以保存文本控件中的内容
For Each ctl In Me
If TypeOf ctl Is TextBox Then
If strContent = "" Then
strContent = ctl.Text
Else
If strContent <> ctl.Text Then
blnChoice = False ' 不同则退出循环
Exit For
End If
End If
End If
Next ctl
MsgBox IIf(blnChoice, "相同", "不同")
End Sub