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:
Immediate output, generated by code highlighted in orange (a specific day was tested, with a tn exceeding the tolerance):![]()
Please Login or Register to view this content.
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 ???
Bookmarks