First, numerical operation:
1)
Dim A,b,c
A=inputbox ("A is:", "input radius")
B=inputbox ("B Yes:", "input radius")
C=a*2+b*2
Msgbox (c)
This input 1, 2 o'clock is 6
2)
Dim A,b,c
A=inputbox ("A is:", "input radius")
B=inputbox ("B Yes:", "input radius")
C= (a+b) "A+b" means 12.
Msgbox (c)
This input 1, 2 o'clock is 24
c= (int (a) +int (b)) * * With the same value as C=a*2+b*2
Second, the judgment structure:
(1) Boolean value (Boolean): Variable type
Dim A, B
A=true,b=false Note that true and "true" are not the same, "true" is a string, and true is a Boolean value and must not be confused.
Enter a number, if less than 100 output "error", if the output is greater than 100 "correct",
Dim a
A=inputbox ("Please enter a number greater than 100")
A=int (a) ' InputBox returns a string, we turn him into an integer
If A>100 Then
MsgBox ("correct")
Else
MsgBox ("error")
End If
(2) If statement: If....then Else End If
Dim a,b,c,d
A=inputbox ("A is:", "input radius")
B=inputbox ("B Yes:", "input radius")
D=inputbox ("Answer:", "Enter an Answer")
D=int (d)
' Here we take out the value of D, turn it into an integer, and put it back in the "D" box.
C=a*2+b*2
If D=c Then
Msgbox ("Hello smart")
Else
Msgbox ("Hello Pig's own problem is not!")
End If
(3) Logical operators: "and" and "or"
Dim A, B
A=inputbox ("Enter a number >10")
B=inputbox ("Enter another number >10")
A=int (a)
B=int (b)
If a>10 and b>10 then
MsgBox ("correct")
Else
MsgBox ("error")
End If
Dim A, B
A=inputbox ("Enter a number >10")
B=inputbox ("Enter another number >10")
A=int (a)
B=int (b)
If a>10 and b>10 then
MsgBox ("correct")
Else
MsgBox ("error")
End If
(4) Select Case
Select Case Variable Name
Case value
Statement
Case value
Statement
Case Else
Statement
End Select
Example: The three Arabic numerals converted into Chinese capital figures
Dim a
A=inputbox ("Enter a value for 1--3")
A=int (a) ' handling InputBox return string problem
Select Case A
Case 1
MsgBox ("one")
Case 2
MsgBox ("Ii.")
Case 3
MsgBox ("three")
Case Else
MsgBox ("Input error")
End Select
This program is written in If...elseif form as follows
Dim a
A=inputbox ("Please enter the value of 1--3")
A=int (a)
If A=1 Then
MsgBox ("one")
ElseIf a=2 Then
MsgBox ("Ii.")
ElseIf A=3 Then
MsgBox ("three")
Else
MsgBox ("Input error")
End If
Points:
1) InputBox returns a string, not a number, which must be converted into a a=int (a) Form.
2) There are only two values for bool variables: true,false
2.5) and both sides of the expression are true, returns True. The expression on either side of or has a true, which returns true
3) If statement format
4) format of the Select...case
Homework:
1) Use 3 bool values to store whether your 3 siblings are male (hint: sister1male=false)
2) Given a number, greater than 10 and less than 20 output "correct", otherwise output "error"
3) Input 12, or 15, output "correct", otherwise output "error"
4) Convert a positive integer within 5 to a larger number in China
5) Self-design a program, apply today's knowledge
1.
Dim a,b,c,d
A= "M"
b= "W"
C= "M"
D=inputbox ("Please enter a, B or C")
If d= "a" then
MsgBox (A)
ElseIf d= "B" then
MsgBox (b)
ElseIf d= "C" then
MsgBox (c)
Else
MsgBox ("#$%^&*")
End If
2.
A=inputbox ("Enter a number")
A=int (a)
If a>10 and a<20 then
MsgBox ("correct")
Else
MsgBox ("error")
End If
3.
A=inputbox ("Enter a number")
A=int (a)
If a=10 or a=20 then
MsgBox ("correct")
Else
MsgBox ("error")
End If
4.
A=inputbox ("Please enter a positive integer within 1-5")
A=int (a)
Select Case A
Case 1
MsgBox ("one")
Case 2
MsgBox ("Ii.")
Case 3
MsgBox ("three")
Case 4
MsgBox ("The restaurant")
Case Else
Mgsbox ("Input error")
End Select
VBS LEARNING: Process Control Statement judging structure