| |

VerySource

 Forgot password?
 Register
Search
Author: ljeternity

Novice solves grammar problems

[Copy link]

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-10-13 17:00: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
x = MsgBox("Not a multiple of 3", vbOKOnly, "Value judgment")
End If
End Sub
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-10-13 17:15:01
| Show all posts
IF...
   ...
ELSE
   ...
END IF

If and end if appear in pairs, but sometimes only one result is needed. For example, in the above example, it is a multiple of 3 to give a prompt instead of no prompt. There is no else, and end if is not necessary, such as:

Dim s As Integer
s = Text1.Text
If s Mod 3 = 0 Then x = MsgBox("It is a multiple of 3", vbOKOnly, "Value judgment")
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-10-13 17:45:02
| Show all posts
In fact, one sentence of code will do
x = MsgBox(IIf(Val(Text1.Text) Mod 3, "not a multiple of 3", "is a multiple of 3"), vbOKOnly, "numerical judgment")
Reply

Use magic Report

8

Threads

19

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-10-13 18:00:01
| Show all posts
Thank you, everyone, I learn VC, now there is a thing that requires VB, I am very awkward to use it, so...
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