Solved

Is there an "Else if" in VB?

Posted on 2003-11-13
10
465 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
(My previous comment was directed to bingie)
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:Igiwwa
Comment Utility
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
Comment Utility
>>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
Comment Utility
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Sorry I do not do CGI.

Anthony
0
 

Author Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

771 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

15 Experts available now in Live!

Get 1:1 Help Now