|
-
Oct 8th, 2006, 04:36 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Comparing two values, program gets it wrong!
Hi all,
I believe I've had this problem before, a long time ago, buut...
Basically, in my program it compares two values to see if one is higher than the other, and then it reports back. The only problem is, the system gets it wrong!
The code I use is:
Code:
If CTOSeconds.Text >= CTCSeconds.Text Then
<Do some stuff>
End If
CTOSeconds is the second box, and CTCSeconds is the first one.
However, I entered 4600 into the first box and 600 into the second, and I get the error message (in "Do some stuff). However, sometimes it works fine (for example, when using 4600 in the first box and 200 in the second).
Any ideas?
-
Oct 8th, 2006, 04:38 PM
#2
Re: Comparing two values, program gets it wrong!
Try it like this:
VB Code:
If Val(CTOSeconds.Text) >= Val(CTCSeconds.Text) Then
'<Do some stuff>
End If
-
Oct 8th, 2006, 04:40 PM
#3
Re: Comparing two values, program gets it wrong!
The problem is that you are comparing text, not numbers (so "2000" < "3", as the first letter is lower).
To convert text to a number, use the Val function as gavio showed.
-
Oct 8th, 2006, 04:42 PM
#4
Thread Starter
Addicted Member
Re: Comparing two values, program gets it wrong!
AH! Works perfect. Thanks!
-
Oct 8th, 2006, 06:16 PM
#5
Re: [RESOLVED] Comparing two values, program gets it wrong!
Why does everyone always think it's the systems fault????
-
Oct 8th, 2006, 06:46 PM
#6
Thread Starter
Addicted Member
Re: [RESOLVED] Comparing two values, program gets it wrong!
 Originally Posted by randem
Why does everyone always think it's the systems fault????
Heh, I suppose because it makes them seem less stupid XD
-
Oct 8th, 2006, 06:53 PM
#7
Re: [RESOLVED] Comparing two values, program gets it wrong!
 Originally Posted by randem
Why does everyone always think it's the systems fault????
That's true... but sometimes it really is... not in this case of course.
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
|