Results 1 to 7 of 7

Thread: [RESOLVED] Comparing two values, program gets it wrong!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Resolved [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?

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Comparing two values, program gets it wrong!

    Try it like this:
    VB Code:
    1. If Val(CTOSeconds.Text) >= Val(CTCSeconds.Text) Then
    2.     '<Do some stuff>
    3. End If

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Comparing two values, program gets it wrong!

    AH! Works perfect. Thanks!

  5. #5
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: [RESOLVED] Comparing two values, program gets it wrong!

    Why does everyone always think it's the systems fault????

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: [RESOLVED] Comparing two values, program gets it wrong!

    Quote 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

  7. #7
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [RESOLVED] Comparing two values, program gets it wrong!

    Quote 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
  •  



Click Here to Expand Forum to Full Width