.


:




:

































 

 

 

 


VBA (visual Basic for Application)




( 2)

081100.62

 

 

2013


:

 

: 2

 

 

: . ..

..

 

28 2013 .

 

 

____ ___________2013 .

 

 

 

. 4

1 VBA (VISUAL BASIC FOR APPLICATION) 5

2 MS ACCESS. 15

3 - .. 29

.. 39

 

 


 

, , .

, .

:

- , , , , ;

- , , .

:

- ;

- ;

- .

:

- .

. : VBA (Visual Basic for Application), Microsoft Access, - .


VBA (VISUAL BASIC FOR APPLICATION)

 

1

: VBA MS Excel, (, , .). , MS Excel, , .

, .

:

1 MS Excel VB. / / Visual Basic [Alt+F11].

2 , Insert→Module.

3 Insert→Procedure, Add Procedure ( 1).

 

 

1 Add Procedure

 

4 Add Procedure Function. <>.

5 , , a b:

 

Public Function (a, b)

= (a^2 + b^2) ^ (1 / 2)

End Function

 

^ .

1 VB . 1, 1 1 , b, ; 2 2 , 2 , ( 2).

2 , . / / , , , ( 3).

 

 

2

 

 

3

 

, y = sin(πx)e−2x .

:

1 VB Y :

 

Public Function Y(x)

Y = Sin(Application.Pi*x)*Exp(-2*x)

End Function

 

Pi, π. VBA, Application.Pi.

2 1 1 y, 2 3 , , -0,5 -0,4 , 4:12.

3 2 =Y(A2) 3:12.

4 2:12 ( ) ( 4).

 

 

4

2

.

: VBA :

1 InputBox ( ):

InputBox ( , [ ]).

2 MsgBox :

MsgBox , [ + ], [ ],

+ , .

, .

:

1 MS Excel VB.

2 , Insert→Module.

3 Insert→Procedure, Add Procedure .

4 Add Procedure Pythagor Sub ( 5). <>. , , , .

 

 

5 Add Procedure

 

5 . .

 

Public Sub Pythagor()

a = InputBox( a)

b = InputBox( b)

c = (a ^ 2 + b ^2) ^ (1 / 2)

MsgBox ( & c)

End Sub

 

& .

6 . ( 6).

 

6

 

VBA, Run / Run Sub/UserForm. Run. F5 .

3

.

: VBA , . UserForm. MS Excel VB Insert→UserForm. ( 7). Toolbox, , ( , ). , View→ToolBox.

(Properties) . , View→Properties Window, F4.

 

7

. .

:

1 , . , , , .

2 VB Insert→UserForm .

3 , , Properties Caption ( , .., .. , ) .

4 CommandButton (), TextBox ( ) Label (, ).

5 , . Name. TextBox1 a, TexxtBox2 b, TextBox3 c.

6 Label1 Caption a=, Label2 b=, Label3 c=, CommandButton1 ( 8).

7 CommandButton1. .

8 :

 

Private Sub CommandButton1_Click()

c.Text = (a.Text, b.Text)

End Sub

 

Text , .

 

 

8

 

9 1 . , / / . , .

10 VB, / / . 1 :

 

Private Sub CommandButton1_Click()

UserForm1.Show

End Sub

 

( ). VB, , Run→Run Sub/UserForm F5.

 

4

.

 

- If/Then/Else.

, , If/Then/Else - If Then 1 [Else 2].

, 1, 2.

, If/Then/Else:

If Then

1

[Else

2]

End If

 

, , , 2.

.

, . :

 

If 1 Then

1

[ElseIf 2 Then

2]

.....................

[Else

]

End If

 

1 , 1, 2. , 2 .. , . ElseIf.

(, a > 5), (, a > 5 b > 2). And ( ), Or( ), Not ( ).

: 20 % , 200 000 ., 15 % , 100 000 200 000 ., 10 % - 50 000 ., 12 % - . .

VBA (Insert Module; Insert Procedure; Function). . , ( S), , .

 

Public Function (S)

If S > 200000 Then

= S + S * 0.2

ElseIf S <= 200000 And S > 100000 Then

= S + S * 0.15

ElseIf S < 50000 Then

= S + S * 0.1

Else

= S + S * 0.12

End If

End Function

 

Excel .

9

 

VBA Excel : , : 100 10 . ; 100 1000 7 . ; 1000 5 . . Excel 50, 150, 500, 900, 1000, 1200 1500 .






:


: 2016-12-18; !; : 815 |


:

:

- , .
==> ...

1983 - | 1772 -


© 2015-2024 lektsii.org - -

: 0.071 .