Get the True Member of an Option Array

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	NextEnd 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
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may