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

Bruce bbruen at ...2308...
Thu Oct 31 02:22:48 CET 2013


On Tue, 2013-10-29 at 13:38 +0100, Charlie Reinl wrote:
> Am Dienstag, den 29.10.2013, 13:57 +1030 schrieb Bruce:
> > 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
> > 
> 
> Salut Bruce,
> 
> Settings.Read (gb.settings)
> Sub Read ( hObject As Object [ , sKey As String, vDefault As Variant ] )
> 
> Settings("Filter", GetFilterSettings, SetDefaultFilter)
> 
> or
> 
> Public Function KeyExists(objSetting As Settings, sFindKey As String) As
> Boolean
> Dim sKey As String
> Dim bRet As Boolean
>    bRet = False
>    For Each sKey In objSetting.Keys
>       If sKey = sFindKey Then
>           bRet = True
>          Break
>       Endif
>    Next
>    Return bRet
> End
> 
> 
> 
Hmm. You second idea works, but I was trying to avoid that as I will be
calling it multiple times, at least once for each filter item that gets
defined.
But it might be better than the messy solution I just posted back to
Tobi.


-- 
Bruce <bbruen at ...2308...>
Paddys-Hill dot net





More information about the User mailing list