?
Solved

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

Posted on 2007-11-26
5
Medium Priority
?
1,591 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

718 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