I think the idea is that formatting is a "function of display" not a
"function of value storage".

You can use hook up common Format & Parse event handlers to your bindings on
a per-datatype basis so you get common display styles for each datatype.




-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Greg Rothlander
Sent: Sunday, August 10, 2008 12:02 AM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: [ADVANCED-DOTNET] Can you extend the datatypes in VB.Net

The data types in .Net do not have a format string with them.  Is it
possible to extend the data types to add a format string?  I thought I came
across an example of this back a few years ago, but I do not recall.  It may
have been an example of how to create your own types.

Can anyone think of a way to extend the data types?  For example, let's say
that I want an Integer with a length of 5 and a format string of "00000".
Is there a way to do that?  The same might do for a date.  I might want to
set the format to "MMDDYYYY", but I would like to carry that within the data
type.

Why?  Because I have to set the format string on thousands of lines through
the program.  If I was able to store it on the data type itself, I wouldn't
have to do this.  If I could extend the data type I might be able to do
something like:

Dim X as Integer = 123
x.FormatString = "00000"
Dim str as string = X.ToString()

str would equal "00123"

I'm just tired of adding the format to EVERY line of code that needs the
length formatted to a 5 digits.  What I have to do now is for every line of
code were X is used, I have to do something like:

        whateverstring = Format(X, "00000")

I would rather just do something like:

        whateverstring = X.ToString() or maybe just whateverstring = X

It seems like there would be some way to do this.  It is very common in
other languages to have the format on the data type.  Dates a very common
thing to run into like this.  It would be nice to have the format of the
date already set by default.

It would also be nice to have an integer with a length that doesn't change.
For example, lets say that I pull something from a database with a field
length of 5 and it has a value of 123.  If I ask it the length, it will say
3.  But I need to know that the real length is 5.  Why?  Because the program
wants to store 00123 in the db column and not 123.  The 00 is important for
the application.

Any thoughts?  Am I missing something simple here and trying to work around
something that should not be worked around?  I do have some limitations
because the db needs the 00123 stored and with really mess up some of the
other programs that use the DB if I did store 123 in that field.  Why?
Other applications written in other languages also use the DB and the DB is
not SQL Server.

Any thoughts would be appreciated.

Best regards,
Jon

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

No virus found in this incoming message.
Checked by AVG.
Version: 7.5.524 / Virus Database: 270.6.0/1601 - Release Date: 8/8/2008
9:02 AM


No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.524 / Virus Database: 270.6.0/1601 - Release Date: 8/8/2008
9:02 AM

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to