PC Review


Reply
Thread Tools Rate Thread

How can i design this approach ?

 
 
Agnes
Guest
Posts: n/a
 
      14th Aug 2004
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





 
Reply With Quote
 
 
 
 
NM
Guest
Posts: n/a
 
      16th Aug 2004
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" <(E-Mail Removed)> a écrit dans le message de
news:e4Nq$(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Agnes
Guest
Posts: n/a
 
      18th Aug 2004
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" <(E-Mail Removed)> ¦b¶l¥ó news:(E-Mail Removed)
¤¤¼¶¼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" <(E-Mail Removed)> a écrit dans le message de
> news:e4Nq$(E-Mail Removed)...
> > 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
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Another Approach to Design =?Utf-8?B?YW5kcmVhaW5wYW5hbWE=?= Microsoft Access Database Table Design 2 31st Jul 2006 08:26 AM
Best Design approach Jason Mauss Microsoft ASP .NET 0 24th Mar 2005 07:48 AM
How can I design this approach ? Agnes Microsoft VB .NET 4 11th Aug 2004 08:52 AM
.Net CF Design Approach Rohit Kaushal Microsoft Dot NET Compact Framework 6 30th Oct 2003 04:38 AM
Design approach for .Net CF Rohit Kaushal Microsoft Dot NET Framework Forms 1 30th Oct 2003 04:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:53 PM.