473,395 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 CausesValidation 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 1369
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(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim txtboxarea As TextBox() = New TextBox() {txt0,txt1,
txt2,txt3,...txt10}
dim txt as TextBox
For Each txt In txtboxarea
AddHandler txt.LostFocus, AddressOf TextBox_LostFocus
Next
End Sub

Private Sub TextBox_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, 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_LostFocus? Can I
call the same TextBox_LostFocus 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(sender, 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(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim txtboxarea As TextBox() = New TextBox() {txt0,txt1,
txt2,txt3,...txt10}
dim txt as TextBox
For Each txt In txtboxarea
AddHandler txt.LostFocus, AddressOf TextBox_LostFocus
Next
End Sub

Private Sub TextBox_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, 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_LostFocus? Can I
call the same TextBox_LostFocus 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(sender, TextBox).Text < 1990 ...

Thank you always for your help,
Rich

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

Private Sub TextBox_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, TextBox).Text = _
Trim(DirectCast(sender, TextBox).Text)
If (DirectCast(sender, TextBox).Name = "txt0" Then
If DirectCast(sender, TextBox).Text < 1990 Or DirectCast
(sender, TextBox).Text > 2010 Then
DirectCast(sender, TextBox).Text = ""
Beep()
MsgBox "Out of bounds!"
Else
If DirectCast(sender, TextBox).Text > 1000 Then
DirectCast(sender, 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(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim txtboxarea As TextBox() = New TextBox() {txt0,txt1,
txt2,txt3,...txt10}
dim txt as TextBox
For Each txt In txtboxarea
AddHandler txt.LostFocus, AddressOf TextBox_LostFocus
Next
End Sub

Private Sub TextBox_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, 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_LostFocus? Can I
call the same TextBox_LostFocus 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(sender, TextBox).Text < 1990 ...

Thank you always for your help,
Rich


Nov 20 '05 #5
* "Rich" <an*******@discussions.microsoft.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 CausesValidation textbox property-how to
use.
Setting 'CausesValidation' 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
CausesValidation to False, how do I raise the validate
Event for other controls?

Thanks,
Rich
-----Original Message-----
* "Rich" <an*******@discussions.microsoft.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 CausesValidation textbox property-how to use.
Setting 'CausesValidation' 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_LostFocus
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 CausesValidation 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
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...
4
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...
2
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...
8
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'. ...
7
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...
6
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...
5
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...
11
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...
9
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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,...

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.