Solved

VB.Net: Check if currency

Posted on 2012-04-02
7
624 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
  • 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 74

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 74

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now