+ Reply to Thread
Results 1 to 9 of 9

Comparison operator > not working

  1. #1
    Registered User
    Join Date
    10-01-2014
    Location
    Lyon, France
    MS-Off Ver
    2010
    Posts
    5

    Comparison operator > not working

    Hi all,

    I have developped some excel macros that are processing weather data, and in one of them I've come upon a very simple issue but that I couldn't fix myself...
    This Sub is looking for a minimal temperature (Tmin, as Double) upon 9 daily routine readings (i=0 to 8, 0=most recent) which includes current temperature (T(i), as string) and explicit minimum temperature reports (Tn(i), as string), with value 999 depicting missing or n/a data. As an extra precaution I use the CDbl convertor everytime Tn(i) or T(i) is called although these strings should only contain numeric data.

    If an explicit min temp (tn) is available then I perform 2 QC tests against temperatures previously reported to find any discrepancy:
    - tn should be <= to any previous temperature report (with a margin of 0.1°c), and
    - tn should remain in a reasonable range from the lowest routine temperature previously reported, withing a margin named "TnTolerance" (Public variable defined as Double, set with an UserForm).
    A Boolean named "ManualCheckRequired" will be set to TRUE if one of these 2 tests fails, for further actions later in the program.

    This is the second test that gets me into trouble. It's hightlighted in red in the code below:
    Please Login or Register  to view this content.
    Immediate output, generated by code highlighted in orange (a specific day was tested, with a tn exceeding the tolerance):
    x=6 y=4
    tntolerance= 1.8
    Tmin-Tn(y)= 2.3
    manualcheck= False


    As you can see despite the term (Tmin-Tn(y)) exceeding the variable TnTolerance (2.3 vs. 1.8) the comparison test (highlighted in red) fails and return FALSE.
    If I put the value 1.8 in the code instead of TnTolerance, the test suceed:
    ManualCheckRequired = Tmin - CDbl(Tn(y)) > 1.8 ' Returns "True"

    On the same basis, the first test (highlighted in bold green) works great with the 0.1°c margin entered as is the the comparison formula.

    Do you have any idea why it won't work with variable (TnTolerance) but with its current value (1.8) typed instead ???
    Attached Images Attached Images

  2. #2
    Registered User
    Join Date
    10-01-2014
    Location
    Lyon, France
    MS-Off Ver
    2010
    Posts
    5

    Re: Comparison operator > not working

    Well I just solved the trouble using
    ManualCheckRequired = Tmin - CDbl(Tn(y)) - TnTolerance > 0

    instead of

    ManualCheckRequired = Tmin - CDbl(Tn(y)) > TnTolerance

    But the question remains: Why x > 1.8 works while x > y doesn't even if y=1.8 ?
    And, additionnaly, why x -y > 0 works when x > y doesn't ?

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Comparison operator > not working

    Just out of interest, does:
    Please Login or Register  to view this content.
    work?
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Registered User
    Join Date
    10-01-2014
    Location
    Lyon, France
    MS-Off Ver
    2010
    Posts
    5

    Re: Comparison operator > not working

    Yep it does !
    I'm puzzled, as TnTolerance is already a Double:
    Please Login or Register  to view this content.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Comparison operator > not working

    No it isn't - it's a Variant. To declare all of those as Double, you have to specify the type for each one:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-01-2014
    Location
    Lyon, France
    MS-Off Ver
    2010
    Posts
    5

    Re: Comparison operator > not working

    Quote Originally Posted by romperstomper View Post
    No it isn't - it's a Variant. To declare all of those as Double, you have to specify the type for each one:
    Please Login or Register  to view this content.
    OMG is it the same for local ones ? Like in:
    Please Login or Register  to view this content.
    Will PolarNight be the only Boolean while all others are Variant ?

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Comparison operator > not working

    Yes, that's correct. You have to specify the type for every variable individually (unless you want the default Variant, or you use DefType statement).

  8. #8
    Registered User
    Join Date
    10-01-2014
    Location
    Lyon, France
    MS-Off Ver
    2010
    Posts
    5

    Re: Comparison operator > not working

    Well thanks for the clarification. That was a lame issue, sorry for bothering. Case solved.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Comparison operator > not working

    Glad to help.

    Please don't forget to mark the thread solved using the Thread Tools link at the top of the page.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Like Operator Not Working for Character List
    By Excel Guy 123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-14-2014, 01:47 PM
  2. [SOLVED] Logical Formula with comparison operator not behaving as expected
    By attal in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-26-2013, 02:13 PM
  3. [SOLVED] need formula for comparison operator
    By Mindoz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2012, 04:42 PM
  4. [SOLVED] I'm trying to do a comparison if statement but it is not working!!
    By Brett Smith in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-28-2006, 02:55 PM
  5. "IN" comparison operator
    By Jared in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2005, 01:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1