+ Reply to Thread
Results 1 to 3 of 3

Syntax for Logical Operators to Limit Input?

  1. #1
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    Syntax for Logical Operators to Limit Input?

    Good Morning,
    I am creating a data entry form and have followed the tutorials written by Peter Aitken in MSDN . He shows how to limit entry to numerical values and that is very clear. I am trying to allow the user to enter a percent such as 21.2%.

    I just can't seem to find the right syntax . I can limit to the decimal point or to the percent sign with a single statement. Or I can limit to the numerical range of 1 through 9, but I can't seem to do all three with one statement.

    Here is the last statement I tried:

    Private Sub txtSolidsRaw_KeyPress(ByVal KeyAscii _
    As MSForms.ReturnInteger)

    If KeyAscii <> 36 Or KeyAscii <> 46 Or KeyAscii <> 48 _
    Or KeyAscii <> 49 Or KeyAscii <> 50 Or KeyAscii <> 51 _
    Or KeyAscii <> 52 Or KeyAscii <> 53 Or KeyAscii <> 54 _
    Or KeyAscii <> 55 Or KeyAscii <> 56 Or KeyAscii <> 57 Then

    KeyAscii = 0

    End If

    End Sub
    Thanks!
    Dennis

    I am using Windows 7 and Office 2007, all of my posts are based on this.

  2. #2
    Tom Ogilvy
    Guest

    Re: Syntax for Logical Operators to Limit Input?

    % is 37

    ? asc("%")
    37

    Private Sub txtSolidsRaw_KeyPress(ByVal KeyAscii _
    As MSForms.ReturnInteger)

    If not ((KeyAscii > 48 And KeyAscii <= 57) or KeyAscii = 46 _
    or KeyAscii = 37) Then

    KeyAscii = 0

    End If

    end if

    --
    Regards,
    Tom Ogilvy

    "DCSwearingen" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Good Morning,
    > I am creating a data entry form and have followed the tutorials written
    > by Peter Aitken in MSDN . He shows how to limit entry to numerical
    > values and that is very clear. I am trying to allow the user to enter
    > a percent such as 21.2%.
    >
    > I just can't seem to find the right syntax . I can limit to the
    > decimal point or to the percent sign with a single statement. Or I can
    > limit to the numerical range of 1 through 9, but I can't seem to do all
    > three with one statement.
    >
    > Here is the last statement I tried:
    >
    > Private Sub txtSolidsRaw_KeyPress(ByVal KeyAscii _
    > As MSForms.ReturnInteger)
    >
    > If KeyAscii <> 36 Or KeyAscii <> 46 Or KeyAscii <> 48 _
    > Or KeyAscii <> 49 Or KeyAscii <> 50 Or KeyAscii <> 51 _
    > Or KeyAscii <> 52 Or KeyAscii <> 53 Or KeyAscii <> 54 _
    > Or KeyAscii <> 55 Or KeyAscii <> 56 Or KeyAscii <> 57 Then
    >
    > KeyAscii = 0
    >
    > End If
    >
    > End Sub
    >
    >
    > --
    > DCSwearingen
    >
    >
    > ------------------------------------------------------------------------
    > DCSwearingen's Profile:

    http://www.excelforum.com/member.php...o&userid=21506
    > View this thread: http://www.excelforum.com/showthread...hreadid=499375
    >




  3. #3
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    Many Thanks

    Thank You!!

    I had a typo in my earlier message. I did have 37 for the percent sign in my code. I needed the parenthesis to combine the operations. I'll have to remember that in the future!!

    Again, thanks to all who post answers on this forum. I read a lot of the answers, even if I have not run across the issue.

+ 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