Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

informatika_uchebnik_Makarova

.pdf
Скачиваний:
25
Добавлен:
09.04.2015
Размер:
19.85 Mб
Скачать

,

.

: 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- –

 

 

591

Sub Proc_A ()

 

 

 

Dim Sq as Single

 

Dim LL as Single

 

Dim HH as Single

 

LL=12

 

HH=23

 

SquarPr L:=LL; H:=HH; S:=Sq

 

 

 

 

 

 

,

 

:

End Sub

 

, .

:

Static <var> As <type>

, (

). .

.

, .

By Val

, .

19.19.

.

19.20.

 

 

Sub Proc_A ()

 

 

 

Dim Sq as Single

 

Dim LL as Single

 

Dim HH as Single

 

LL=12

 

HH=23

 

SquarPr L:=(LL); H:=(HH); S:=Sq

 

 

 

End Sub

 

VBA

VBA ,

. ,

, , . , VBA ( . 19.6)

( ).

VBA ,

Variant, String.

592

(String), :

;

;

.

VBA ,

– $.

, $:

1 9 . 6 . VBA

 

 

 

ABS() – ;

 

RND() – ;

 

INT() – ;

 

.

 

LCASE() – ;

 

UCASE() – ;

 

LEFT() – ;

 

RIGHT() – ;

 

LEN() – .

 

DATE() – ;

 

CDATE() – ;

 

() – ;

 

NOW() – (

 

);

 

DAY() – ;

 

MONTH() – ;

 

WEEKDAY() – ;

 

YEAR() – .

 

IN () – (

 

);

 

CSTR() – ;

 

CVAR() – VARIANT;

 

FORMAT() – , , ,

 

;

 

STRCOMP() – ;

 

VAL() – .

 

FILEATRR() – ;

 

FILEDATETIME() –

 

) ;

 

FILELEN() – ;

 

FREEFILE() –

 

.

 

 

VBA , , ,

( );

.

:

593

! – 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.

:

 

 

 

 

594

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.

 

 

595

Select CDemse

Select,

 

,

 

– Demse

CaseDemse21

 

Dem=21

,

 

 

Case Demse 22; 25; 28

 

 

Dem=31

,

 

 

Case Demse 45 To 48

, Cdemse

 

45 48

Dem=41

,

 

 

Case Else

 

 

 

Dem=51

 

End Case

Select

For-Next. ,

, , ( )

, .:

,

Next. ( ),

( )

.

, ,

Next.

Exit For.

, Next. ForNext .

19.25.

 

 

596

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

597

> 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.

:

.

:

.

598

, .

, .

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

 

 

 

599

:

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

 

600

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]