+ Reply to Thread
Results 1 to 10 of 10

Thread: positive and negative number check?

  1. #1
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    positive and negative number check?

    I have a text box and a submit button in MS ACCESS

    and i want to check if the number entered is positive or negative.

    So if 3 is entered and i click submit, it writes a message on the screen saying "negative"

    can someone help with some code logic

  2. #2
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    here is my logic:
    Code:
    Private Sub submit_Click()
    Dim txtNumber As Integer
    Dim submit
        
    If txtNumber + Abs(txtNumber) = 0 Then
     MsgBox "Negative"
    Else
     MsgBox "Positive"
        End If
    End Sub
    

  3. #3
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    also need to write some code on :

    Finding the largest and smallest numbers from a list held in a file. Assume that each number is on a separate line.

    Calculating the mean, median and mode of a series of numbers entered by a user from the keyboard.

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Moved to Access Forum

  5. #5
    Barn Enthusiast sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69's Avatar
    Join Date
    Mar 2008
    Location
    The frigid northern plains
    Posts
    432
    Rep Power
    7

    Quote Originally Posted by Centurion View Post
    here is my logic:
    Code:
    Private Sub submit_Click()
    Dim txtNumber As Integer
    Dim submit
        
    If txtNumber + Abs(txtNumber) = 0 Then
     MsgBox "Negative"
    Else
     MsgBox "Positive"
        End If
    End Sub
    
    This won't work, what if the number was 0? That's not really a negative.

    Code:
    Private Sub submit_Click()
    Dim txtNumber as Integer
    
    txtNumber = int(val(me.mytextbox))
    
    If txtNumber < 0 then
     Msgbox("Negative")
    Else
     Msgbox("Positive")
       End If
    End Sub
    
    Join our Folding team: DeveloperBarn Folding
    -----------------------------------
    Folding Stats - Stanford University
    Folding Stats - Extreme Over-Clocking
    Folding Stats - Kakao Stats
    Folding Stats - Xtreme CPU

    -----------------------------------

  6. #6
    Barn Enthusiast sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69's Avatar
    Join Date
    Mar 2008
    Location
    The frigid northern plains
    Posts
    432
    Rep Power
    7

    Quote Originally Posted by Centurion View Post
    also need to write some code on :

    Finding the largest and smallest numbers from a list held in a file. Assume that each number is on a separate line.

    Calculating the mean, median and mode of a series of numbers entered by a user from the keyboard.
    I would use domain aggregate functions.

    Davg
    Dcount

    median would be dcount of your list plus one divided by 2.

    MyMedian = (nz(dcount("[mynumbers]","mytable"),0)+1)/2
    Join our Folding team: DeveloperBarn Folding
    -----------------------------------
    Folding Stats - Stanford University
    Folding Stats - Extreme Over-Clocking
    Folding Stats - Kakao Stats
    Folding Stats - Xtreme CPU

    -----------------------------------

  7. #7
    Moderator don94403 is a jewel in the rough don94403 is a jewel in the rough don94403 is a jewel in the rough don94403's Avatar
    Join Date
    Mar 2008
    Location
    San Mateo, CA, USA
    Posts
    313
    Blog Entries
    8
    Real Name
    Don Ravey
    Rep Power
    6

    I'm afraid that is not the definition of a median. Median is the value of the item for which half the values are greater and half are less. As a simple example, if you have the values: 23, 28, 31, 40, 52, 66, 74, the median is 40, not (7 + 1) / 2, or 4. (And the mean, or average, is their sum divided by the count, in this case about 44.85...)
    Last edited by don94403; February 23rd, 2010 at 11:43 PM.
    question = 2B || !2B

  8. #8
    Barn Enthusiast sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69's Avatar
    Join Date
    Mar 2008
    Location
    The frigid northern plains
    Posts
    432
    Rep Power
    7

    sorry, didn't explain it correctly, meant to say that you count how many numbers you have; in don's example, he had 7 numbers. you add 1 to the count which makes 8, and divide by 2, which gives you 4 - meaning the forth number in the ascending sequence..... sorry, was rushed when I jotted down that formula.
    Join our Folding team: DeveloperBarn Folding
    -----------------------------------
    Folding Stats - Stanford University
    Folding Stats - Extreme Over-Clocking
    Folding Stats - Kakao Stats
    Folding Stats - Xtreme CPU

    -----------------------------------

  9. #9
    Moderator don94403 is a jewel in the rough don94403 is a jewel in the rough don94403 is a jewel in the rough don94403's Avatar
    Join Date
    Mar 2008
    Location
    San Mateo, CA, USA
    Posts
    313
    Blog Entries
    8
    Real Name
    Don Ravey
    Rep Power
    6

    :-) I figured it was either that, or you were relaxing with your second martini when you wrote it! :-)
    question = 2B || !2B

  10. #10
    Barn Enthusiast sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69's Avatar
    Join Date
    Mar 2008
    Location
    The frigid northern plains
    Posts
    432
    Rep Power
    7

    lol, well, if I could have martinis at work, then it would be a lot less stressful these days, lol.
    Join our Folding team: DeveloperBarn Folding
    -----------------------------------
    Folding Stats - Stanford University
    Folding Stats - Extreme Over-Clocking
    Folding Stats - Kakao Stats
    Folding Stats - Xtreme CPU

    -----------------------------------

+ Reply to Thread

Similar Threads

  1. How do I check the tag of a child?
    By bryceowen in forum JavaScript Programming
    Replies: 4
    Last Post: February 19th, 2009, 02:01 PM
  2. Javascript Regex Pattern for decimal number(18,5)
    By guddu in forum JavaScript Programming
    Replies: 12
    Last Post: January 27th, 2009, 11:28 AM
  3. Replies: 9
    Last Post: January 12th, 2009, 06:42 PM
  4. add increment number in date
    By guddu in forum JavaScript Programming
    Replies: 2
    Last Post: August 13th, 2008, 10:47 AM
  5. Page Number Manipulation
    By AOG123 in forum Microsoft Access
    Replies: 6
    Last Post: March 20th, 2008, 02:38 PM

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

SEO by vBSEO