2
2.1 VBA
: VBA - -.
, . *.xls.
.
VBA. .
Windows-.
, , .
, Module1(Code). , , .
, , , , . .
. /.
, , . /UserForm, / .
2.2 -
, .
VBA.
Function , Function End Function . , . (, ).
.
: , , .
1 :
- Function;
- () ,
- .
2
3 End Function
:
[Private | Public] Function () As
( )
=
End Function
[Private | Public] ,
;
Function , , ;
( );
,
;
As () ,
;
;
, ;
|
|
End Function ,
.
:
1) ;
2) , .. _. , , . , .
1.
. , .
:
1 :
a, b, x Î R
: z Î R.
2 :
Function z(a, b, x)
z1 = Abs(Log(x) / Log(10)) - Sqr(Abs(Cos(x) - Exp(x)))
z2 = Abs(Tan(Abs(a * x - b)) / Sin(Abs(x)) + b)
z3 = Atn(z2 / Sqr(Abs(1 - z2 ^ 2)))
z = Log(Abs(z1 * z3))
End Function
.
3 :
- VBA MS Excel;
- 1 0,126;
- 2 0,842;
- 3 0,34;
- 4, ;
- →;
- ;
- z ;
- 1, 2, 3 .
2.
. , .
:
1 :
, Î Z
Î Z.
2 :
Function (, )
= * (1 + / 100)
End Function
3 , , , 25%, 1000. :
- 2 1000 ( );
- 2 25 ();
- 2, ;
- →;
-
- .
4 2, 2 .
2.3 -
Sub subroutine (), . , : , , . .
:
[Private | Public] Sub () As
( )
|
|
End Sub
2.4
2.4.1
VBA :
- : -Z, a-z;
- : -, -;
- 0-9;
- _;
- , (, , );
- , :
+,-,*,/,\,^,=,>,<,[,],(,),.,:,{,},,@,&;
- , : <=, >=, <>;
- , . , () Rem.
.
Rem
VBA (), .
, .
:
- ;
- () ;
- ;
- ( );
- ( );
- ( ).
2.4.2
, . .
, .
- , , , , .
:
1) , VBA;
2) ;
3) , . - , , , .. ;
4) 255 , VBA 31 ;
5) .
,
N, I, Number, ;
.
:
- , ;
- ;
- ( ), , .
2.4.3
, . . , .
VBA.
(, ), ().
:
, :
-
- .
. : , , , , .
:
Static | Public | Private | Dim < 1> [As < 1>], [< 2>[As < 2>]]
Dim (dimension ) , VBA, ;
(, VBA);
As () , VBA, ;
|
|
;
Private (), Public () , ;
Static () , , (, ) .
1.
Dim intName As Integer
, Variant.
. VBA :
Dim a, b As Long
b Long, Variant.
2.4.4
.
: , .
1 , , .
1.
Д, Program, 3.14, +
2
1.
-3, -485, 44, 0
3
:
- (): 0.1, -0.125;
- <><>: 7.32+00 (=7.32), 1.5-02 (=0.015).
().
. .
VBA VB. , Object Browser ( ).
2.
MsgBox " ", vbInformation
( vbInformation , ).
,
:
[Public/Private] Const <_> [As < >] = < >,
< > - , , .
, .
3.
Const PI As Single = 3.14
Pi
Const Firm =
2.4.5
.
.
, . , .
:
Dim VarName As String *
, , .
1.
Dim strMyName As String * 20 ( 20 )
VBA , , &. .
2.
strMy = Visual & Basic for Applications
2.4.6
() .
, , .
, , , .
:
|
|
- ( );
- , ( ),
- ( ). Public.
()- (, ), , . .
, , .
:
Dim , . , . .
Static Dim. : , .
Dim, Private (), , . ( ).
Public , .
2.4.7
. , .
:
() | ||
. . , .
. 1 VBA, .
1 -
Byte ( ) | 1 | 0255 | |||||
Boolean ( ) | 2 | TrueFalse | |||||
Integer ( ) | 2 | -3276832767 | |||||
Long Integer ( ) | 4 | +/-2.19 | |||||
( ) | |||||||
Single ( ) | 4 | -3.40282338-1.401298-45 1.401298-453.40282338 | |||||
Double ( ) | 8 | -1.7976313486232308-4.94065645841247-324 4.940656458412473241.7976313486232308 | |||||
String ( - ) | 1 | 1 65400 | |||||
String ( - ) | 10 + 1 | 0 | |||||
Object ( ) | 4 | ||||||
Variant | |||||||
Variant | 16 , 22 + 1 | ||||||
2.5 VBA
VBA :
- ;
- , VBA;
- ;
-
2.5.1
2 - VBA
Abs (x) | - |
Atn (x) | arctg (x) , |
Sin (x) | sin (x) , |
Cos (x) | cos (x) |
Tan (x) | tg (x) , |
Exp (x) | ex e, , |
Log (x) | ln (x) |
Sqr (x) | - |
Rnd (x) | [0,1). Randomize () ) |
Sgn (x) | +1, , -1, , 0, 0 |
Fix (x) | . |
Int (x) | . |
|
|
2.5.2 , VBA
3 - , VBA
Log(X)/Log(10) | lg() |
Atn | arcsin (x) , |
Atn | arccos (x) , |
Cos (x)/Sin (x) | ctg (x) - , |
π | Pi = 4 * Atn (1) |
2.5.3
, Format. Variant (String), , .
:
Format ( [, ( )])
, 4.
4 -
General Number | |
Currency | |
Fixed | |
Standard | |
Percent | |
Scientific | |
Yes/No | No, 0, Yes |
True/False | False, 0, True |
On/Off | Off, 0, On |
11 - ,
Immediate
2
, 5.
5 -
. . , , - , 0, , . . Debug.Print Format (1.2 ^2, ##.000) | |
# | . . , , - , #, , . . Debug.Print Format (1.2 ^2, ##.###) |
5
. () | . , . |
E+,E-, e+, e- | . . Debug.Print Format (sin(x) * exp(5), #.###e+##) |
% | . Debug.Print Format (0.5, #.%) ( 50 %) |
d,m,y | , , Data . Debug.Print Format (Now, dd/mm/yyyy) ( , 25.09.2005 |
/ | , , Data |
2.5.4
, 6.
6 -
Val (String) | , string, (Val . Value , String ) |
Str (number) | Variant (String), number. Str . |
CStr () | |
CInt () | Integer |
CSng () | Single |
2.6 ,
VBA .
, - . VBA, , , , , VBA. ,
Label1.Caption = Time
, , .
.
(Expression) , . .
: