Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
I have a dialog box in which there are a number of frames(fraMWidth) containing option buttons. I'm trying to use Select Case statements to define values dependant on which option button is chosen. I'm struggling with the code and would appreciate any assistance. A snippet of code so far is: Dim MWidth as integer Select Case fraMWidth.Control.Value Case optW20 = True MWidth = 20 Case optW16 = True MWidth = 16 Case optW12 = True MWidth = 12 Case optW10 = True MWidth = 10 Case optW8 = True MWidth = 8 Case optWOther = True MWidth = txtWOther.Value End Select TIA -- Al@n |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try something like this:
1) Use a naming convention for the option buttons Example: All width settings optionbuttons begin with "optW" 2)Enter the width value in the TAG property of those option buttons Example: optW20 would have a TAG property set to: 20 3) Use this kind of code the harvest the MWidth value: '--------Start of Code---------- Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If UCase(Left(oCtrl.Name, 4)) = "OPTW" Then If oCtrl.Value = True Then MWidth = oCtrl.Tag Exit For End If End If Next oCtrl '--------End of Code---------- Is that something you can work with? *********** Regards, Ron XL2002, WinXP "Al@n" wrote: Hi I have a dialog box in which there are a number of frames(fraMWidth) containing option buttons. I'm trying to use Select Case statements to define values dependant on which option button is chosen. I'm struggling with the code and would appreciate any assistance. A snippet of code so far is: Dim MWidth as integer Select Case fraMWidth.Control.Value Case optW20 = True MWidth = 20 Case optW16 = True MWidth = 16 Case optW12 = True MWidth = 12 Case optW10 = True MWidth = 10 Case optW8 = True MWidth = 8 Case optWOther = True MWidth = txtWOther.Value End Select TIA -- Al@n |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ron
Thanks for the suggestion, I've never come across TAG before. I guess for the free format entre "optWOther", I will have to define the TAG using code. I'll give it a go Thanks again. Thanks Alan "Ron Coderre" wrote in message ... Try something like this: 1) Use a naming convention for the option buttons Example: All width settings optionbuttons begin with "optW" 2)Enter the width value in the TAG property of those option buttons Example: optW20 would have a TAG property set to: 20 3) Use this kind of code the harvest the MWidth value: '--------Start of Code---------- Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If UCase(Left(oCtrl.Name, 4)) = "OPTW" Then If oCtrl.Value = True Then MWidth = oCtrl.Tag Exit For End If End If Next oCtrl '--------End of Code---------- Is that something you can work with? *********** Regards, Ron XL2002, WinXP "Al@n" wrote: Hi I have a dialog box in which there are a number of frames(fraMWidth) containing option buttons. I'm trying to use Select Case statements to define values dependant on which option button is chosen. I'm struggling with the code and would appreciate any assistance. A snippet of code so far is: Dim MWidth as integer Select Case fraMWidth.Control.Value Case optW20 = True MWidth = 20 Case optW16 = True MWidth = 16 Case optW12 = True MWidth = 12 Case optW10 = True MWidth = 10 Case optW8 = True MWidth = 8 Case optWOther = True MWidth = txtWOther.Value End Select TIA -- Al@n |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
For the optWOther optionbutton, set the Tag to: "Other"
Then use something like this: '--------Start of Code---------- Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If UCase(Left(oCtrl.Name, 4)) = "OPTW" Then If oCtrl.Value = True Then MWidth = oCtrl.Tag If MWidth = "Other" Then MWidth = txtWOther.Value End If Exit For End If End If Next oCtrl '--------End of Code---------- You'd probably also want to check that the user actually entered a value. Does that help? *********** Regards, Ron XL2002, WinXP "Al@n" wrote: Ron Thanks for the suggestion, I've never come across TAG before. I guess for the free format entre "optWOther", I will have to define the TAG using code. I'll give it a go Thanks again. Thanks Alan "Ron Coderre" wrote in message ... Try something like this: 1) Use a naming convention for the option buttons Example: All width settings optionbuttons begin with "optW" 2)Enter the width value in the TAG property of those option buttons Example: optW20 would have a TAG property set to: 20 3) Use this kind of code the harvest the MWidth value: '--------Start of Code---------- Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If UCase(Left(oCtrl.Name, 4)) = "OPTW" Then If oCtrl.Value = True Then MWidth = oCtrl.Tag Exit For End If End If Next oCtrl '--------End of Code---------- Is that something you can work with? *********** Regards, Ron XL2002, WinXP "Al@n" wrote: Hi I have a dialog box in which there are a number of frames(fraMWidth) containing option buttons. I'm trying to use Select Case statements to define values dependant on which option button is chosen. I'm struggling with the code and would appreciate any assistance. A snippet of code so far is: Dim MWidth as integer Select Case fraMWidth.Control.Value Case optW20 = True MWidth = 20 Case optW16 = True MWidth = 16 Case optW12 = True MWidth = 12 Case optW10 = True MWidth = 10 Case optW8 = True MWidth = 8 Case optWOther = True MWidth = txtWOther.Value End Select TIA -- Al@n |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ron
That helps immensley. Thanks Al@n "Ron Coderre" wrote in message ... For the optWOther optionbutton, set the Tag to: "Other" Then use something like this: '--------Start of Code---------- Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If UCase(Left(oCtrl.Name, 4)) = "OPTW" Then If oCtrl.Value = True Then MWidth = oCtrl.Tag If MWidth = "Other" Then MWidth = txtWOther.Value End If Exit For End If End If Next oCtrl '--------End of Code---------- You'd probably also want to check that the user actually entered a value. Does that help? *********** Regards, Ron XL2002, WinXP "Al@n" wrote: Ron Thanks for the suggestion, I've never come across TAG before. I guess for the free format entre "optWOther", I will have to define the TAG using code. I'll give it a go Thanks again. Thanks Alan "Ron Coderre" wrote in message ... Try something like this: 1) Use a naming convention for the option buttons Example: All width settings optionbuttons begin with "optW" 2)Enter the width value in the TAG property of those option buttons Example: optW20 would have a TAG property set to: 20 3) Use this kind of code the harvest the MWidth value: '--------Start of Code---------- Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If UCase(Left(oCtrl.Name, 4)) = "OPTW" Then If oCtrl.Value = True Then MWidth = oCtrl.Tag Exit For End If End If Next oCtrl '--------End of Code---------- Is that something you can work with? *********** Regards, Ron XL2002, WinXP "Al@n" wrote: Hi I have a dialog box in which there are a number of frames(fraMWidth) containing option buttons. I'm trying to use Select Case statements to define values dependant on which option button is chosen. I'm struggling with the code and would appreciate any assistance. A snippet of code so far is: Dim MWidth as integer Select Case fraMWidth.Control.Value Case optW20 = True MWidth = 20 Case optW16 = True MWidth = 16 Case optW12 = True MWidth = 12 Case optW10 = True MWidth = 10 Case optW8 = True MWidth = 8 Case optWOther = True MWidth = txtWOther.Value End Select TIA -- Al@n |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Another possibility which doesn't require using the Tag property is this...
Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If oCtrl.Parent Is fraMWidth Then If oCtrl.Name Like "optW*" Then If oCtrl.Value = True Then MWidth = Replace(oCtrl.Name, "optW", "") Exit For End If End If End If Next oCtrl The code does require the naming convention you mentioned in your first item. If, as I suspect, that only OptionButtons with names beginning with "optW" will be in the fraMWidth frame, then we can eliminate the If-Then level that tests for the name. In that case, the code becomes... Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If oCtrl.Parent Is fraMWidth Then If oCtrl.Value = True Then MWidth = Replace(oCtrl.Name, "optW", "") Exit For End If End If Next oCtrl One final note that the numbers following the "optW" can contain any number of digits (in case that flexibility is needed). Rick "Ron Coderre" wrote in message ... Try something like this: 1) Use a naming convention for the option buttons Example: All width settings optionbuttons begin with "optW" 2)Enter the width value in the TAG property of those option buttons Example: optW20 would have a TAG property set to: 20 3) Use this kind of code the harvest the MWidth value: '--------Start of Code---------- Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If UCase(Left(oCtrl.Name, 4)) = "OPTW" Then If oCtrl.Value = True Then MWidth = oCtrl.Tag Exit For End If End If Next oCtrl '--------End of Code---------- Is that something you can work with? *********** Regards, Ron XL2002, WinXP "Al@n" wrote: Hi I have a dialog box in which there are a number of frames(fraMWidth) containing option buttons. I'm trying to use Select Case statements to define values dependant on which option button is chosen. I'm struggling with the code and would appreciate any assistance. A snippet of code so far is: Dim MWidth as integer Select Case fraMWidth.Control.Value Case optW20 = True MWidth = 20 Case optW16 = True MWidth = 16 Case optW12 = True MWidth = 12 Case optW10 = True MWidth = 10 Case optW8 = True MWidth = 8 Case optWOther = True MWidth = txtWOther.Value End Select TIA -- Al@n |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Rick
Thank you for the reply, an interesting slant on the issue. I will give it a try. Regards Al@n "Rick Rothstein (MVP - VB)" wrote in message ... Another possibility which doesn't require using the Tag property is this... Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If oCtrl.Parent Is fraMWidth Then If oCtrl.Name Like "optW*" Then If oCtrl.Value = True Then MWidth = Replace(oCtrl.Name, "optW", "") Exit For End If End If End If Next oCtrl The code does require the naming convention you mentioned in your first item. If, as I suspect, that only OptionButtons with names beginning with "optW" will be in the fraMWidth frame, then we can eliminate the If-Then level that tests for the name. In that case, the code becomes... Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If oCtrl.Parent Is fraMWidth Then If oCtrl.Value = True Then MWidth = Replace(oCtrl.Name, "optW", "") Exit For End If End If Next oCtrl One final note that the numbers following the "optW" can contain any number of digits (in case that flexibility is needed). Rick "Ron Coderre" wrote in message ... Try something like this: 1) Use a naming convention for the option buttons Example: All width settings optionbuttons begin with "optW" 2)Enter the width value in the TAG property of those option buttons Example: optW20 would have a TAG property set to: 20 3) Use this kind of code the harvest the MWidth value: '--------Start of Code---------- Dim oCtrl As Control Dim MWidth For Each oCtrl In UserForm1.Controls If UCase(Left(oCtrl.Name, 4)) = "OPTW" Then If oCtrl.Value = True Then MWidth = oCtrl.Tag Exit For End If End If Next oCtrl '--------End of Code---------- Is that something you can work with? *********** Regards, Ron XL2002, WinXP "Al@n" wrote: Hi I have a dialog box in which there are a number of frames(fraMWidth) containing option buttons. I'm trying to use Select Case statements to define values dependant on which option button is chosen. I'm struggling with the code and would appreciate any assistance. A snippet of code so far is: Dim MWidth as integer Select Case fraMWidth.Control.Value Case optW20 = True MWidth = 20 Case optW16 = True MWidth = 16 Case optW12 = True MWidth = 12 Case optW10 = True MWidth = 10 Case optW8 = True MWidth = 8 Case optWOther = True MWidth = txtWOther.Value End Select TIA -- Al@n |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
IF Statements to Select Case??? | Excel Discussion (Misc queries) | |||
Case without Select Case error problem | Excel Discussion (Misc queries) | |||
CASE STATEMENTS | Excel Programming | |||
Using Select Case Statements | Excel Programming |