Visual Basic Core Snippet Routines
GetSelectedOptionIndex
          
                 
   Returns the index of the selected option button in a control array.          
           Updated:   Monday December 26, 2011   
click to copy code:  


   Applies to:   VB4-32, VB5, VB6   
OS restrictions:   None  
 Code Snippet
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright 1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function GetSelectedOptionIndex() As Long

  'returns the selected item index from
  'an option button array. Use in place
  'of multiple If...Then statements!
  'If your array contains more elements,
  'just append them to the test condition,
  'setting the multiplier to the button's
  'negative -index.
   GetSelectedOptionIndex = Option1(0).Value * 0 Or _
                            Option1(1).Value * -1 Or _
                            Option1(2).Value * -2 Or _
                            Option1(3).Value * -3
End Function

 Calling Syntax
  nSelIndex = GetSelectedOptionIndex()

 Comments / Related
demo in use:   VarMonthName: Retrieve Localized Month Names
VarWeekdayName: Retrieve Localized Weekday Names
ShellExecute: Send Large Emails in Outlook Express
SendMessage: Auto-size ListView Column Width
FindFirstFile: Changing File and/or Folder Attributes Recursively
Shell_NotifyIcon: Display Systray Balloon Tips
   
  
Related:   Pure VB: Determine the Selected Button in a Option Button Control Array  

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright 1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter