Results 1 to 5 of 5

Thread: Check if variable is a Decimal?**RESOLVED

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    142

    Check if variable is a Decimal?**RESOLVED

    Hey Guys,
    I just want to know if an incoming variable is a decimal or not. All the variables I send to the program are suppose to be decimals but a few sneak by that aren't and it messes everything up. Any help would be great. Thanks.

    Example of good data coming in: 125.78
    Example of bad data coming in: 125.122.3

    Last edited by bebandit; Oct 3rd, 2003 at 12:13 PM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I would do it this way , if it raised error , then it's not decimal elsewise , it's decimal .

    VB Code:
    1. Public Function CheckDecimal(ByVal number As Object) As Boolean
    2.         Try
    3.             MessageBox.Show(Convert.ToDecimal(number))
    4.             Return True
    5.         Catch ex As Exception
    6.             MessageBox.Show("Error while converting to Decimal")
    7.             Return False
    8.         End Try
    9.     End Function

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Use something like this to test it .
    VB Code:
    1. MessageBox.Show(CheckDecimal(xxxx))

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    142

    That did it!!

    Thanks Pirate,
    That worked well.....
    You da MAN!
    Bebandit

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Or something like Decimal.Parse()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width