Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Iam using vb6 .Please can u write any code which can guide me that how to use Switch statement.I shall be so much thankfull if the code would be also execute.
For example i have four option buttons i have a choice to only select one .I think in this way Switch statement can be use..but how...?
Thnaks in advance.

I think you mean Select Case...it is VB's equivalent to C/C++'s switch statement.
IN C/C++
switch(aValue)
{
case 0:
DoSomething();
break;
case 1:
DoSomethingElse();
break;
}IN VB
Select Case(aValue)
Case 0: Call DoSomething()
Case 1: Call DoSomethingElse()
End Selectbut back to the option button.
when you put them on the form they will only allow one to be selected at a time so all you have to do is find out which one was selected.Let's say you have four option buttons:
Option1
Option2
Option3
Option4
And One Command Button:
Command1Then you do this:
Private Sub Command1_Click()
If Option1.Value Then
MsgBox "You Selected Option1", vbOKOnly, "Done"
ElseIf Option2.Value Then
MsgBox "You Selected Option2", vbOKOnly, "Done"
ElseIf Option3.Value Then
MsgBox "You Selected Option3", vbOKOnly, "Done"
ElseIf Option4.Value Then
MsgBox "You Selected Option4", vbOKOnly, "Done"
End If
End Sub

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |