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

vb.net 2003 ... Global Formatting ?

the data input app im writing has some 30 + input fields and i want to be
able to format them.

I know i can use the .validate on each textbox and format the 'string'
however this require loads of repetitive codeing. Is there a way possible
to globally format the textboxes both on the .validate function, as well as
when the enter key is pressed.

Any suggestions or examples wouldbe very usefull, as i have a loads of these
data forms to create .. all requiring formatting
as a cheeky footnote before every one shouts 'Character Casing' i am using
the vbProperCase. I have this public fubction, but it strill requites a
huge amount od screen handling code.

Public Function FormatString(ByVal StringtoFormat As String, ByVal
TypeofFormat As Integer) As String
Try
Select Case TypeofFormat
Case ProperCase
FormatString = StrConv(StringtoFormat,
VbStrConv.ProperCase)
Case LowerCasing
Case UpperCasing
End Select
Catch NoFormat As Exception
MsgBox("Unable to format String. Please contatc your systems
administrator", MsgBoxStyle.Exclamation, " Formatting")
FormatString = StringtoFormat
End Try
End Function

Thank you in advance
Oct 9 '06 #1
4 2897
You can have one validate handler for all text boxes assuming that the
formatting is the same for each text box, this should work, i.e.,

Private sub handes_Validating (ByVal source as object, ByVal e as eventargs) _
handles txtbox1.validating, txtbox2.validating, ....., txtbox30.validating
Dim tx as TextBox = DirectCast(source,Textbox)
tx.text = myformatter(tx.text)
End Suib
--
Dennis in Houston
"Peter Newman" wrote:
the data input app im writing has some 30 + input fields and i want to be
able to format them.

I know i can use the .validate on each textbox and format the 'string'
however this require loads of repetitive codeing. Is there a way possible
to globally format the textboxes both on the .validate function, as well as
when the enter key is pressed.

Any suggestions or examples wouldbe very usefull, as i have a loads of these
data forms to create .. all requiring formatting
as a cheeky footnote before every one shouts 'Character Casing' i am using
the vbProperCase. I have this public fubction, but it strill requites a
huge amount od screen handling code.

Public Function FormatString(ByVal StringtoFormat As String, ByVal
TypeofFormat As Integer) As String
Try
Select Case TypeofFormat
Case ProperCase
FormatString = StrConv(StringtoFormat,
VbStrConv.ProperCase)
Case LowerCasing
Case UpperCasing
End Select
Catch NoFormat As Exception
MsgBox("Unable to format String. Please contatc your systems
administrator", MsgBoxStyle.Exclamation, " Formatting")
FormatString = StringtoFormat
End Try
End Function

Thank you in advance
Oct 9 '06 #2
Dennis wrote:
You can have one validate handler for all text boxes assuming that the
formatting is the same for each text box, this should work, i.e.,

Private sub handes_Validating (ByVal source as object, ByVal e as eventargs) _
handles txtbox1.validating, txtbox2.validating, ....., txtbox30.validating
Dim tx as TextBox = DirectCast(source,Textbox)
tx.text = myformatter(tx.text)
End Suib
--
Dennis in Houston
Technically correct, but since Peter seems to strongly dislike
repetitive labor, I'm guessing he'll dislike having to type the
"txtbox1.validating, txtbox2.validating, ....., txtbox30.validating"
part for each form. And remembering to keep it up-to-date whenever he
adds new textboxes.

Peter, the best way is probably to create your own UserControl that
Inherits System.Windows.Forms.TextBox, adds a custom property for your
TextFormat, and automatically catches the Validating event of its base
class and applies the correct formatting. And whatever other
extensions you need to make the perfect TextBox.

If you don't understand what I just said, or if that's just not an
option, here's another way which is a bit of a hack by comparison, but
will do the trick. The idea is to use the Tag property of the textbox
to select the format, and attach your own validator to every textbox on
a form that has a non-empty tag, with just one line of code per form:

1) Include this in the Load event of every Form you want to apply
special TextBox formatting to:

AddMyValidator(Me)

2) Include this in a module:

Sub AddMyValidator(ByVal frm As Object)
' Attaches our custom validator to every textbox on a form that
' has something in the Tag.
Dim tb As TextBox
For Each ctl As Object In frm.Controls
If ctl.GetType.ToString = "System.Windows.Forms.TextBox" Then
tb = DirectCast(ctl, TextBox)
If tb.Tag <"" Then AddHandler tb.Validating, AddressOf
MyValidator
End If
Next
End Sub

Sub MyValidator(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs)
' Custom textbox validator.
Dim tb As TextBox = DirectCast(sender, TextBox)
Select Case tb.Tag
Case "Lower" : tb.Text = Strings.LCase(tb.Text)
Case "Upper" : tb.Text = Strings.UCase(tb.Text)
Case "Proper" ' etc
End Select
End Sub

3) Now set the Tag of the textboxes to the format you want, which can
be done easily and to multiple textboxes at a time.

Oct 10 '06 #3
If the loop/addhandler method is used (and it's a good technique), it needs
to be in recursive form to catch any textboxes that are children of another
control on the form. Do you know of any way this can be done by hooking the
windows messages?
--
Dennis in Houston
"te******@hotmail.com" wrote:
Dennis wrote:
You can have one validate handler for all text boxes assuming that the
formatting is the same for each text box, this should work, i.e.,

Private sub handes_Validating (ByVal source as object, ByVal e as eventargs) _
handles txtbox1.validating, txtbox2.validating, ....., txtbox30.validating
Dim tx as TextBox = DirectCast(source,Textbox)
tx.text = myformatter(tx.text)
End Suib
--
Dennis in Houston

Technically correct, but since Peter seems to strongly dislike
repetitive labor, I'm guessing he'll dislike having to type the
"txtbox1.validating, txtbox2.validating, ....., txtbox30.validating"
part for each form. And remembering to keep it up-to-date whenever he
adds new textboxes.

Peter, the best way is probably to create your own UserControl that
Inherits System.Windows.Forms.TextBox, adds a custom property for your
TextFormat, and automatically catches the Validating event of its base
class and applies the correct formatting. And whatever other
extensions you need to make the perfect TextBox.

If you don't understand what I just said, or if that's just not an
option, here's another way which is a bit of a hack by comparison, but
will do the trick. The idea is to use the Tag property of the textbox
to select the format, and attach your own validator to every textbox on
a form that has a non-empty tag, with just one line of code per form:

1) Include this in the Load event of every Form you want to apply
special TextBox formatting to:

AddMyValidator(Me)

2) Include this in a module:

Sub AddMyValidator(ByVal frm As Object)
' Attaches our custom validator to every textbox on a form that
' has something in the Tag.
Dim tb As TextBox
For Each ctl As Object In frm.Controls
If ctl.GetType.ToString = "System.Windows.Forms.TextBox" Then
tb = DirectCast(ctl, TextBox)
If tb.Tag <"" Then AddHandler tb.Validating, AddressOf
MyValidator
End If
Next
End Sub

Sub MyValidator(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs)
' Custom textbox validator.
Dim tb As TextBox = DirectCast(sender, TextBox)
Select Case tb.Tag
Case "Lower" : tb.Text = Strings.LCase(tb.Text)
Case "Upper" : tb.Text = Strings.UCase(tb.Text)
Case "Proper" ' etc
End Select
End Sub

3) Now set the Tag of the textboxes to the format you want, which can
be done easily and to multiple textboxes at a time.

Oct 10 '06 #4
Dennis wrote:
If the loop/addhandler method is used (and it's a good technique), it needs
to be in recursive form to catch any textboxes that are children of another
control on the form. Do you know of any way this can be done by hooking the
windows messages?
--
Dennis in Houston
Hmm, I didn't think of that. I suppose this is a bit sloppy, but it
does work for any TextBox within a panel or any other Windows container
(not sure about UserControls):

Sub AddMyValidator(ByVal frm As Object)
' Attaches our custom validator to every textbox on a form that
' has something in the Tag.
Dim tb As TextBox
Try
For Each ctl As Object In frm.Controls
If ctl.GetType.ToString = "System.Windows.Forms.TextBox" Then
tb = DirectCast(ctl, TextBox)
If tb.Tag <"" Then AddHandler tb.Validating, AddressOf
MyValidator
Else
AddMyValidator(ctl)
End If
Next
Catch
End Try
End Sub

Oct 10 '06 #5

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

Similar topics

13
by: Larry L | last post by:
I have a Module that declares several arrays as public, some string, some integers. I then have 2 forms. Form A is the main form, that loads on start-up, and has a command button to open Form B. On...
1
by: chris mancini | last post by:
I have recently installed Visual Studio .Net 2003 and have noticed that there are problems with formatting in the HTML code page. If I format the HTML the way I want and navigate back to design...
59
by: seberino | last post by:
I've heard 2 people complain that word 'global' is confusing. Perhaps 'modulescope' or 'module' would be better? Am I the first peope to have thought of this and suggested it? Is this a...
4
by: brAccess | last post by:
I recently installed Access 2003 and immediately noticed problems with applications that work fine in 2000 and XP. I use conditional formatting on continuous forms for a number of reasons. When...
4
by: Wayne Aprato | last post by:
I have a simple database which was originally written in Access 97. When converted to Access 2000 file format it ran flawlessly in Access 2002. I've just tried to run it in Access 2003 and I am...
4
by: Dave Brydon | last post by:
Access 2003 I have a combo box in my personnel table, which draws its data from a trade code table; the original field in the code table, is numeric, Long Integer, and formatted with 5 zero's . ...
0
by: Todd Gill | last post by:
We have recently modified our ASP.NET web application to make web service calls asynchronously using the global.asax PreRequestHandler technique as explained in the following article by Matt Powell...
12
by: cmdolcet69 | last post by:
Can anyone give me some ideas on how to convert the following program to vb 2003? I would like to jsut take this code and implement it in vb. def.h /* Global Type Definitions */ typedef ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
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...

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.