VB 2005 parse string and format with 2 trailing zero's

Posted on 2007-11-26
Last Modified: 2013-11-25
This code produces and error in vb 2005 .net 3 framework. How do I get the textbox which is an Access database backend and text datatype to show 45.00 rather than 45  I don't need the Currency symbol.

Private Sub TxtWholesalePrice_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtWholesalePrice.Validated
        Dim WholesalePrice As Decimal
        TxtWholesalePrice.Text = Decimal.Parse(WholesalePrice, 2).ToString("f2")
    End Sub
Question by:mindserve
  • 3
  • 2
LVL 38

Expert Comment

ID: 20351358
Try this instead:

TxtWholesalePrice.Text = Decimal.Parse(WholesalePrice, 2).ToString("0.00")
LVL 38

Expert Comment

ID: 20351468
Actually the parse is not being called correctly.  Just convert to floating point and format:

TxtWholesalePrice.Text = CDbl(WholesalePrice).ToString("0.00")

Author Comment

ID: 20351838
What that gives me is 0.00 when I enter 45 , but not 45.00..??? any other ideas?
LVL 38

Accepted Solution

PaulHews earned 125 total points
ID: 20352918
That extra variable never gets populated.  We need to take the value from the textbox, convert it and format it.

TxtWholesalePrice.Text = CDbl(TxtWholesalePrice).ToString("0.00")

Author Comment

ID: 20353032
This worked, but I had to declare price as decimal...

            Dim Price As Decimal = CDec(TxtWholesalePrice.Text)
            TxtWholesalePrice.Text = CDbl(Price).ToString("0.00")
        Catch ex As Exception
        End Try

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now