I just discovered Lookup and was wondering how I would change this code to use it?
If Dictionary_Inputs.hasKey(“Rain Sensor”) And Dictionary_Inputs.value(“Rain Sensor”) = “Closed” Then
I just discovered Lookup and was wondering how I would change this code to use it?
If Dictionary_Inputs.hasKey(“Rain Sensor”) And Dictionary_Inputs.value(“Rain Sensor”) = “Closed” Then
If dictionary_inputs.Lookup(“Rain Sensor”, “”) = “Closed” Then
You’ll want to put the “not closed” value in the second parameter.
If dictionary_inputs.Lookup(“Rain Sensor”, “Open”) = “Closed” Then
If the statement is false do you need to do something with the returned “Open”?
Nope.
In that case could u just leave the second statement as “”?
Yes, As long as an empty string doesn’t mean anything to you.
Thanks, Greg. By the time I’m done rewriting this program it will be time to rewrite it again. So much to learn.
I still must not have this right since it errors:
If dictionary_inputs.Lookup(“Rain Sensor”, “Open”) = “Closed” Then
RainSensorArray.addrow(datetime.now)
End
Replace the smart quotes with plain ones
Okay, you got me on this one. Where do I find a plain Quote?
“”
Are smart quotes. ""
are plain quotes.
So what you actually need is:
If dictionary_inputs.Lookup("Rain Sensor", "Open") = "Closed" Then
RainSensorArray.addrow(datetime.now)
End
It’s on your keyboard. In fact it’s for the curly quotes that you have to fiddle about to get.
If dictionary_inputs.Lookup("Rain Sensor", "Open") = "Closed" Then
RainSensorArray.addrow(datetime.now)
End
But since the value ‘Open’ is never used, there is no difference between this and
dictionary_inputs.haskey , surely?
I’m not sure why other than going to my keyboard prefs and unchecking “Use Smart Quotes”. It works now. My original quotes in XOJO looked like plain quotes but I notice on the forum they looked like smart ones I used. A little confusing.
I’m looking for a value of “Closed” to be true.
It looks like this key has multiple states. Empty for uninitialized, Open for in use, closed for not in use. This setup could also account for adding additional states in the future like “Error”.
Normally for me two states exist, Close and Open. But as you say others could be used.
Got it.
In effect, this is a workaround for the exception you would usually get by assuming the key exists when it doesn’t.