473,775 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

create/use form event/property to validate txtEntry

Hello,

I have 10 textboxes on a form. I would like to validate
text-data entry on each textbox. I was looking for a
Form_Current event or Form_Change event but did not
recognize any such events. Or maybe there is a property
for the Textboxes where I can set data entry conditions?
Wondering about CausesValidatio n textbox property-how to
use.

I was thinking maybe I could create a custom form event
that would loop through an array of textboxes when the
event is raise and would check the content of each textbox
like as soon as the textbox loses focus. Is there such a
form event? Do I need to create one? How to create this
event and raise the event?

Thanks,
Rich
Nov 20 '05 #1
7 1382
Cor
Hi Rich,

Did I not send you an example with that in it?

Set the handler for the lostfocus event?
Using an array of controls?

Cor
Nov 20 '05 #2
Yes you did. Thank you. Now I see an application for
this. I don't have dotnet loaded at the workplace (yet)
just at home. So have to wait to try the following, but
would something like this work?

Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim txtboxarea As TextBox() = New TextBox() {txt0,txt1,
txt2,txt3,...tx t10}
dim txt as TextBox
For Each txt In txtboxarea
AddHandler txt.LostFocus, AddressOf TextBox_LostFoc us
Next
End Sub

Private Sub TextBox_LostFoc us(ByVal sender As Object, _
ByVal e As System.EventArg s)
DirectCast(send er, TextBox).Text = _
Trim(DirectCast (sender, TextBox).Text)
If sender.Name = "txt0" Then
If sender.Text < 1990 Or sender.Text > 2010 Then
sender.Text = ""
Beep()
MsgBox "Out of bounds!"
Else
If sender.Text > 1000 Then
sender.Text = ""
Beep()
MsgBox "Out of Bounds!"
End If
End Sub

---what's best way to invoke TextBox_LostFoc us? Can I
call the same TextBox_LostFoc us for each textbox or do I
have to make one for each textbox? Do I need to cast
sender.Text or do I need to change that to

DirectCast(send er, TextBox).Text < 1990 ...

Thank you always for your help,
Rich

-----Original Message-----
Hi Rich,

Did I not send you an example with that in it?

Set the handler for the lostfocus event?
Using an array of controls?

Cor
.

Nov 20 '05 #3
Cor
Hi Rich,

When you do that directcast around all "sender" than I think something as
that yes.
You also can look at the "leave" event and the oposite from that "enter"

Cor
Yes you did. Thank you. Now I see an application for
this. I don't have dotnet loaded at the workplace (yet)
just at home. So have to wait to try the following, but
would something like this work?

Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim txtboxarea As TextBox() = New TextBox() {txt0,txt1,
txt2,txt3,...tx t10}
dim txt as TextBox
For Each txt In txtboxarea
AddHandler txt.LostFocus, AddressOf TextBox_LostFoc us
Next
End Sub

Private Sub TextBox_LostFoc us(ByVal sender As Object, _
ByVal e As System.EventArg s)
DirectCast(send er, TextBox).Text = _
Trim(DirectCast (sender, TextBox).Text)
If sender.Name = "txt0" Then
If sender.Text < 1990 Or sender.Text > 2010 Then
sender.Text = ""
Beep()
MsgBox "Out of bounds!"
Else
If sender.Text > 1000 Then
sender.Text = ""
Beep()
MsgBox "Out of Bounds!"
End If
End Sub

---what's best way to invoke TextBox_LostFoc us? Can I
call the same TextBox_LostFoc us for each textbox or do I
have to make one for each textbox? Do I need to cast
sender.Text or do I need to change that to

DirectCast(send er, TextBox).Text < 1990 ...

Thank you always for your help,
Rich

Nov 20 '05 #4
If I understand correctly then:

Private Sub TextBox_LostFoc us(ByVal sender As Object, _
ByVal e As System.EventArg s)
DirectCast(send er, TextBox).Text = _
Trim(DirectCast (sender, TextBox).Text)
If (DirectCast(sen der, TextBox).Name = "txt0" Then
If DirectCast(send er, TextBox).Text < 1990 Or DirectCast
(sender, TextBox).Text > 2010 Then
DirectCast(send er, TextBox).Text = ""
Beep()
MsgBox "Out of bounds!"
Else
If DirectCast(send er, TextBox).Text > 1000 Then
DirectCast(send er, TextBox).Text = ""
Beep()
MsgBox "Out of Bounds!"
End If
End Sub

And I believe the opposite of "Enter" for VB would
be "Exit". So you suggest I could look at the "Leave"
or "Exit" events in the help files? I will have a look.

Many thanks for your suggestions.
Rich
-----Original Message-----
Hi Rich,

When you do that directcast around all "sender" than I think something asthat yes.
You also can look at the "leave" event and the oposite from that "enter"
Cor
Yes you did. Thank you. Now I see an application for
this. I don't have dotnet loaded at the workplace (yet)
just at home. So have to wait to try the following, but
would something like this work?

Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim txtboxarea As TextBox() = New TextBox() {txt0,txt1,
txt2,txt3,...tx t10}
dim txt as TextBox
For Each txt In txtboxarea
AddHandler txt.LostFocus, AddressOf TextBox_LostFoc us
Next
End Sub

Private Sub TextBox_LostFoc us(ByVal sender As Object, _
ByVal e As System.EventArg s)
DirectCast(send er, TextBox).Text = _
Trim(DirectCast (sender, TextBox).Text)
If sender.Name = "txt0" Then
If sender.Text < 1990 Or sender.Text > 2010 Then
sender.Text = ""
Beep()
MsgBox "Out of bounds!"
Else
If sender.Text > 1000 Then
sender.Text = ""
Beep()
MsgBox "Out of Bounds!"
End If
End Sub

---what's best way to invoke TextBox_LostFoc us? Can I
call the same TextBox_LostFoc us for each textbox or do I
have to make one for each textbox? Do I need to cast
sender.Text or do I need to change that to

DirectCast(send er, TextBox).Text < 1990 ...

Thank you always for your help,
Rich


Nov 20 '05 #5
* "Rich" <an*******@disc ussions.microso ft.com> scripsit:
I have 10 textboxes on a form. I would like to validate
text-data entry on each textbox. I was looking for a
Form_Current event or Form_Change event but did not
recognize any such events. Or maybe there is a property
for the Textboxes where I can set data entry conditions?
Wondering about CausesValidatio n textbox property-how to
use.
Setting 'CausesValidati on' to 'True' will prevent raising the
'Validating' event for other controls.
I was thinking maybe I could create a custom form event
that would loop through an array of textboxes when the
event is raise and would check the content of each textbox
like as soon as the textbox loses focus. Is there such a
form event? Do I need to create one? How to create this
event and raise the event?


You can store some data in the textboxs' 'Tag' property.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
Thank you for this explanation. So if I set
CausesValidatio n to False, how do I raise the validate
Event for other controls?

Thanks,
Rich
-----Original Message-----
* "Rich" <an*******@disc ussions.microso ft.com> scripsit:
I have 10 textboxes on a form. I would like to validate text-data entry on each textbox. I was looking for a
Form_Current event or Form_Change event but did not
recognize any such events. Or maybe there is a property for the Textboxes where I can set data entry conditions? Wondering about CausesValidatio n textbox property-how to use.
Setting 'CausesValidati on' to 'True' will prevent raising

the'Validating' event for other controls.
I was thinking maybe I could create a custom form event
that would loop through an array of textboxes when the
event is raise and would check the content of each textbox like as soon as the textbox loses focus. Is there such a form event? Do I need to create one? How to create this event and raise the event?


You can store some data in the textboxs' 'Tag' property.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
.

Nov 20 '05 #7
Just reporting back that I used Cor's TextBox_LostFoc us
Event handler and it worked perfectly! Thanks.

Thank you all for your help.

Rich
-----Original Message-----
Hello,

I have 10 textboxes on a form. I would like to validate
text-data entry on each textbox. I was looking for a
Form_Current event or Form_Change event but did not
recognize any such events. Or maybe there is a property
for the Textboxes where I can set data entry conditions?
Wondering about CausesValidatio n textbox property-how to
use.

I was thinking maybe I could create a custom form event
that would loop through an array of textboxes when the
event is raise and would check the content of each textboxlike as soon as the textbox loses focus. Is there such a
form event? Do I need to create one? How to create this
event and raise the event?

Thanks,
Rich
.

Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3106
by: CJM | last post by:
Can somebody clarify if/how/when a simple form is submitted when the <Enter> key is pressed? As I understood it, if you have a form with a single submit button, if enter is pressed, the form should be submitted as if the button is pressed. Is this correct? Does this behaviour vary across browsers? Chris
4
2652
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a script that validates the form fields. the validation procedure is called ONCLICK event of the submit button. Follwowing is the structure of the validation procedure.
2
1660
by: lmeng | last post by:
Hi, I am new to this Forum. Thanks in advance for any kind help. In the following HTML code, when I change the value of one text field then click "Modify" button, if the validation fails a message will popup and the cotent of the form should NOT be submitted. (The actual code connects to the database at the backend so I can check if the value is submmited).
8
1345
by: Arthur Rusdell-Wilson | last post by:
I find that in a large form (especially if there is a table within the form?) that the form is submitted to my server-side script even when a JavaScript 'onsubmit' event handler returns 'false'. does any one else have this problem, and is there a work-round? -- Arthur Rusdell-Wilson
7
8869
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
6
2154
by: stellstarin | last post by:
I have a HTML page containing two submit buttons in the same form.When the form is submitted,I want to know through which submit button the form was submitted. Is there any event or property which identifies this?
5
1930
by: kevinmajor1 | last post by:
Hello, all. I'm currently trying to write a script that will perform form validation upon submission. I know that more validation should be performed on the server's side...this is just a test to see if I can get the client side to work. My problem is that I'm trying to make a validator that is 100% separated from the XHTML code. I don't even want an event handler assignment in the form. Unfortunately, I can't see how to grab a hold...
11
3001
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
9
2813
by: AMBLY | last post by:
Hello ! Hope someone might be able to help me with this one. I run Access2000 on XP. I have a form : frmONE- which contains a txt field: ctrCTN from my table/database. The values in ctrCTN are unique. Next to this field is a cmdFIND button frmONE is open and the active window. I want to search for values in ctrCTN, and go to the record which contains that value. I do not want to use a cmdButton with in-built Access Find procedure to...
0
9622
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10051
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6718
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.