Solved

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

Posted on 2007-11-26
5
1,574 Views
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
0
Comment
Question by:mindserve
  • 3
  • 2
5 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 20351358
Try this instead:

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

Expert Comment

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

TxtWholesalePrice.Text = CDbl(WholesalePrice).ToString("0.00")
0
 
LVL 1

Author Comment

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

Accepted Solution

by:
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")
0
 
LVL 1

Author Comment

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


Try
            Dim Price As Decimal = CDec(TxtWholesalePrice.Text)
            TxtWholesalePrice.Text = CDbl(Price).ToString("0.00")
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString)
        End Try
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Run code from text file in vb 1 64
Excel VBA, find a string in a column, update a cell 7 80
Problem to open text file 11 110
how to Classify of email (pdf attachments) 7 36
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

778 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