| |

VerySource

 Forgot password?
 Register
Search
View: 3200|Reply: 13

Novice solves grammar problems

[Copy link]

8

Threads

19

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-10-13 10:30:01
| Show all posts |Read mode
How does end if work in the conditional statement of VB? Under what circumstances is it combined with what purpose?
Sometimes an error pops up saying that else does not have an if. Why?
Take the following program:
Private Sub Command1_Click()
Dim s As Integer
s = Text1.Text
If s Mod 3 = 0 Then
     x = MsgBox("is a multiple of 3", vbOKOnly, "numerical judgment")
Else
     If s Mod 3 <> 0 Then
          x = MsgBox("Not a multiple of 3", vbOKOnly, "Value judgment")
     End If
End If
End Sub

Who is this end if used in conjunction with, and how can I change it if I don’t need it? Thank you! ! !
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-10-13 11:30:01
| Show all posts
The end if is matched with if. An if must have an end if.
such as:
if condition then
     Execute 1
else
     Execute 2
end if
Reply

Use magic Report

0

Threads

10

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-10-13 12:30:02
| Show all posts
The most basic grammar... Khan one

If condition Then
[statements]

[ElseIf condition-n Then
[elseifstatements] ...

[Else
[elsestatements]]

End If
Reply

Use magic Report

0

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-10-13 14:30:01
| Show all posts
Don't end if, it's okay to see if you feel tired
if a>b then statement 1: statement 2: statement 3: statement...
Reply

Use magic Report

8

Threads

19

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-10-13 14:45:01
| Show all posts
All in all, one IF corresponds to one END IF, right?
Thank you please sum up
Reply

Use magic Report

1

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-10-13 15:00:01
| Show all posts
Yes
If there is no end if
You can't debug it
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-10-13 15:45:01
| Show all posts
There must be an end if after the if
There can be an else or a new if statement in the middle, but the corresponding if statement must also have an end if

if ... then
...if ...then
   ...
   else
   ...if ... then
      ...
      end if
    end if
end if

Such a standardized code writing makes it easy to see which if corresponds to which END IF
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-10-13 16:00:02
| Show all posts
Very simple IF End if statements must appear in pairs, except for those written in one line.

1) (one line):
If ... then ...

2) (Need to pair)
if ....then
...
end if

3) Nesting
if ....then
if ....then
end if
end if
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-10-13 16:15:01
| Show all posts
Private Sub Command1_Click()
Dim s As Integer
s = Text1.Text
★If s Mod 3 = 0 Then
  X = MsgBox("is a multiple of 3", vbOKOnly, "numerical judgment")
Else
  ●If s Mod 3 <> 0 Then
    X = MsgBox("Not a multiple of 3", vbOKOnly, "Numerical judgment")
  ●End If
★End If
End Sub

★●Pairing appears
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-10-13 16:45:02
| Show all posts
Private Sub Command1_Click()
Dim s As Integer
s = Text1.Text
If s Mod 3 = 0 Then
     x = MsgBox("is a multiple of 3", vbOKOnly, "numerical judgment")
ElseIf s Mod 3 <> 0 Then
     x = MsgBox("Not a multiple of 3", vbOKOnly, "Value judgment")
End If
End Sub
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list