我想控制text1内容如果是 "text1" ,那么就提示错误,text1重新得到焦点.
如果text2内容为空,那么提示错误,text2重新得到焦点.我的代码如下: 当text1的内容为"text1"时,就会进入死循环,请问如何解决.Private Sub Text1_LostFocus()
If Text1 = "Text1" Then
MsgBox "错误"
Text1.SetFocus
End If
End SubPrivate Sub Text2_LostFocus()
If Text2 = "" Then
MsgBox "error"
Text2.SetFocus
End If
End Sub
如果text2内容为空,那么提示错误,text2重新得到焦点.我的代码如下: 当text1的内容为"text1"时,就会进入死循环,请问如何解决.Private Sub Text1_LostFocus()
If Text1 = "Text1" Then
MsgBox "错误"
Text1.SetFocus
End If
End SubPrivate Sub Text2_LostFocus()
If Text2 = "" Then
MsgBox "error"
Text2.SetFocus
End If
End Sub
解决方案 »
- vb浏览文件夹问题
- 如何得到datagrid 每一行每一列的数据? (vb.net)
- 动态数组没有初始化及使用on error resume next的严重后果
- 关于窗体最大化
- 简单问题:如何将浮点数转换成16进制
- 急啊!MSDATGRD.OCX和MSFLXGRD.OCX控件过期问题
- 请高手帮忙:关于MSFlexGrid与Text控件配合的问题
- 怎样在vb的MSChart里改变图例的名字
- 来,送你100分!!!!!
- 谁有生成39码,或把字符转换成条码的程序,给我一份,好吗
- 紧急求助个简单的问题:VB中我记得有个函数,能够判断一个值,如果为空可以赋一个默认值
- unicode的文件写入后全成了乱码了
dim bIsErr as Boolean
bIsErr = false;Private Sub Text1_LostFocus()
If Text1 = "Text1" Then
bIsErr = true
MsgBox "错误"
end if
Text1.SetFocus
End If
End Sub然后在Text1的change事件中加bIsErr = false;
If KeyAscii = 13 Then
If UCase(Text1.Text) = UCase("Text1") Then
MsgBox "错误"
Text1.SetFocus
Else
Text2.SetFocus
End If
KeyAscii = 0
End If
End SubPrivate Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Trim(Text2.Text) = "" Then
MsgBox "错误"
Text2.SetFocus
Else
Text1.SetFocus
End If
KeyAscii = 0
End If
End Sub
If Text1 = "Text1" Then
MsgBox "错误"
text1.text="" '<----加上这句试试
Text1.SetFocus
End If
End Sub
我加了一个变量解决了问题!我是在text2的lostfocus事件中增加了一个判断来实现的.Dim IsErr As BooleanPrivate Sub Text1_LostFocus()
If Text1 = "Text1" Then
IsErr = True
MsgBox "错误"
Text1.SetFocus
Else
IsErr = False
End If
End SubPrivate Sub Text2_LostFocus()
If IsErr = False And Text2 = Empty Then
MsgBox "error"
Text2.SetFocus
End If
End Sub
If Text1.Text = "Text1" Then
MsgBox "错误"
Text1.SetFocus
End If
End Sub
Private Sub Text2_Change()
If Text2.Text = "" Then
MsgBox "error"
Text2.SetFocus
End If
End Sub
这样的话,如果在text1输入内容时,如果想输入的内容是 text111111的话,那么输到一半就会提示错误呀.
在text2输入内容时,如果输入错了.全部删除后也是提示错误的.
P这个只有在按回车键才会发生事件,如果按TAB,如果直接用鼠标操作呢?
请问怎么解决!Dim bIsErr As BooleanPrivate Sub Command1_Click()
Text3 = Text1 & Text2
End SubPrivate Sub Command2_Click()
Text1.Enabled = False
Text2.Enabled = False
Text3 = "取消"
End SubPrivate Sub Text1_GotFocus()
bIsErr = False
End SubPrivate Sub Text1_LostFocus()
If bIsErr = False And Text1 = "" Then
MsgBox "text1 不能为空"
bIsErr = True
Text1.SetFocus
End If
End SubPrivate Sub Text2_GotFocus()
bIsErr = True
End SubPrivate Sub Text2_LostFocus()
If bIsErr = False And Text2 = "" Then
MsgBox "text2 不能为空..."
bIsErr = True
Text2.SetFocus
End If
End Sub