将代码放入文本框事件的最佳位置 [英] Best place to put the code in the textbox event

查看:81
本文介绍了将代码放入文本框事件的最佳位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个代码放在一个文本框中得到焦点事件。它做的是当它获得焦点时它从表中找到一个值并将其分配给文本框。但如果没有值,它会告诉用户定义它并将焦点放在另一个控件上,如果响应为是,否则告诉用户它无法继续。



我得到的是,如果没有值并且响应是肯定的,则无法将焦点放在该控件上并且只是循环消息。如果响应为是,任何想法都会打破循环。

  Dim  dr  As  OleDb.OleDbDataReader = GetData(qry)
如果 dr.HasRows = True 那么
dr.Read
TextBox32.Text = dr.Item( total
If Val(TextBox32。文字)> 800 然后
TextBox37.Text = Val(TextBox32.Text) - 800
否则
TextBox37.Text = 0
结束 如果
TextBox38.Text = Val(TextBox36.Text) + Val(TextBox37.Text)
TextBox31.Text =(Val(TextBox33.Text)+ Val(TextBox32.Text))* Val(TextBox34.Text)
循环

否则
如果 MsgBox( 未为当前月份& MonthName(currentdate.Month,错误)&放大器; vbCrLf& _
是否要定义它?,MsgBoxStyle.Question + MsgBoxStyle.YesNo , 项目工资单)= MsgBoxResult.Yes 然后
TextBox27.Focus()
其他
MsgBox( 如果没有定义燃油允许量,则无法定义容差,MsgBoxStyle.Critical, 项目工资单
退出 Sub
结束 如果
结束 < span class =code-keyword>如果

解方案
我不会用GotFocus事件可言,但是把你的代码的验证事件。检查无效数据是该事件的目的。默认情况下,将e.Cancel参数设置为True,然后一旦有了有效数据,将其设置为False,一切都将继续。


我只是将代码放入了Enter事件中文本框。

Hi guys,

I have a code placed in a textbox got focus event.what it does is when it gets a focus it finds a value from a table and assigns it to the textbox.But if ther's no value it tells the user to define it and puts the focus on another control if the response is yes otherwise telling the user it can't proceed.

What i'm getting is,if there's no value and the response is yes it can't put the focus to that control and just loops the message.Any idea to break the loop if the response is yes.

Dim dr As OleDb.OleDbDataReader = GetData(qry)
            If dr.HasRows = True Then
                Do While dr.Read
                    TextBox32.Text = dr.Item("total")
                    If Val(TextBox32.Text) > 800 Then
                        TextBox37.Text = Val(TextBox32.Text) - 800
                    Else
                        TextBox37.Text = 0
                    End If
                    TextBox38.Text = Val(TextBox36.Text) + Val(TextBox37.Text)
                    TextBox31.Text = (Val(TextBox33.Text) + Val(TextBox32.Text)) * Val(TextBox34.Text)
                Loop

            Else
                If MsgBox("Fuel allowance not defined for the current month of " & MonthName(currentdate.Month, False) & vbCrLf & _
                        "Do you want to define it?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Project Payroll") = MsgBoxResult.Yes Then
                    TextBox27.Focus()
                Else
                    MsgBox("Cannot define allowance without defining fuel allowance", MsgBoxStyle.Critical, "Project Payroll")
                    Exit Sub
                End If
            End If

解决方案

I wouldn't use the GotFocus event at all, but put your code in the Validation event. Checking for invalid data is what that event is designed to do. By default, set the e.Cancel parameter to True, then once you have valid data, set it to False and all will proceed.


I just put the code in the Enter event of the textbox.


这篇关于将代码放入文本框事件的最佳位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆