I think there would be a flaw with that code. I do not wish to overwrite any good values in the array with “0” since I save/update the array every day to the HD. It needs to maintain all existing values. I need to test it yet but changing the array to a variant may be answer for my code.
Just set to -1 if not valid – Then you will be solid unless that is an issue then the Variant route is solid also.
Thanks Mike, it’s all good to help with the steep learning curve I’m on.
…and do not forget the leap year… day !
Actually, I don’t think it’s an issue since the array will be 366 days and a new array is only triggered when the system clock changes the year. I am only interested in daily totals to override my watering system and a yearly total for grins. Not a 366th day, who cares it’s “0”
No, experienced oldster who forgot things everytime
Now, think at the Jewish Calendar (new year occured to them (Roch Hachana ended yesterday) and at the muslim calendar. I do not even talk about the different dates in use in India.
That would be trouble making
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
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?
when i first saw dim sum… i thought of this https://en.wikipedia.org/wiki/Dim_sum instead…
You’re making me hungry.