VB.Net: Check if currency

Posted on 2012-04-02
Last Modified: 2012-04-02
i am using,

how to check if a value is in currency format or is a currency.
Question by:baabaa_nl
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
LVL 17

Expert Comment

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

Expert Comment

ID: 37797857

Author Comment

ID: 37797860
value from a datagridviewcell
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!

LVL 20

Expert Comment

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....
LVL 75

Accepted Solution

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

LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37797884

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.
LVL 17

Expert Comment

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)

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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