Solved

Is there an "Else if" in VB?

Posted on 2003-11-13
10
472 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy a row 12 75
VBA: Select SQL query based on a config Sheet v2 11 55
Copy a range from 1..n excel sheets to one destination sheet 2 72
Assign a value in Excel V-Basic 3 38
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 …
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.
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…
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…

739 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