注册 登录
编程论坛 VB6论坛

如何使连个text都符合要求后,再一次执行!

wxl900306 发布于 2013-03-09 11:16, 522 次点击
下面的代码我是想要在按键按下后判断text3和text4都符合要求后在开始进行发送和延时,但语句好像不对
程序代码:
Private Sub Command2_Click()            '发送序列号按键
Dim outbyte1(0) As Byte
Dim number1 As Integer
Dim x As Integer, y As Integer

Command2.Enabled = False
Command3.Enabled = False



'While x = 0
    If IsNumeric(Text3.Text) Then
        If IsNumeric(Text4.Text) Then
            If Val(Text4) < 1 Then
                'x = 0
                MsgBox "定时时间输入错误!", vbExclamation, "警告"
                Text4 = ""
                Command2.Enabled = True
            End If
        Else
            'x = 0
            MsgBox "定时时间输入错误!", vbExclamation, "警告"
            Text4 = ""
            Command2.Enabled = True
        End If
        If 0 < Val(Text3.Text) And Val(Text3.Text) < 100 Then        'text3.text是字符串,要用val转换,并且在vb中不能写成0 < Val(Text3.Text)<100要分开写
            number1 = Text3.Text
            outbyte1(0) = CByte(number1)
            MSComm1.Output = outbyte1               '发送给序列号
        Else
            'x = 0
            Text3.Text = ""
            MsgBox "请输入正确的序列号!", vbOKOnly, "警告"
        End If

    Else
        'x = 0
        Text3.Text = ""
        MsgBox "请输入正确的序列号!", vbOKOnly, "警告"
    End If
'Wend
Timer1.Enabled = True
End Sub

 
3 回复
#2
wxl9003062013-03-09 11:20
也就是说text3的要求是:在1-99的数字,text4的要求是:>0的延时时间这两个同时满足要求后才能执行发送和延时
#3
elongtown2013-03-09 11:34
搞得真复杂,你可以这么写啊:If IsNumeric(Text3.Text) and IsNumeric(Text4.Text) and Val(Text4) >= 1 Then
                               MsgBox "定时时间输入错误!", vbExclamation, "警告"
                               ......
                            else If 0 < Val(Text3.Text) And Val(Text3.Text) < 100 Then
                               ......

 其他的楼下继续
#4
Artless2013-03-10 14:23
        If 0 < Val(Text3.Text) And Val(Text3.Text) < 100 Then        'text3.text是字符串,要用val转换,并且在vb中不能写成0 < Val(Text3.Text)<100要分开写
            number1 = Text3.Text
            outbyte1(0) = CByte(number1)
            MSComm1.Output = outbyte1               '发送给序列号
Timer1.Enabled = True
        Else
            'x = 0
            Text3.Text = ""
            MsgBox "请输入正确的序列号!", vbOKOnly, "警告"
        End If

    Else
        'x = 0
        Text3.Text = ""
        MsgBox "请输入正确的序列号!", vbOKOnly, "警告"
    End If
'Wend
End Sub
1