[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.
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
Re: A Number + A Number = 4
Quote:
Originally Posted by
Resilience
[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.
Re: A Number + A Number = 4
...so if the label values can contain decimals use CDbl() instead of Int() or Val().
Re: A Number + A Number = 4
I prefer CInt() & CLng() for integers in a string.
Re: A Number + A Number = 4
Quote:
Originally Posted by
CDRIVE
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
Re: A Number + A Number = 4
From MSDN Library
Quote:
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.
Re: A Number + A Number = 4
Quote:
Originally Posted by
Resilience
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