vb if and ElseIf

Source: Internet
Author: User

The use of if and ElseIf in VB is:

If...then...elseif...then...else...endif

Remember to do not add a colon after then, add a colon to the else without an if error, because the addition of a colon means that if the statement is only executed then, even if the execution is finished, so the following

1 SubTest ()2 DimI as Integer3 DimJ as Integer4 Dima5  fori =1  to 2:6Debug.Print ("This is the first"&Str(i) &"Secondary Cycle")7A =InputBox("Please enter")8     9     IfA ="1"  ThenTen         MsgBox("perform 1") OneDebug.Print ("perform 1") A     ElseIfA =" -"  Then -         MsgBox("Perform 2") -Debug.Print ("Perform 2") the     ElseIfA =" +"  Then -         MsgBox("Perform 3") -Debug.Print ("Perform 3") -     ElseIfA =" -"  Then +         MsgBox("Perform 4") -Debug.Print ("Perform 4") +     ElseIfA =" -"  Then A         MsgBox("Perform 5") atDebug.Print ("Perform 5") -     Else: -         MsgBox("Nothing has been done .") -Debug.Print ("Nothing has been done .") -     End If - NextI in End Sub

If you add a colon, you can only be an if:

1 SubTest ()2 DimI as Integer3 DimJ as Integer4 Dima5  fori =1  to 2:6Debug.Print ("This is the first"&Str(i) &"Secondary Cycle")7A =InputBox("Please enter")8     9     IfA ="1"  Then:Ten         MsgBox("perform 1") OneDebug.Print ("perform 1") A  - NextI - End Sub

If this is the following, you will get an error:

1 SubTest ()2 DimI as Integer3 DimJ as Integer4 Dima5  fori =1  to 2:6Debug.Print ("This is the first"&Str(i) &"Secondary Cycle")7A =InputBox("Please enter")8     9     IfA ="1"  Then:Ten         MsgBox("perform 1") OneDebug.Print ("perform 1") A     ElseIfA ="2"  Then: -         MsgBox("Perform 2") - NextI the End Sub

vb if and ElseIf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.