[Gambas-user] gb.settings: Detect if a slot exists

Tobias Boege taboege at ...626...
Tue Oct 29 13:43:51 CET 2013


On Tue, 29 Oct 2013, Bruce wrote:
> I have a need to detect if a particular Slot exists in the .config
> file for an application. Just the Slot not whether any value lines exist
> under it.
> 
> There doesn't seem to be a way to do this via gb.settings?  I have tried
> using 
> 
>         If Settings.Keys["Filter"] then
> 
> but this seems always to be true. Similarly
> 
>         If Settings["Filter"] then
> 
> always seems to be false.
> 
> So is there a way to find out if a Slot does exist?
> 
> ---- more info -----
> The problem is that the value lines depend on about 8 text boxes set or
> cleared by the user. If one or more of the text boxes are empty then
> that value line will not appear under the [Filter] slot. So I can't
> detect the existence of the slot by detecting a particular value line.
> In fact if they clear all the filter strings then that whole slot will
> disappear.
> 
> Thus I need to check if the slot exists, so then I could
>         If Settings.Exist["Filter"] then 
>           GetFilterSettings
>         Else
>           SetDefaultFilter
>         Endif
> 

Hmm. Settings["Filter"] will return Null if the slot does not exist. Note
that the slot is also non-existent if you do assign Null like

  Settings["Filter"] = Null

which means Settings[sKey] returning Null is a necessary and sufficient
indicator that sKey is not a slot in the Settings.

So, use

  If IsNull(Settings["Filter"]) Then
    ' Settings["Filter"] does not exist...
  Endif

in case you want to do something when the "Filter" key does not exist.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list