Computing.Net > Forums > Programming > How to use Switch statement in vb

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to use Switch statement in vb

Reply to Message Icon

Name: gardenair
Date: June 2, 2003 at 20:49:44 Pacific
OS: winxp
CPU/Ram: 900
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Chi Happens
Date: June 13, 2003 at 20:45:11 Pacific
Reply:

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 Select

but 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:
Command1

Then 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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: How to use Switch statement in vb

Switch statement in vb6..? www.computing.net/answers/programming/switch-statement-in-vb6/9080.html

How to manage print spooler in VB www.computing.net/answers/programming/how-to-manage-print-spooler-in-vb/5161.html

how to add a namespace to VB code www.computing.net/answers/programming/how-to-add-a-namespace-to-vb-code/6142.html