473,396 Members | 1,816 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,396 software developers and data experts.

How can i design this approach ?

I created my own usercontrol of textbox and my base from . Every windows
will inhertied this mybaseform and every textbox will use that usercontrol.
Now, mybaseform got a function "public overridables function
fieldvalidation(byval _fieldname as string) as boolean"
in my usercontrol's validated event, I want to pass the textbox's name to
that function.
Can I do that ??
my aim ; in each windows form e.g frmInvoice, with a textbox,
txtInvNo,txtCompanyCode.
I want to use a "simple" and global way to pass the 'txtInvNo' to the
fieldvalidation()

public ..... function fieldvalidation(byval _field as string) as boolean
if _field = "txtInvNo" or _field = "CHECKALL"then
if me.txtInvNo.text.trim.length =0 then
messagebox.show("error")
blnFlag = false
end if
if _field = "txtCompanyCode" or _field = "CHECKALL"then
if me.txtInvNo.CompanyCode.trim.length =0 then
messagebox.show("error ")
blnFlag = false
end if
.........
end func

I want to create a BIG function to do the field valiation , instead of do it
in each textbox's validated event.
Anyone understand my question ?
Thanks in advance

Nov 21 '05 #1
2 1341
NM
Hi,

In your own usercontrol of textbox, create this new event :

Public Event fieldValidation(ByVal _field as string)
Then define a method that'll raise that event :

Private Sub mytextbox_Validated(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Validated

Raise Event fieldValidation(Me.name)

End Sub

Then in your form define the fieldValidation procedure that handles
fieldValidation event of all textbox :

public sub fieldvalidation(byval _field as string) Handles
txtInvNo.fieldValidation, txtCompanyCode.fieldValidation
if _field = "txtInvNo" or _field = "CHECKALL"then
if me.txtInvNo.text.trim.length =0 then
messagebox.show("error")
blnFlag = false
end if
if _field = "txtCompanyCode" or _field = "CHECKALL"then
if me.txtInvNo.CompanyCode.trim.length =0 then
messagebox.show("error ")
blnFlag = false
end if
........ end sub
I notice that you are doing the same test for all your textbox; so in my
opinion, inplement your test in your usercontrol of textbox :

Private Sub mytextbox_Validated(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Validated
if me.text.trim.length = 0 then
messagebox.show("error")
blnFlag = false
end if
End Sub

The advantages are :
- if you add or delete a textbox from your form, no need to add or remove
the if condition related;
- a small and easy "fieldvalidation" function to manipulate
Hope this help;
Regards

"Agnes" <ag***@dynamictech.com.hk> a écrit dans le message de
news:e4**************@tk2msftngp13.phx.gbl... I created my own usercontrol of textbox and my base from . Every windows
will inhertied this mybaseform and every textbox will use that usercontrol. Now, mybaseform got a function "public overridables function
fieldvalidation(byval _fieldname as string) as boolean"
in my usercontrol's validated event, I want to pass the textbox's name to
that function.
Can I do that ??
my aim ; in each windows form e.g frmInvoice, with a textbox,
txtInvNo,txtCompanyCode.
I want to use a "simple" and global way to pass the 'txtInvNo' to the
fieldvalidation()

public ..... function fieldvalidation(byval _field as string) as boolean
if _field = "txtInvNo" or _field = "CHECKALL"then
if me.txtInvNo.text.trim.length =0 then
messagebox.show("error")
blnFlag = false
end if
if _field = "txtCompanyCode" or _field = "CHECKALL"then
if me.txtInvNo.CompanyCode.trim.length =0 then
messagebox.show("error ")
blnFlag = false
end if
........
end func

I want to create a BIG function to do the field valiation , instead of do it in each textbox's validated event.
Anyone understand my question ?
Thanks in advance

Nov 21 '05 #2
Dear NM,
Your codes is so great.
BUt I wonder public sub fieldvalidation(byval _field as string) Handles
txtInvNo.fieldValidation, txtCompanyCode.fieldValidation......etc
(30fields's validatin)
Will it make the programm too slow ??
Thanks
"NM" <NM****@hotmail.com> ¦b¶l¥ó news:e4*************@TK2MSFTNGP09.phx.gbl
¤¤¼¶¼g...
Hi,

In your own usercontrol of textbox, create this new event :

Public Event fieldValidation(ByVal _field as string)
Then define a method that'll raise that event :

Private Sub mytextbox_Validated(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Validated

Raise Event fieldValidation(Me.name)

End Sub

Then in your form define the fieldValidation procedure that handles
fieldValidation event of all textbox :

public sub fieldvalidation(byval _field as string) Handles
txtInvNo.fieldValidation, txtCompanyCode.fieldValidation
if _field = "txtInvNo" or _field = "CHECKALL"then
if me.txtInvNo.text.trim.length =0 then
messagebox.show("error")
blnFlag = false
end if
if _field = "txtCompanyCode" or _field = "CHECKALL"then
if me.txtInvNo.CompanyCode.trim.length =0 then
messagebox.show("error ")
blnFlag = false
end if
........ end sub
I notice that you are doing the same test for all your textbox; so in my
opinion, inplement your test in your usercontrol of textbox :

Private Sub mytextbox_Validated(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Validated
if me.text.trim.length = 0 then
messagebox.show("error")
blnFlag = false
end if
End Sub

The advantages are :
- if you add or delete a textbox from your form, no need to add or remove
the if condition related;
- a small and easy "fieldvalidation" function to manipulate
Hope this help;
Regards

"Agnes" <ag***@dynamictech.com.hk> a écrit dans le message de
news:e4**************@tk2msftngp13.phx.gbl...
I created my own usercontrol of textbox and my base from . Every windows
will inhertied this mybaseform and every textbox will use that

usercontrol.
Now, mybaseform got a function "public overridables function
fieldvalidation(byval _fieldname as string) as boolean"
in my usercontrol's validated event, I want to pass the textbox's name to that function.
Can I do that ??
my aim ; in each windows form e.g frmInvoice, with a textbox,
txtInvNo,txtCompanyCode.
I want to use a "simple" and global way to pass the 'txtInvNo' to the
fieldvalidation()

public ..... function fieldvalidation(byval _field as string) as boolean
if _field = "txtInvNo" or _field = "CHECKALL"then
if me.txtInvNo.text.trim.length =0 then
messagebox.show("error")
blnFlag = false
end if
if _field = "txtCompanyCode" or _field = "CHECKALL"then
if me.txtInvNo.CompanyCode.trim.length =0 then
messagebox.show("error ")
blnFlag = false
end if
........
end func

I want to create a BIG function to do the field valiation , instead of

do it
in each textbox's validated event.
Anyone understand my question ?
Thanks in advance


Nov 21 '05 #3

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

Similar topics

1
by: John | last post by:
I'm developing an application for medical use that will be used to capture patient background and visit data. The application will have approximately 50 forms, with an average of about 20 fields...
3
by: Omer van Kloeten | last post by:
The Top Level Design: The class Base is a factory class with a twist. It uses the Assembly/Type classes to extract all types that inherit from it and add them to the list of types that inherit...
25
by: John Morgan | last post by:
Though I have designed and implemented a number of large reasonably well received web sites I do not consider myself a graphics designer I am now for the first time going to work with a ...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
10
by: charlie | last post by:
I posted this at Macromedia Dreamweaver newsgroup but go no response. I've been trying to learn CSS. Below is a link to a couple of designs that I managed to do using absolute position. ...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
17
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
3
by: Mousam | last post by:
Hi All, First of all forgive me for the length of this post. I am developing one library for some text editor. In this library I want to provide a set of C++ classes which will enable client (of...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
0
by: jsimone | last post by:
This question is about DB2 table design and performance. We are using DB2 UDB Enterprise 8.2 on Linux. We have 6 tables in a parent-child (one-to-many) relationship with each other. Each...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.