Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Function in VB 2005

Status
Not open for further replies.
Aug 1, 2003
39
US
I am sending a string value to a function and using the value in this Format Function within the called function

DollarAmount = Format(DollarAmount, "000000.00")

During debug I notice it changes DollarAmount variable for instance from "120.00" to "000000.00" instead of "000120.00" like it should. I am wondering why it is not working?

Thanks in Advance
Brian
 
you could try changing dollaramount from a string to a single:

Code:
DollarAmount = Format(CSng(DollarAmount), "000000.00")


mr s. <;)

 
DollarAmount = String.Format("000000.00",DollarAmount)

or, if that doesn't work, how about

DollarAmount = String.Format("000000.00",Decimal.Parse(DollarAmount))


Not tested either...
 
The format function will only work correctly with numeric values if you want to format that so misterstick and mmilans second attempt should both work.

Christiaan Baes
Belgium

My Blog
 
Thanks to all,

I tried misterstick's first and it worked. I haven't tried the others yet and don't know if I will have time to.

In this case CSng converted the string to a Single variable from the string I was trying to convert.

I was using VB.NET in a nutshell

Format Function
Class
Microsoft.VisualBasic.Strings

Syntax
Format(expression[, style[, dayofweek[, weekofyear]]])

expression
Use: required
Data Type: String/Numeric
Any Valid string or numeric expression

Style
Use: Optional
Data Type: String
A valid Name or user-defined format expression

I figured having the String in the expression that it would worked.

Thanks to all for your help
 
may be this one..
Code:
DollarAmount = Format([COLOR=red]Val[/color](DollarAmount), "000000.00")

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top