Solved

Is there an "Else if" in VB?

Posted on 2003-11-13
10
471 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

756 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