|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Collection of Radio buttons Functionretrieve (and later use) the caption of the actual radio button select, but I am having the hardest time. I've tried several different contstructs and none have worked I'm not even sure what argument to throw in the function call (I've got 'GetCaption(optSelect(Index))' at this point) The function I've currently got (hardcoded, but not what I'm after) is: Private Function GetCaption(intItem As Integer) As String Dim sTitle As String Select Case intItem Case 0 sTitle = "Select" ' caption of optSelect(0) Case 1 sTitle = "Update" ' caption of optSelect(1) Case 2 sTitle = "Insert" '....etc Case 3 sTitle = "Delete" End Select GetCaption = sTitle End Function Can anyone see what I'm missing here? I just want to return the caption of the selected radiobutton. private sub command1_click()
dim ndx as long ndx = GetSelectedOptionIndex2(option1) if ndx > -1 then debug.print option1(ndx).caption end if end sub Private Function GetSelectedOptionIndex2(obj As Object) As Long Dim ctl As OptionButton 'default return value if nothing 'is selected GetSelectedOptionIndex2 = -1 If VarType(obj) = vbObject Then If TypeOf obj(obj.LBound) Is OptionButton Then For Each ctl In obj If ctl.Value Then GetSelectedOptionIndex2 = ctl.Index Exit For End If Next End If 'If TypeOf End If 'If VarType End Function -- Randy Birch MS MVP Visual Basic http://vbnet.mvps.org/ Please reply to the newsgroups so all can participate. "Elmo Watson" <sputnik@nospam.yahoo.com> wrote in message I have a collection of 4 radio buttons - - I'm trying to write a function tonews:%23ZppLpxQGHA.5552@TK2MSFTNGP14.phx.gbl... retrieve (and later use) the caption of the actual radio button select, but I am having the hardest time. I've tried several different contstructs and none have worked I'm not even sure what argument to throw in the function call (I've got 'GetCaption(optSelect(Index))' at this point) The function I've currently got (hardcoded, but not what I'm after) is: Private Function GetCaption(intItem As Integer) As String Dim sTitle As String Select Case intItem Case 0 sTitle = "Select" ' caption of optSelect(0) Case 1 sTitle = "Update" ' caption of optSelect(1) Case 2 sTitle = "Insert" '....etc Case 3 sTitle = "Delete" End Select GetCaption = sTitle End Function Can anyone see what I'm missing here? I just want to return the caption of the selected radiobutton. "Elmo Watson" <sputnik@nospam.yahoo.com> wrote How about saving the Caption whenever it gets changed, much like:> I have a collection of 4 radio buttons - - I'm trying to write a function to > retrieve (and later use) the caption of the actual radio button select, but > I am having the hardest time. Private Sub optSelect_Click(Index As Integer) optSelect(0).Tag = optSelect(Index).Caption End Sub Now the Tag property of optSelect(0) will always contain the currently selected Caption, no function would be necessary. Msgbox optSelect(0).Tag HTH LFS |
|||||||||||||||||||||||