|
-
Jun 20th, 2009, 03:03 PM
#1
Thread Starter
Fanatic Member
[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.
-
Jun 20th, 2009, 03:31 PM
#2
Lively Member
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.
-
Jun 21st, 2009, 09:06 AM
#3
Re: A Number + A Number = 4
 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.
<--- 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?? 
-
Jun 21st, 2009, 11:17 AM
#4
Re: A Number + A Number = 4
...so if the label values can contain decimals use CDbl() instead of Int() or Val().
-
Jun 22nd, 2009, 08:00 AM
#5
Addicted Member
Re: A Number + A Number = 4
I prefer CInt() & CLng() for integers in a string.
-
Jun 23rd, 2009, 03:44 PM
#6
Lively Member
Re: A Number + A Number = 4
 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
--- 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.
-
Jun 23rd, 2009, 04:01 PM
#7
Addicted Member
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.
-
Jun 23rd, 2009, 04:21 PM
#8
Re: A Number + A Number = 4
 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
<--- 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|