Sub pr()
Dim a, b, s, p, r As Single
a = CSng(InputBox(" "))
b = CSng(InputBox(" "))
s = a + b
p = a * b
r = a - b
MsgBox s
MsgBox p
MsgBox r
End Sub
2 Visual Basic for Application.
. , - , (macro), . , , .
, , . , , . , -.
( ) , . , , .
, . VBA. VBA , . , . , - , , . , , , , .
, , VBA , , , .
Dim x, y, p As Single
x = CSng(InputBox(" "))
y = CSng(InputBox(" "))
p = (Abs(x) - Abs(y)) / (1 + Abs(x * y))
MsgBox p
End Sub
3 - .
- , , ; , , .
|
|
.
- , .
- , , .
, .
.
. , .. . , , , . (inheritance).
.
(encapsulation) - , (.. ) - .
.
- , , ( ).
, .
Sub pr()
Dim x, y, p, s As Single
x = CSng(InputBox(" "))
y = CSng(InputBox(" "))
s = (x + y) / 2
p = (x * y) / 2
MsgBox s
MsgBox p
End Sub
4 Visual Basic for Application. .
VBA // Visual Basic. VBA : , , , , .
VBA / . .
. , .
. , . : . . , . , . Enter.
VBA . . /. . , .
|
|
. , . : . , . : , .
/ . , .
Sub pr()
Dim x, y, p As Single
x = CSng(InputBox(" "))
y = CSng(InputBox(" "))
p = Sqr(x ^ 2 + y ^ 2)
MsgBox p
End Sub
5 Visual Basic for Application.
(syntax) , VBA. , VBA, (syntax errors), , , , .
, , VBA (parses) , . (parsing) VBA , , . VBA . (compiling) VBA , VBA .
VBA , (, VB , , ). , , VBA , VBA .
VBA, . , , (runtime errors) runtime . . , , , ..
Sub pr()
Dim l, r, s As Single
l = CSng(InputBox(" "))
r = l / 2 * 3.14
s = 2 * 3.14 * r ^ 2
MsgBox s
End Sub
6 Visual Basic for Application.
: Byte 1 0 255
Integer 2 -32768 32767
Long 4 -2147483648 2147483647
Single 4 . : -3.40282338 -1.401298-45. : 1.401298-45 3.40282338
Double 8 . : -1.79769313486232308 -4.94065645841247-324. : 4.94065645841247-324
|
|
Boolean 2 ; True () False ()
Date 8 . 1 100 31 9999 . 00:00:00 23:59:59
String ( ) 10 + . 0 () 2
String ( ) ( ) . () 65400
Variant 16 + 1 / Variant . Variant . ; , Double
Object 4 , VBA.
Sub pr()
Dim x, y As Single
x = CSng(InputBox(" "))
y = CSng(InputBox(" "))
If x > y Then
MsgBox x
End If
If y > x Then
MsgBox y
End If
End Sub
7 , Visual Basic for Application.
, , - . , , , .
. :
1. ;
2. , ;
3. , , ;
4. 255 ;
5. vba.
VBA. VBA .
.
. , VBA , Variant.
VBA . , .
, , . , , , . .
Dim, Public, Private Static. , Public, Private , Static .
: Dim < 1, 2,> As < > Dim < 1> As < 1>, < 2> As < 2>,< 3> As < 3>,
|
|
VBA, . .
, ; .
, , Const.
Sub pr()
Dim x, y As Single
x = CSng(InputBox(" "))
y = CSng(InputBox(" "))
If x < y Then
MsgBox x
End If
If y < x Then
MsgBox y
End If
End Sub
8 Visual Basic for Application.
+ N1 + N2 . N1 N2
N1 - N2 . N2 N1
* N1 * N2 . N1 N2
/ N1 / N2 . N1 N2
\ Nl \ N2 . N1 N2, , .
N1 ^ N2 . N1 N2.
(relational operators). , , ( ).
Boolean: True False. ,
^ 1 = 2 . True, El 2, False
< El < 2 , . True, El , 2, False
> El > 2 , . True, 1 2, False
> El > 2 , . True, 1 , 2, False
<> El <> 2 . True, 1 2, False
Sub pr()
Dim a, b, c As Single
a = CSng(InputBox(" "))
b = CSng(InputBox(" "))
c = CSng(InputBox(" "))
If (a > c) And (b > c) Then
a = 2 * a
b = 2 * b
c = 2 * c
Else
a = Abs(a)
b = Abs(b)
c = Abs(c)
End If
MsgBox a
MsgBox b
MsgBox c
End Sub
9 . .
VBA , , ,
And El And E2 . True, 1 2 True, False
Or El Or E2 . True, (1 2) True; False
Not Not El . True, 1 False; False, El True
Xor El Xor E2 . True, 1 2 ; False
Eqv El Eqv E2 . True, 1 , 2; False
Imp El Imp E2 . False, 1 True 2 False; True.
/
,
*, / ;
\ Mod
+, - ;
&
Like, =, , Is .
Not And Or Xor Eqv Imp
Sub pr()
Dim x, y, z As Single
x = CSng(InputBox(" "))
y = CSng(InputBox(" "))
If x > y Then
z = x - y
Else
z = y - x + 1
|
|
End If
MsgBox z
End Sub
10 Visual Basic for Application.
- , . , , , Main().
:
Sub _()
End Sub
, , . - , .. Public , .. Private.
End Sub .
, . . . , .
:
Public function _( )
_
End Function
. . . , , , - .
Sub pr()
Dim x, y, z As Single
x = CSng(InputBox(" "))
y = CSng(InputBox(" "))
If x > y Then
MsgBox x
Else
MsgBox x
MsgBox y
End If
End Sub
11 Visual Basic for Application.
Abs(N) N
Cos(N) N, N ,
Sin(N) ; N ,
Tan(N) ; N
Atn(N) N
Exp(N) , N ( () 2,718282)
Fix(N) N. Fix , . N , Fix , N
Int(N) N. Int , . N , Int , N
Log(N) N
Rnd(N) ; . Rnd VBA- Randomize
Sgn(N) ; . Rnd VBA- Randomize
Sqr(N) N. VBA , N
Sub pr()
Dim s, i As Integer
s = 0
For i = 1 To 10 Step 1
s = s + i
Next i
MsgBox s
End Sub
12 Visual Basic for Application.