Results 1 to 2 of 2

Thread: Numbers, decimals...help!

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    10
    Hi,
    I have a program with six text boxes and a few of these relate to one another ie. data entered changes the data in the other after a calculation. The problem I am having is that if I display a negative num or decimal or nothing...I get an error.
    I tried some code that checks to see if it is a number before doing the calc but it didn't check for decimals and negative numbers.
    Can anyone please help with how to do this.

    Thanks in advance,

    Scott
    Trying to teach myself visual basic

  2. #2
    Lively Member
    Join Date
    Jan 1999
    Location
    Lincolnshire, UK
    Posts
    111
    Here are two functions that will check the numbers

    public Function CheckNeg(vValue as single) as boolean
    if abs(vvalue)=vvalue then
    CheckNeg=false
    else
    CheckNeg=true
    end if
    End Function

    Public Function CheckDecimal(vValue as single) as boolean
    if Int(vValue)=vvalue then
    CheckDecimal=False
    else
    CheckDecimal=True
    end if
    End Function

    These Functios will both return false if the number is OK, else they will return True if the number is a decimal or negative

    PS If you use singles instead of Integers or Longs then unless you are doing square roots then you shouldn't get many errors

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