I'm reading values from the KeyValueStore. When the value returns null it seems impossible to test for in a way that seems intuitive.
i.e. the following does not work and the value continues to be null:
In both cases deviceID remains as null
I know it can be solved in the following way:
..but this seems long and just 'feels' wrong..
Is there an alternative way? Maybe a solution would be a method that passes a default value that is returned if the kvs value was null?
i.e. the following does not work and the value continues to be null:
B4X:
Dim deviceID as String
Dim mykvs As KeyValueStore
mykvs.Initialize(File.DirApp, "settings")
deviceID = mykvs.Get("device")
If deviceID = Null Then deviceID = "test"
If deviceID = "" Then deviceID = "test"
I know it can be solved in the following way:
B4X:
Dim o As Object
mykvs.Initialize(File.DirApp, "settings")
o = mykvs.Get("device")
If o = Null Then
deviceID = "test"
Else
deviceID = o
End If
..but this seems long and just 'feels' wrong..
Is there an alternative way? Maybe a solution would be a method that passes a default value that is returned if the kvs value was null?