Results 1 to 8 of 8

Thread: [RESOLVED] A Number + A Number = 4

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Resolved [RESOLVED] A Number + A Number = 4

    Hi I have a question. Is there a way where in one caption I can have a number and in another caption I can have a different number and when a button is hit it can add those to numbers up and if it is grater than 4 it can show how much it exceeds and if it is less than 4 it can show how much it needs to make 4.

  2. #2
    Lively Member
    Join Date
    May 2005
    Posts
    125

    Re: A Number + A Number = 4

    Code:
    Label1.Caption = 2
    Label2.Caption = 3
    
    If Int(Label1.Caption) + Int(Label2.Caption) > 4 Then MsgBox (Int(Label1.Caption) + Int(Label2.Caption)) - 4
    use int() to get the numerical value of a string
    --- Science does not explain why things are what they are. What we get from Science is our interpretation of how things do what they do.
    --- No Scientific law of the universe is stable, we did not create it, and we will never understand all of its abilities.
    --- What we determine as reality is a mere assumption of what tomorrow will be based on what yesterday was.

  3. #3
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: A Number + A Number = 4

    Quote Originally Posted by Resilience View Post
    [CODE]

    use int() to get the numerical value of a string
    Int() does not return the numerical value of a string. It returns the Integer portion of a number.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  4. #4

  5. #5
    Addicted Member
    Join Date
    Jun 2009
    Location
    C:\Windows\SysWOW64\
    Posts
    229

    Re: A Number + A Number = 4

    I prefer CInt() & CLng() for integers in a string.

  6. #6
    Lively Member
    Join Date
    May 2005
    Posts
    125

    Re: A Number + A Number = 4

    Quote Originally Posted by CDRIVE View Post
    Int() does not return the numerical value of a string. It returns the Integer portion of a number.
    no no no.....

    it returns the Integer portion of the numerical value of the string
    --- Science does not explain why things are what they are. What we get from Science is our interpretation of how things do what they do.
    --- No Scientific law of the universe is stable, we did not create it, and we will never understand all of its abilities.
    --- What we determine as reality is a mere assumption of what tomorrow will be based on what yesterday was.

  7. #7
    Addicted Member
    Join Date
    Jun 2009
    Location
    C:\Windows\SysWOW64\
    Posts
    229

    Re: A Number + A Number = 4

    From MSDN Library
    Int, Fix Functions


    Returns the integer portion of a number.

    Syntax

    Int(number)

    Fix(number)

    The required number argument is a Double or any valid numeric expression. If number contains Null, Null is returned.

    Remarks

    Both Int and Fix remove the fractional part of number and return the resulting integer value.

    The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

  8. #8
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: A Number + A Number = 4

    Quote Originally Posted by Resilience View Post
    no no no.....

    it returns the Integer portion of the numerical value of the string
    Wrong, wrong, wrong! Read post 7 by Cube8. What he posted is verbatim from the MSDN Library. If you're still a skeptic then run this..

    Code:
    Option Explicit
    
    Private Sub Form_Load()
       Dim Data
       Data = "bgh12uhj"
       Me.Caption = Int(Data)        ' Error, error, error....
    End Sub
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

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