• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 909
  • Last Modified:

VB.Net: Check if currency

i am using vb.net,

how to check if a value is in currency format or is a currency.
0
baabaa_nl
Asked:
baabaa_nl
  • 2
  • 2
  • 2
  • +1
1 Solution
 
nepaluzCommented:
Where is the value? In a string variable, textbox, datagridview ...?
0
 
BuggyCoderCommented:
0
 
baabaa_nlAuthor Commented:
value from a datagridviewcell
0
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!

 
BuggyCoderCommented:
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
 
käµfm³d 👽Commented:
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
 
käµfm³d 👽Commented:
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
 
nepaluzCommented:
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

Independent Software Vendors: 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!

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now