AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Syed Rizwan Muhammad Rizvi
Expertise
I can answers questions regarding web based and desktop based programming in VB.Net. Which can include SOAP, XML, Custom Controls, COM Interoperability etc.

Experience
Have been working in this specific area for last 2 years previously I was a VB 6 Developer with experties in other languages as well. Total 10 years of programming experience.

 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > Formatting a number

Topic: VB.NET



Expert: Syed Rizwan Muhammad Rizvi
Date: 5/1/2007
Subject: Formatting a number

Question
Hello,

I'm learning vb.net and am having a problem with formatting a number.

I have a form with a textbox that needs to be formatted when it is displayed. If I hardcode the value in my code it works however if I use the textbox it does not get formatted.  Below is my code.  Thanks.  


This line does not format the number just puts it out as 112080812  
Me.TextBox1.Text = Format("{0:##,###,##0}", Me.TextBox1.Text)

This line works if hard coded
Me.TextBox1.Text = String.Format("{0:##,###,##0}", 112080812)  

Answer
Formatting highly depends on the type of data that you are passing when you say Textbox1.text then you are acutally passing a string not a number. to work round that problem use the CINT or CDBL or VAL functions to convert your string to numeric datatype and then pass it to the format method e.g.:

Me.TextBox1.Text = Format("{0:##,###,##0}", CDBL(Me.TextBox1.Text))

regards,
Rizwan


Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.