+ Reply to Thread
Results 1 to 6 of 6

test if a value is an integer

  1. #1
    pablo bellissimo
    Guest

    test if a value is an integer

    Hiya there,

    Can anyone tell me how I can test a variable to see if it is a whole number?

    I want to write something like:

    do until variable = integer

    I am just playing around trying to write something that will generate a list
    of prime numbers...

    I know how I could test a given list to show True if it is a prime but I
    want to create a list of just prime numbers.

    Can anyone help?

    Thanks

  2. #2
    Norman Jones
    Guest

    Re: test if a value is an integer

    Hi Pablo,

    > Can anyone tell me how I can test a variable to see if it is a whole
    > number?


    Try something like:

    '===============>>
    Public Sub Test()
    Dim rng As Range
    Dim rCell As Range

    Set rng = Range("A1:A10")

    For Each rCell In rng.Cells
    With rCell
    If IsNumeric(.Value) Then
    If .Value >= 1 Then
    If .Value = Int(.Value) Then
    MsgBox .Value & vbTab & "Integer!"
    Else
    MsgBox .Value & vbTab & "not an integer!"
    End If
    End If
    End If
    End With
    Next

    End Sub
    '<<===============

    ---
    Regards,
    Norman



    "pablo bellissimo" <[email protected]> wrote in
    message news:[email protected]...
    > Hiya there,
    >
    > Can anyone tell me how I can test a variable to see if it is a whole
    > number?
    >
    > I want to write something like:
    >
    > do until variable = integer
    >
    > I am just playing around trying to write something that will generate a
    > list
    > of prime numbers...
    >
    > I know how I could test a given list to show True if it is a prime but I
    > want to create a list of just prime numbers.
    >
    > Can anyone help?
    >
    > Thanks




  3. #3
    Stefi
    Guest

    RE: test if a value is an integer

    IF yourvariable MOD 1 = 0 THEN

    Regards,
    Stefi


    "pablo bellissimo" wrote:

    > Hiya there,
    >
    > Can anyone tell me how I can test a variable to see if it is a whole number?
    >
    > I want to write something like:
    >
    > do until variable = integer
    >
    > I am just playing around trying to write something that will generate a list
    > of prime numbers...
    >
    > I know how I could test a given list to show True if it is a prime but I
    > want to create a list of just prime numbers.
    >
    > Can anyone help?
    >
    > Thanks


  4. #4
    Norman Jones
    Guest

    Re: test if a value is an integer

    Hi Steffi,

    > IF yourvariable MOD 1 = 0 THEN


    From the imediate window:

    ? 1.25 Mod 1
    0

    ? o Mod 1
    0

    ..---
    Regards,
    Norman



    "Stefi" <[email protected]> wrote in message
    news:[email protected]...
    > IF yourvariable MOD 1 = 0 THEN
    >
    > Regards,
    > Stefi
    >
    >
    > "pablo bellissimo" wrote:
    >
    >> Hiya there,
    >>
    >> Can anyone tell me how I can test a variable to see if it is a whole
    >> number?
    >>
    >> I want to write something like:
    >>
    >> do until variable = integer
    >>
    >> I am just playing around trying to write something that will generate a
    >> list
    >> of prime numbers...
    >>
    >> I know how I could test a given list to show True if it is a prime but I
    >> want to create a list of just prime numbers.
    >>
    >> Can anyone help?
    >>
    >> Thanks




  5. #5
    Norman Jones
    Guest

    Re: test if a value is an integer


    > From the imediate window:



    From the immediate window:

    ---
    Regards,
    Norman



    "Norman Jones" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Steffi,
    >
    >> IF yourvariable MOD 1 = 0 THEN

    >
    > From the imediate window:
    >
    > ? 1.25 Mod 1
    > 0
    >
    > ? o Mod 1
    > 0
    >
    > .---
    > Regards,
    > Norman




  6. #6
    Stefi
    Guest

    Re: test if a value is an integer

    Hi Norman,

    Sorry, of course you are right. I mistook remainder for fractional part and
    didn't test my answer. The right answer

    IF yourvariable - INT(yourvariable) = 0 THEN

    I appreciate very much your being particular about spelling.

    Regards,
    Stefi

    "Norman Jones" wrote:

    >
    > > From the imediate window:

    >
    >
    > From the immediate window:
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "Norman Jones" <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi Steffi,
    > >
    > >> IF yourvariable MOD 1 = 0 THEN

    > >
    > > From the imediate window:
    > >
    > > ? 1.25 Mod 1
    > > 0
    > >
    > > ? o Mod 1
    > > 0
    > >
    > > .---
    > > Regards,
    > > Norman

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1