Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb6 Visual basic多句柄事件_Vb6_Visual Studio 2013 - Fatal编程技术网

Vb6 Visual basic多句柄事件

Vb6 Visual basic多句柄事件,vb6,visual-studio-2013,Vb6,Visual Studio 2013,我有一个问题,如何为我的代码创建多个句柄。我找到了一些示例,但仍然不知道如何与我的代码结合。(我完全是初学者,所以任何帮助或建议都会非常有用) 以下是我想要创建的内容: Private Sub t_VDOSC_LostFocus(sender As Object, e As EventArgs) Handles t_VDOSC.LostFocus, t_VDOCC.LostFocus, t_VSOCC.LostFocus, t_VSOSC.LostFocus Dim not_o

我有一个问题,如何为我的代码创建多个句柄。我找到了一些示例,但仍然不知道如何与我的代码结合。(我完全是初学者,所以任何帮助或建议都会非常有用)

以下是我想要创建的内容:

Private Sub t_VDOSC_LostFocus(sender As Object, e As EventArgs) Handles t_VDOSC.LostFocus, t_VDOCC.LostFocus, t_VSOCC.LostFocus, t_VSOSC.LostFocus

        Dim not_ok As Boolean = False
        If IsNumeric(t_VDOSC.Text) = True Then
            If (CDbl(t_VDOSC.Text) >= 0 And CDbl(t_VDOSC.Text) <= 2.0) Or CDbl(t_VDOSC.Text) = 99999 Then

            Else
                not_ok = True
            End If
        Else
            not_ok = True
        End If

        If not_ok = True Then
            MsgBox("Values must be between 0 and 2!")
            t_VDOSC.Focus()
        End If
        text_default(sender)
    End Sub
text\u-akactive
text\u默认值为颜色设置

我在VB6中找到了一个例子,非常简单的代码,它有索引,我不喜欢在我的代码中有索引

IF Index = 1 Or Index = 2, or Index = 6, or Index = 7 Then
If Text3(Index) >=0 And Text3(Index) <=4 Then
如果索引=1或索引=2,或索引=6或索引=7,则
如果Text3(Index)>=0且Text3(Index)(1),则可以在一个处理程序中处理多个事件,如前所述。但问题是,您只使用了第一个文本框
t\u VDOSC
,因此,第二、第三和第四个文本框似乎不起作用。您应该使用
sender
而不是第一个文本框
t_VDOSC

(2)并且您正在
LostFocus
事件中检查验证;如果该值无效,则显示
消息框
,并将焦点设置回原位。这就是问题所在

比如-文本框A失去焦点,然后文本框B获得焦点; 在文本框A
LostFocus
事件中检查验证,然后将焦点设置回文本框A;它将再次触发文本框B
LostFocus
事件,然后您再次将焦点设置回文本框B;(它将创建一个无限循环)。 为了避免无限循环,可以使用
验证
事件

(3)解决方案是。。。让
LostFocus
事件处理程序如下

Private Sub t_VDOSC_LostFocus(sender As Object, e As EventArgs) Handles _ 
    t_VDOSC.LostFocus, t_VDOCC.LostFocus, t_VSOCC.LostFocus, t_VSOSC.LostFocus

    text_default(sender)
End Sub
(4)检查
验证事件中的数据验证过程,如下所示

Private Sub t_VDOSC_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles t_VDOSC.Validating, t_VDOCC.Validating, t_VSOCC.Validating, t_VSOSC.Validating
    Dim t_sender As TextBox
    t_sender = CType(sender, TextBox)
    Dim not_ok As Boolean = False
    If IsNumeric(t_sender.Text) = True Then
        If (CDbl(t_sender.Text) >= 0 And CDbl(t_sender.Text) <= 2.0) Or CDbl(t_sender.Text) = 99999 Then

        Else
            not_ok = True
        End If
    Else
        not_ok = True
    End If

    If not_ok = True Then
                           'You don't need to call t_sender.Focus() here
        e.Cancel = True    'This will prevent losing focus with invalid data
        MsgBox("Values must be between 0 and 2!")
    End If
    text_default(t_sender)
End Sub
Private Sub t_VDOSC_验证(ByVal sender作为对象,ByVal e作为System.ComponentModel.CancelEventArgs)_
处理t_VDOSC.Validating、t_VDOCC.Validating、t_VSOCC.Validating、t_VSOSC.Validating
将发送器设置为文本框
t_sender=CType(发送者,文本框)
Dim not_ok作为布尔值=False
如果IsNumeric(t_sender.Text)=True,则

如果(CDbl(t_sender.Text)>=0和CDbl(t_sender.Text)谢谢。这很好。我还有一个问题。在两个不同的选项卡中(我有
TabControl1
->
TabPage1
TabPage2
)可以有两个同名的
文本框,或者我必须以不同的方式重命名它(我现在就是这样做的;我已经更改了tab2中的
文本框的名称,如
t\u VDOSC
)。不,您不能在
VB.NET
中为不同的对象设置相同的名称,但您可以在
vb6
中进行设置
Private Sub t_VDOSC_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles t_VDOSC.Validating, t_VDOCC.Validating, t_VSOCC.Validating, t_VSOSC.Validating
    Dim t_sender As TextBox
    t_sender = CType(sender, TextBox)
    Dim not_ok As Boolean = False
    If IsNumeric(t_sender.Text) = True Then
        If (CDbl(t_sender.Text) >= 0 And CDbl(t_sender.Text) <= 2.0) Or CDbl(t_sender.Text) = 99999 Then

        Else
            not_ok = True
        End If
    Else
        not_ok = True
    End If

    If not_ok = True Then
                           'You don't need to call t_sender.Focus() here
        e.Cancel = True    'This will prevent losing focus with invalid data
        MsgBox("Values must be between 0 and 2!")
    End If
    text_default(t_sender)
End Sub