Format() method

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

I would like to add $ symbol in numeric amount. For that I have used
Microsoft.VisualBasic.Strings.Format(strAmount, "$0.00").

But it seems to me that I am using VisualBasic name space and my manager
wants to use .Net name space function instead of VisualBasic. Is there is any
function availble for this in .Net?

Sorry I am new to .Net hence I am not sure about this.

Regards,
Ramesh
 
But it seems to me that I am using VisualBasic name space and my
manager wants to use .Net name space function instead of VisualBasic.
Is there is any function availble for this in .Net?

String.Format.
 
Kannan said:
hi,

I would like to add $ symbol in numeric amount. For that I have used
Microsoft.VisualBasic.Strings.Format(strAmount, "$0.00").

But it seems to me that I am using VisualBasic name space and my manager
wants to use .Net name space function instead of VisualBasic. Is there is any
function availble for this in .Net?

Sorry I am new to .Net hence I am not sure about this.

Regards,
Ramesh

Why does your manager let you program VB if there is an aversion to using the VisualBasic namespace? I really don't understand that
position.
 
Kannan said:
I would like to add $ symbol in numeric amount. For that I have used
Microsoft.VisualBasic.Strings.Format(strAmount, "$0.00").

But it seems to me that I am using VisualBasic name space and my manager
wants to use .Net name space function instead of VisualBasic.

Why? Are you writing Visual Basic code or not?
If you are, then the /compiler/ will be using stuff from
Microsoft.VisualBasic under the covers - you're not saving or gaining
anything by ignoring the functionality that's provided for you.
If you want to go down that road, write in C#.
Is there is any function availble for this in .Net?

Well, yes, there is but, looking at your code, you need to be careful.

Imports VB = Microsoft.VisualBasic

Dim s as String _
= VB.Strings.Format( strAmount, "$0.00" )

You're relying on Evil Type Coercion to convert "strAmount" from a
String into a numeric value, before formatting it using a numeric
formatting pattern. AFAIK, none of the .Net methods will do this;
you'll have to do the conversion yourself, as in

Dim d as Double _
= CDbl( strAmount ) ' I know; I'm terrible :-)
Dim s as String _
= d.ToString( "$0.00" )

HTH,
Phill W.
 
VisualBasic namespace is really just for legacy stuff and converted
projects... if you want to code in "true" .NET you should not use it and
find the real way to do it from the System namespace down.. you never know
when MS may ditch the VisualBasic namespace
 
I believe you are quite mistaken. The VisualBasic.Compatibility namespace is there for that purpose. If you don't like VB, then
switch to C#.
 
Smokey said:
VisualBasic namespace is really just for legacy stuff and converted
projects... if you want to code in "true" .NET you should not use it and
find the real way to do it from the System namespace down.. you never know
when MS may ditch the VisualBasic namespace

I would beg to differ.

The Microsoft.VisualBasic./Compatibility/ assembly contains all the
"old" stuff that we really /shouldn't/ be bothering with any more -
fixed length strings and such like (yuk!).

The Microsoft.VisualBasic assembly is part and parcel of the language,
like it or not - it's even used by the Visual Basic /compiler/, under
the covers. Just see /if/ you can compile a V.B. assembly that
/doesn't/ have a dependency on this assembly!

(and, if you /haven't/ got to VB'2005 yet, just what /is/ the "true
..Net" version of

ReDim Preserve myArray( 22 )

??

Regards,
Phill W.
 
Back
Top