Solved

VB.Net: Check if currency

Posted on 2012-04-02
7
729 Views
Last Modified: 2012-04-02
i am using vb.net,

how to check if a value is in currency format or is a currency.
0
Comment
Question by:baabaa_nl
[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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37797851
Where is the value? In a string variable, textbox, datagridview ...?
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37797857
0
 

Author Comment

by:baabaa_nl
ID: 37797860
value from a datagridviewcell
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37797867
use Regex.IsMatch("RegularExpression") to match the value.

Use the regular expression used in my above link
You can call this method on any Datagrid event which you feel is suitable after databinding event....
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 37797873
You should be able to use something like Decimal.TryParse, supplying the appropriate parameters. In this way, you won't have to do any special coding if your code moves to machine where the format is £2,00 (and your development machine is set up as $2.00).

For example:

Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
    Dim provider As IFormatProvider = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat
    Dim d As Decimal

    Me.lblResult.Text = Decimal.TryParse(Me.txtInput.Text, Globalization.NumberStyles.Currency, provider, d)
End Sub

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37797884
P.S.

The last parameter to Decimal.TryParse is passed ByRef, so if the call to TryParse succeeds, then the converted value will be stored in "d" (in my example). TryParse itself returns a boolean value indicating whether or not the value being tested could be converted to a Decimal type.
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37797901
datagridviewcell does not store values in currency (either string, decimal, double etc) you can parse the value in the cell to check it is numeric, e.g IsNumeric(Me.DataGridView1.Item(0).Value.ToString)
0

Featured Post

Industry Leaders: 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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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