Agreed…
I need to take this a step further. I saved the RainSensorArray(day) array as a variant array and later loaded it back in on startup. Each value is 0.0. All looks fine until I use this For Each statement to get a total on the variant array:
Var values() As Variant = RainSensorArray
Var sum As Variant
For Each d As Variant In values
sum = sum + d
Next
I receive a nil exception for the sum=sum+d code. Would 0.0 = 0.0 + 0.0 cause a nil?
The array values look okay in the debugger for startup and all show as 0.0. Values = Variant(366) and d = 0.0
Changing sum to an integer seems make things happier. Not sure I understand yet.
When you dim sum as a variant, it starts out nil. That would cause the first iteration to throw a nilobject. If you defined it as
Var sum as Variant = 0.0
That would probably make it happy as well. But it’s best to avoid variants where possible.
You nailed it, Tim. Sounds like a bug but what do I know…
That’s just how variants work. And why you should avoid them. Too much head-scratching involved.
I’m just about bald from this already so what’s a few more hairs. I’ll keep the variant taboo in mind. The project is coming along nicely but I can already see a rewrite to the rewrite, well some.
I think a dictionary would be ideal to store your readings rather than an array. The dictionary using a key/value pair so you don’t need a reading for every day and you can use the HasKey & Lookup functions to check if a key (day) exists or set a default value using Lookup.
It is also easy to save using the generatejson & parsejson functions to serialise & deserialise the data.
Good point, Wayne! I do like using dictionaries but I’m not familiar with Json . I have another method to construct that will keep track of the lowest 24-hour temperatures. I am trying to reason this out now. This may be an opportunity to learn some Json commands with a dictionary. I need to be able to continue with these 24 hr low temps even when the program has been stopped for a which. Yes, the blank entries. The 24hr low needs to be a “running low temp”. Need a challenge?
You’re making me hungry.