-
May 29th, 1999, 10:32 PM
#1
option buttons/check boxes question
I'm working with VB6. I have a couple of groups of checkboxes and option buttons on their own frames, being treated as groups. Is there a way I can use Select Case to go through each control on a frame and respond to its status (i.e. checked/unchecked) instead of using If/Then statements? I tried creating a control array of checkboxes but it didn't work with Select Case. Thanks.
-
May 31st, 1999, 02:20 AM
#2
Re: option buttons/check boxes question
Hi,
To loop thru individual items of control array you should use For each. Ex.
dim lpChkBox as CheckBox
for each lpChkBox in me.Check1
' Check1 is the control arry of Check Boxes
' You couls use a case here
select case( lpChkBox.index)
case 0
case 1
case 2
end select
next lpChkBok
This way you can loop thru groups-wise, one at a time.
I tried to do a single loop for all controls but was not possible to findout which control's reference i was getting: Like this:-
dim lpAnyCnt as Control
for each lpAnyCnt in me
' ???? How to determine if lpAnyCnt is a
' CheckBox or option Btn or Frame or anyother??
next lpAnyCnt
but wouldn't work.
Apparently, "For Each" is not supported by Frame control!!, though it is a container - gives Err 438. So only way out, is to loop for indiv. grps seperately.
I hope this helps.
Ravi Kiran
ps: You could also use member variables and set them in _click, _change events , so that just refer this variable to get the latest state!!
-
May 31st, 1999, 10:16 AM
#3
Re: option buttons/check boxes question
You might try looping through all the controls, checking which frame it's on and then checking for individual control types. Something like...
Dim c as Control
for Each c In me.Controls
If c.Container is me.Frame1 then
If TypeName(c) = "CheckBox" then
MsgBox "CheckBox: " & c.Name & " is " & IIf(c.Value, "Checked", "UnChecked")
ElseIf TypeName(c) = "OptionButton" then
MsgBox "OptionButton: " & c.Name & " is " & IIf(c.Value, "Checked", "UnChecked")
End If
End If
next
Hope this helps.
Brian
-
June 2nd, 1999, 02:31 AM
#4
Re: option buttons/check boxes question
Hi,
After poring over VB's help i found that 'Typeof' is better than Typename for controls. They both work the sameway, in the sense that
Msgbox typename(c) , in that sample code
shows correct types.
But an 'if' statement on TypeName is prone to "typographic" errors .. meaning , in the line
If TypeName(c) = "CheckBox" Then
we are checking with the string "CheckBox", so by mistake if you type "Checkbox", the 'if' condition will fail!!!
Instead if you use typeof, then as you type
if typeof c is... automatically, VB will
display the list which will contain all the possible types, from which we can choose 'CheckBox', and we cannot go wrong!.
So Typeof is to be used for Controls while Typename is to be used for data types line integer.
Ravi
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|