Solved

Is there an "Else if" in VB?

Posted on 2003-11-13
10
468 Views
Last Modified: 2010-05-01
In C++ you can do something like:


If (x =1){
//do something
}
else if(x=2){
//something else
}
else if(x=3){
//something else
}
else{
//catch all
}

Is there a VB 6 equivalent?

Thanks
0
Comment
Question by:Igiwwa
  • 5
  • 4
10 Comments
 
LVL 11

Expert Comment

by:bingie
ID: 9743971
Yes

If (x = 1) Then
'do somthing
Else
If (x = 2) Then
'somthing else
Else
If (x = 3) Then
'somthing else
Else
'catch all
End If
End If
End If

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9743979
Sure, it is called "ElseIf", but you could just as well use a Case statement (that would be Switch in C++) for that example.

Anthony
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 25 total points
ID: 9743993
I believe this code matches closer to yours:

If x =1 Then
   //do something
ElseIf x=2 Then
   //something else
ElseIf x=3 Then
   //something else
Else
   //catch all
End If

Anthony
0
 

Author Comment

by:Igiwwa
ID: 9744000
Correct me if I am wrong, but I believe the code you gave me is equivalent to:

If (x =1){
    //do something
}
else{
     if(x=2){
          //something else
     }
     else{
          if(x=3){
               //something else
          }
         else{
              //catch all
          }
      }
}

which is not quite as elegant as the C++ way.  or maybe I am being foolish/picky
0
 

Author Comment

by:Igiwwa
ID: 9744004
(My previous comment was directed to bingie)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Igiwwa
ID: 9744019
Thanks acperkins.  I seem to remember you helping me in another question as well.  You are my go-to guy.

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9744057
>>I seem to remember you helping me in another question as well.<<
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20776495.html

Anthony
0
 

Author Comment

by:Igiwwa
ID: 9744076
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9744292
Sorry I do not do CGI.

Anthony
0
 

Author Comment

by:Igiwwa
ID: 9747925
I wish I didn't have to.  CGI/Perl is unpleasant to me.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now