The problem is that basic evaluations and move of data from variable to
variable also uses the formatting.

For example, lets say that I had a date and a numeric.  The date has a
length of 8 and the numeric has a length of 4.  You can do something like

        Num = 0001              Length=4
        Date= 20080813  Length=8
        Num = date

Now the legacy system understands all of the formatting stuff, so Num would
contain only 2008.  Why? The system would take a look at the lengths of each
and do something like

        Num = CInt(mid(date.Format("00000000"), 1, num.length))

Now num contains 2008.  But lets say that it contained only something like
0008.  When you look at num, it would display 0008 as its value in the
legacy system.  That's not a big deal in .Net and .Net can show 8 as the
value.  That's ok because when you pull the value out to display, you would
apply its format.  Something like the following would work for that.

        Textbox.Text = num.Format("0000")

So you are half correct in what you are saying, but unfortunately every time
a variable is used in the legacy code, the formatting comes into play.

So my code currently takes something like

        num = date

and returns

        Num = CInt(mid(date.Format("00000000"), 1, num.length))

        I can covert it to use a function such as...

        Num = FunctionCall(date, "00000000", num, "0000")
        or
        Num = FunctionCall(date, 8, num, 4)  'Just pass in the length and
construct the format string to make the call look better.

Which one of these would you rather maintain?  That's sort of the issue
here.  I'm trying to separate the complexity of all of this into a function,
extension, or something else.  Then my code would like more like this, which
is MUCH better in my mind.

        Num = date.Format
        Or
        Num = FunctionCall(date)
        Or
        Num = date   'If I can figure out how to extend the datatypes.

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Ryan Heath
Sent: Wednesday, August 13, 2008 1:26 AM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] Can you extend the datatypes in VB.Net

>>Do you use the formating also when displaying the values in the UI?
Yes.

>>If not, is it possible to defer the formating right before writing the
*value* to the db?
At that point it is known (is it?) to which db field you are going to write
to.

Currently it seems you are coupling the format information to a variable.
But it think it should be coupled to a db field (constructure).

Somewhere you store/define the db field info.

Table.Field.Type.Length

Then right before the actual insert/update into db should occur,
format the incoming values according to db field information.
This should/can be handled in one place and not al over your app(s).

HTH
// Ryan

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

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

===================================
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