,
.
: Sub Proc_B (Val1 As Single; Val2 As Date;... )
( Windows –
) .
, . ,
Optional.
19.18.
|
|
Sub SquarPr (L As Single; H As Single; |
SquarPr |
S As Single; Optional F) |
|
If IsMissing (F) Then F=100 |
VBA – IsMissing |
|
F, F |
|
, F |
|
100 (F Variant) |
S=L*H |
|
End Sub |
|
|
|
.
1- –
|
|
Sub Proc_A () |
|
Dim Sq as Single |
|
SquarPr 12; 23; Sq |
|
|
|
|
, |
|
|
|
Sq |
End Sub |
|
2- – ,
|
|
Sub Proc_A () |
|
|
|
Dim Sq as Single |
|
Dim LL as Single |
|
Dim HH as Single |
|
LL=12 |
|
HH=23 |
|
SquarPr LL HH Sq |
|
|
|
|
, |
|
Sq |
End Sub |
|
3- –
! – As <type>.
.
19.21.
|
|
Sub Proc_A () |
|
|
|
Dim S as Single |
|
Dim LL as Single |
|
Dim HH as Single |
|
LL=12 |
|
HH=23 |
|
S=Sq(LL;H)/2+1200 |
Sq |
End Sub |
|
Function Sq (H As Single; L As Single As Single) |
Sq |
Sq=H*L |
Sq |
|
|
End Function |
|
VBA
, : ,
, .
If. :
.
:
If < > Then < >
( ). (True),
, Then; (False),
If .
– , :
).
.
19.22.
If MaxPrice > 23,000.00$ Then MaxPrice=23,500.00$
If Student_Card(100).FullName Like " *" Then number=Student_Card(100).Group
VBA.
:
Not |
|
r |
" " |
And |
" " |
Imp |
|
Or |
" " |
Eqv |
|
. 1 ,
1, 2 .
,
Else, , – , End If.
19.23. If
|
|
If AvgPrice > 12000 Then |
1 |
DiffPrice=Full(234, 45600) |
1 , |
ElseIf AvgPrice > 24000 Then |
2 |
DiffPrice=Full( 12000, 45000) |
2 , |
ElseIf AvgPrice > 36000 Then |
3 |
DiffPrice=Full(24000, 50000) |
3 , |
Else |
1 – 3 , |
DiffPrice=Full(36000, 70000) |
|
End If |
If |
Select Case. ,
( ):
: Case 45 Case 3, 4, 5, Case 5 12.
, Else, Else
, , End Case.
19.24.
Sub stickRandom() |
|
Dim numrows As Integer; numcols As Integer |
|
Dim therow As Integer; thecol As Integer |
|
numrows = Selection.Rows.Count |
|
numcols = Selection.Columns.Count |
|
|
|
Debug. Print numrows; numcols |
|
|
|
Randomize |
|
Debug.Print Rnd For therow = 1 To numrows |
|
For thecol = 1 To numcols |
|
Selection. Cells(therow; thecol).Value = Rnd |
|
|
|
|
Selection – |
|
Cells – |
|
|
|
Value – " " |
Next thecol |
|
Next therow |
|
End Sub |
|
Do-Loop. , Do – , Loop – ;
4 :
1) True
Do While < >
> Exit Do
> Loop
, >.
– 0. Exit Do Loop –
.
2) True
Do
> Exit Do
> Loop While < >
, >. 3) False
Do Until < >
> Exit Do
> Loop
Until , , > .
– 0. 4) False
Do
> Exit Do
> Loop Until < >
, , .
– 1.
19.26.
|
|
Option Explicit |
|
|
|
Sub Do_Rnd() |
|
Dim a As Single |
|
Dim i As Integer, |
|
Randomize |
|
Do While True |
Do. – |
|
|
a=Rnd |
|
Debug.Print a |
|
If a > 0.99 Then Exit Do |
– |
Loop |
|
End Sub |
|
|
|
While-Wend. Do While-Loop.
(Exit Do ), .
While < >
> Wend
For Each. , .
( ) . ,
. – .
For Each < > In < >
> Exit For
>
< > Variant, < > – .
Exit For.
VBA :
.
– ,
, ANSI.
:
.
:
.
, .
, .
FileFree,
( 1-511).
:
Open < > [For < >] [Access < >] [< >] As [#] [L n=< >]
< > |
- , ; |
< > |
- |
: |
Append |
|
|
Binary |
|
|
Input |
|
|
Output |
|
|
Random |
|
; |
> - : |
Read |
|
|
Write |
|
|
Read Write |
|
; |
> |
- |
: |
Shared |
|
|
Lock Read |
|
|
Lock Write |
|
|
Lock Read Write |
|
; |
|
- |
; |
> |
- |
, – 32767 |
|
|
. (512 |
|
|
). |
;
. Binary, Input, Random
, ; Append, Output
.
19.27.
|
|
Open "FILE" For Input As #1 |
|
Open "FILE" For Binary Access |
|
Write As #1 |
|
Type Record Define userdefined type |
|
ID As Integer |
|
Name As String * 20 |
|
End Type |
|
Dim MyRecord As Record |
|
Open "FILE" For Random As #1 |
. |
Len = Len(MyRecord) |
|
|
Len |
Open "FILE" For Output Shared As #1 |
|
|
( |
|
) |
Open "FILE" For Binary Access |
, |
Read Lock Read As #1 |
|
|
|
:
Close [< >]
, .
19.28.
Close #1; #2; #4 |
' , 1,2,4 |
Close |
' |
. 1.
– :
Print # ; [< >]
:
[{Spc(n) | Tab[(n)]}] [< >] [charpos]
Spc(n) |
- ; |
Tab(n) |
- ; |
< > - ; |
charpos |
- . ; |
|
( ). |
,
Print.
19.29.
|
|
Open "FILE" For Output As #1 |
|
Print # 1 ; " " |
|
Print #1; |
|
Print #1; " "; Tab ; " " |
|
Print #1; " " ; " " ; " " |
|
Print #l;Spc(5); " " |
5 |
Print #l;Tab(10); " " |
10 |
MyBool = False |
|
MyDate = #February 12, 1969# |
|
|
MyNull = Null |
|
MyError = CVErr(32767) |
|
Print #1; MyBool; |
|
Print # 1; MyDate; " " |
|
Print # 1 ; MyNull; " " |
|
Print #1 ; My Error; " " |
|
Close #1 |
|