RPG and COBOL are probably the most common ones that do and the ones that I
am running into.  I'm sure other languages do the same thing but I am not as
familiar with them.

For example, when you declare a variable in RPG it has a true length
associated with it.  That length is what is setting the formatting.  Here's
a pseudo the VB version of what they can do...  assuming that VB could have
all of this!

Dim int1 as Integer Length(4) Inz(12)
Dim dt as date    Length(8) Inz('20080812') Format(*YMD)

If you looked out what int1 contain, it would actually contain 0012.  This
is because the length is 4, but the value is only 12.  So it pads with
zeros.

Now in these legacy languages when you do something like

        int1 = dt

the OS is able to do something for you behind the scenes.  It does something
sort of like...

        Int1 = Mid(dt.Format("00000000"), 1, Int1.Length)

Int1 would then contain 2008.  In the legacy language all you have to do is
[int1 = dt].  The rest of it is handled for you.

What I am running into is that I wrote a compiler for .Net for the legacy
languages.  So I compile the legacy languages and output whatever .Net code
base you want, be it C#, VB.Net, or MSiL.  But in order to correctly output
the code, I have to find a decent way to handle this stuff in .Net.  This is
one area where I can handle it, but I think there is a better way.

What I have is a function that sort of looks like...

        Int1 = FunctionCall(dt, "00000000", int1, "0000")

Where I have to pass in the formats.  That's sort of lame looking code and I
want to get ride of having to passing in the formats.  I can do that if I
could do one of two things.  If I could ask what the length of dt is as
defined, not what it currently contains.  Or I could build a little array in
the constructor of the class and store the data.

        "int1", "4"
        "dt", "8"

When I come back around to that function call, I could do something like...

        Int1 = FunctionCall(dt)

With this, I would have to be able to ask .Net what's the name of dt.  Of
course it's "dt", but once I pass it into the function I don't know of a way
to get it's real name, so I cannot lookup the length from the little array.

Or using extensions in 3.5 I could do

        Int1 = dt.Format()

If I could extend .ToString() or whatever is the default for integers and
dates, I might be able to do something like...

        Int1 = dt

I think that these options are MUCH better than hard coding the format
strings for EVERY line of code that uses the variables, which is almost
every line of code.

It would seem that there has to be some way to get one of the options to
work.  I just have something causing me problems in each version.

Any thoughts or suggestions would be very much appreciated.

Best regards,
Jon "Greg"ory Rothlander






-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of John Warner
Sent: Wednesday, August 13, 2008 3:48 AM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] Can you extend the data types in VB.Net
Importance: Low

Greg, educate me a bit; what other language stores format with data types?

John Warner


> -----Original Message-----
> From: Discussion of advanced .NET topics. [mailto:ADVANCED-
> [EMAIL PROTECTED] On Behalf Of Greg Rothlander
> Sent: Tuesday, August 12, 2008 8:50 PM
> To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
> Subject: Re: [ADVANCED-DOTNET] Can you extend the datatypes in VB.Net
>
> Exactly.  That is what it is in .Net, but not in other languages.  In
other
> languages you store the format within the data type.  So I'm just trying
to
> figure out good way to keep track of the format as well.
>
> I can keep track of the format in a little array.  Then look up the
format
> when the variable is about to be displayed.  It seems that using
extensions
> in 3.5 might handle this for me.  But now I have to figure out how to
look
> it up within an array.
>
> -----Original Message-----
> From: Discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED] On Behalf Of Phil
> Sayers
> Sent: Sunday, August 10, 2008 12:19 AM
> To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
> Subject: Re: [ADVANCED-DOTNET] Can you extend the datatypes in VB.Net
>
> 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 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

===================================
This list is hosted by DevelopMentor.  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