Setting an element in an array of option buttons to True is easy. Click on the option button, or use this code:

OptionArray(ThisOne) = True

ThisOne is the Index of the member you want to be selected. Getting the True member of an option array is not so simple. Because you need to perform this kind of task in almost any reasonably complex program, adding this function to your code library or generic module simplifies the task. You don’t need to know the array size in advance:

Function OptionTrueIs(OptionArrayName As _
	Variant) As Integer
	' Returns the index of the True
	' member of an option array
	Dim Ctl as Control
	For Each Ctl in OptionArrayName
		If Ctl.Value = True Then
			OptionTruels = Ctl.Index
			Exit For
		End If
	Next
End Function

You can use the routine to set a Public variable from a Properties sheet using this format:

SomePublicVariable = OptionTrueIs(SomeOptionArray())

Or use this code to save a program variable between runs:

SaveSetting("MyApp", "OptionSettings", _
	"OptionKey", OptionTrueIs(SomeOptionArray())

Load the routine using this code:

SomeOptionArray(GetSetting("MyApp", "", _
	"OptionSettings", "OptionKey",0))=True

Or you can load the routine using this code:

SomePublicVariable = GetSetting("MyApp", "", _
	"OptionSettings", "OptionKey",0)

Use this code to control a Select Case structure:

Select Case OptionTrueIs(SomeOptionArray())
	Case 0:
	' This code will execute if element 0
	' of SomeOptionArray() is selected.
End Select

Use this code to test a condition:

If OptionTrueIs(SomeOptionArray()) = SomeValue Then
	' This code will execute if element
	' SomeValue of SomeOptionArray() is
	' selected.
End If

Popularity: 7% [?]