1. , Visual Basic,...10 Visual Basic "visual" ˆ "basic" ˆ BASIC (Beginner's All-purpose Symbolic...

81
1 () 1. , , Visual Basic,

Transcript of 1. , Visual Basic,...10 Visual Basic "visual" ˆ "basic" ˆ BASIC (Beginner's All-purpose Symbolic...

1

�����������(�������)

��1. �����������, ��������������, Visual Basic, ������� ������

�� ����������

2

�����������

� ����: ����������� (���������2012/2013)

� ���������: ���. �-� ���� ����������� ������: 4 ���� ������ ������: ���� 12-14 � �������10-12

3

���������

� �������

� ����

� ��������� ��� � ������������ ��

�������� �� ������

http://www.institutzamatematika.com/index.php/KOMPJUTERSKI_PRAKTIKUM_2

4

������� ������

� ��������

� 2 ����������� ������� ������ �/��� ����

(���������)

5

������� ����������

� �����90% �� �������� �� ���������������� ������� �������� �

����, �����90% �� ����������������

� �����10% �� �������� ������������������� ���� ��, �����90% �� ���� ���!�� �� �������

6

�������?

7

"���� ����������?

� ��������� ������, ����� ��������� �������

� ����������� ����� ���������� ��

����������� ������� ����� ������

� ������������ ���������: ��������� ��� � ��� ��� �� �� ������ � ��

��������� ����� ���������� ���

������

8

#��� $���������� ������������?

� �������� ���� �� ������ ���������� ��� ��

���������� ������������ ����� �� ������

� �������� � ��������� ��������� �� ��

- ������� �� ��(��������� ���„�������“���������, 1=„on“ � 0=„off“)

- low level �� ��� (�������������� �������� ������������, Assembler, BAL, …)

- high level �� ��� (��� �������� ���������������, Pascal, FORTRAN, COBOL, C, C++, Prolog, Java, Visual Basic, …)

9

#��� $���������� ������������?

� �������� �������� ������� ���� ��

��������� ����������� ������� ��

������������������ �������� �����

� �� � ��� �������� � ���� �� � ���

��� ������ �������������������

������, �������� �� � ����� ���������� ����������������

10

Visual Basic

� "visual" � ������� �� ����������������� �� ������ ��� ��� �� ����

����������

� "basic" � ������� �� ����������������BASIC (Beginner's All-purpose Symbolic Instruction Code), ���������������������� ������� ���������� ��

���������

� Visual Basic (VB) Windows ���������

11

Visual Basic

� VB ����� ������ ���� ���������������� �� ���������� ������, ������� � ��������� �� Windows��������� (��������������, �������� �� ����� ��� $����������������� �� ��� ������� �������)

� ��������� ������� �� VB � �������VB-�����(�������� �� $������)

� (����� 1. VB-�����: �������� ���������� � �������� �����)

12

%������ ������ �� ������������

������� �� �������� �� ������ ��������

� ����� � �� ��������(�������� ���������, ��� �� � ������ �� �������, ������� ��������� �� ������, ������ �������� �� �������� ������� �!�������

��������������)� �� ������� (������� �� ������ ���������, ���!�� �� ������� ���� �� ���������������� ��� �� ��������������-���������)

13

%������ ������ �� ������������

� ������� (������� �� ��������������������� �������������� �� �������)

� ������ � �������� �� ������ (�������� ����������� �� ������ (bug) �� ������������ �������, ������ ���� ��������� ����������� ���� ��� �������� �� ������)

� ������������ (����������� �� ���������������������� ������ ���������, ���������� �����, ���������� ��� ����� ��������� ����� �� � ������� ������)

14

������� �� ����� ������

����������

� �������� �� ������� �� ��������, �������, $������

� ������� �� $������� � ����� ������������ ��

�����������

� $��������� � ��������� (indentation) �������

� �������� � ������������

� ��������� �� �������� ����� ����������

� (���������� �� ��� ����� ���������������� �� ����� 1.)

15

"�������

� ��������� ������, ������ ��� ��� � ������ �� ������, � �� ��������� ����� �������������

� ������������ ������ �� ������� ��

��������� ��������� ������ ������ ����������

�� ��� ��� ������ �� ������������ �� ������

� ����������������Visual Basic �� ������ �� ������������������������� �����BASIC �������� ��������, ������������ ��������� �� �������, ��� �� ���� �������� ������ ��Windows ��������

16

"�������

� ���� �� �������� ������ ��

������������ + �������� ������������������Visual Basic + ����������� ���������� = ����� ���������� (�����)

1

�����������(�������)

��2. ���������

2

����������� ���...

� ������������ ������ �� �������

�� ��������� ��������� ������ ������

���������� �� ��� ��� ������ ��

��������� ��� �� ������

� ������������ ������ ��

������������ ���������� �.. ������� �� ������ �� �������, ������ �� ������� ���� ��������

���������� ��� �� ������� ������� -���������

3

������ ������������� �� ����������

� ��������� ������ ���� ��������, ������ ������� ����������, ���� �������� ������������ � ����� � ������ ��������

� ������ ������������� �� ����������:- ����������� ���� �� ��� ������ ����- ������ �� ����� ������� �� ���

����������� ������ ���� �� ��� ���������

�����

- ����� ��������� ��� �� ��� ��������� �������� ������

4

������ ������������� �� ����������

- ��� �� ������� ������������������ ������� ����� �����

- ���������� �� ����� �������� �� ����� �������� �� �������� ���

� ��� �� �� ������� ������� ��

�������� �������� ������

- ����������� ���� �� ��� �������� ��������

5

������������ ���� �� �������

� ! ��������� ��� „�����“ ����������������. !� ����, �������

- ������ ������ (� ����� �������������� ����� ������� - Halting Problem: "���������� � ����� ����� �������, �� ������ ���� ���������� ����� � ������ �������� ��� ������ ��������.)

- „����“ ������ (�� ���������� �������������� �� �� �� ��� ������� - Traveling Salesmen Problem)

- ������ �� ��� � ��� ���������������� ��� (������� ������ - K-server problem)

6

#��� �� ������������ �� ����������

� �������� � ������� (�������� ���������, ���������� �� ��� ����������� �� �������)

� �������� � ����� � �������

� �������� � ������ ���� �������

�� ������ �� ������� (����� ����������� ����)

� ��������� � ���������� (������������ ��� ���� ���)

7

#��� �� ������������ �� ����������

� ��������� � ���������� (������� ������������)

� ��������� � �� ������� � ����������

(����������� �� ���� �������� ������� �� �������������� ������ ��������)

� ������ � ���������� (� ���������������� � ���������� �������� ��

����������)� ������� � ���������� (������������������� �� �������, � ������� �� ��������� ������ �� ��������� �����)

8

$�� �������� �� ������������ ������

� ��������� � ����� (������������ ���������� � ��)

� ������ � ����� (� �������� ��/������ � � ������ �������

����������� ������� �� ���������)� �������� � ����� (loops) (��������� ����������� �� ������

����������)

9

%�����������

&������ ��� � �������� �� ��������������

- ���������� ������� ������- ������� (�������� ����)- ���/����- �������� (���������� ������ � �������� �������)- ������ (������ ��� ����� - „��“ ��� „�“)- ���������� �������� ������� �����

� ( ���� �� ������������ �� ������� ������� 1. P � V � ����� - ���� ���� ������ ��������� � �����)

10

����� ���

� ���� ��� ������� ������ �� ����������

���������� ���, ������������ �� �����������' �� � ������� �� ������ �� ������

�� �������, ����������� �� �� �������������������� �����

� �������� �� ���� �����

- ������������������������- ����� � ����� ������ �� ����������� �����

� ( ���� �� ���� ����� ������� ������� 1. P � V � ����� - ���� ���� ������ ��������� � �����)

11

$���� �� ���������

� �������� ��������� (� ���������� �� ��� ��������� ���

�������)� �������� ��������� (�������� ���� ������� ��������'� � �� ��)

� ( ���� �� �������� ���������������� �� ����� 2. ������ � ���� 30 ��������� ����� - �������� ���� �� �������� � �����)

1

�����������(�������)

��3. ������ �� ������������ ��Visual Basic

2

��������������...

� ����������e ������ ���� ������������������ ���� ���� ������� �������� ��������� ������� ��������

� ��������� �� ���������� ������ ��������� �� ����������������-�������� ��������� ������� �������� �� �������

� ��������� �� ��������������������� �������� �� ����� �������� �������

3

������� ����� �� �������

� ����� ������� ������������ ��� ��� �� ������������ Visual Basic �:

- ��� ��- � �������� ���� (Strings)

� ��������� � ������������:- ��������� (� �� �������������� �������,

��������� ��������� �� ���� ��������� �� Const constname =expression, ��� expression � ������ �����������, ���������� ��� ������� ������ )

- ���� ����� (��� �� �� ���������������������)

� (����������� �� ����������� �� ���� ��������� ����������� Form_Activate)

4

���������

� ���� ������� �� �� � ������� �� ��������� �� ���������� �� ��������.- �� �� ������ ���������� �� ����������� ����������1 � ����������255 ��������, - ���� �� ����� �� �����, - ��� �� ������ �����, ����� � ������������ ("_"), - Visual Basic � ���� ������� � ������ ������� ����� �� ���� �� ����������(������� brojnacifri � brojNaCifri � �������������� ���� ��������)

5

���������

- � ����� �� ���� ���������� �����(�� "=“) 1) var = num (�� ���������� var � � ����������������� �������num, �. �=3)2) var = str (�� ���������� var � � ������� ������������������str, �. ime="Ana")3) var2 = var1 (�� ���������� var2 � � ��������������� ������������ var1, �. a=3:b=a, �������� ������������ b ���� �������3)4) var = expression (��� � ������� �������� ���������expression, � ���� �������� ��������������� �� ���������� var, �. a=3:b=a^2, �������� ������������ b ���� �������9)

� (����������� �� ���������� �� ��������� ���������� ��������� Form_Activate)

6

��������� �� ��������

Dim var As type� var �� ������ �������� type ����������� �������� � �������� �� ����������������, ��� ������General Declarations �� �� ���� �� ���������� ���������

� ����������� � �������� �� ����������������� ��������� (�������������!������������� �����������)

� ��� ����� �������� � ���������� � ������ ������Variant

7

"���� �� �������� (type)Integer - ��� ����� �� -32768 �� 32767Long - ��� ����� �� -2147483648 �� 2147483647Single - ������0, ������ ��1.40129#10-45 �� 3.40283#1038 ����������7 �������� ����� � �������� �� ��� �����

Double - ������0, ������ ��4.9406520#10-324 ��1.797693134862316#10308 �� ��������17 �������� ����� ��������� �� ��� �����

String - ������� ��0 �� 32767 ����� (���� �������, ���� ������ ����)

Boolean - �� �������� True ��� FalseCurrency - ����� �� -922337203658477.5808 ��

922337203658477.5807 �� ��������4 ��. ����Date - ����� ��� ������. ������ ��1 ���.100 �� 31 ��. 9999Byte - ����� ��0 �� 255Variant - ��� ����� �� �������

8

$��������� ������ �

������ �� ���������

� ������� �� ����

+ (�������)- (������) * (�����)/ (���)

� �������� �� ����

^ (�������)\ (��������� ���) Mod (��������� ���)& (������ ���������)

("������ �� ������� �� Immediate Window)

9

���������� ��������� ��

����������� ������

( ) - �������� �� ������� ��� � �������^ - ������� �� ��� ����� � �������- - ���������� �� ����������� ����* / - ������� � ����� � ������\ - ����������� ��� ���Mod - ����������� ��� ����+ - - ��������� � �������� � ������� ("������ �� ����������� ��������� ������������� ������� �� Immediate Window)

10

%������ ������ � �������

������

� ������� � ����

= (������ ��)<> (�������� ��)< (����� ��)> (������ ��)<= (����� ��� ������ ��)>= (������ ��� ������ ��)

� ������� �� ����

Not (�)And (�)Or (���)Xor (���...���)

("������ �� �������� ������ � ����� �� Immediate Window)

11

&������� �������

� Visual Basic ��� ��! ���������� ������� (built-in functions).

� '���� �������� ������� �� ����������� �� ����� ����� ���!� ��� ��� ����� ����.

� (����� �������� � �������� ���������� �� ���� �������� ��� ���������.

� ��� ����� ������ � ��� ��� ����������������� ����.

� &������� ������� �� Visual Basic: Abs, Atn, Cos, Exp, Fix, Int, Log, Rnd, Round, Sgn, Sin, Sqr, Tan

� ("������ �� ��������� ������� �� Immediate Window)

12

(��/ ����

� ������InputBox �������(��������� ����������� ��������)

var=InputBox(prompt) ��� var=Val(InputBox(prompt))� ������ Print � ��

object.Print [outputlist]- ������� ������ �� �������� Spc(n) �Tab(n) � �������� , (������) � ; (����� ������)

� ������ MsgBox �������(�� �� � �������������� �� ����������)

MsgBox(prompt)� ("������ �� �������� Print ����������������� Form_Activate)

13

)������ ��������� If…Then

- ����������If cond1 Then

statements1ElseIf cond2 Then

statements2…ElseIf cond(n) Then

statements(n)Else

statements(n+1)End If

- ��������� �� ��� � �� ���������������� ���� ������� � ��������

If cond1 ThenIf cond2 Then

statementsEnd If

End If��� �� � ����� ����

If cond1 And cond2 Thenstatements

End If

- ���������If cond Then statement1 Else statement2

("������ �� ��������������� ��������� Form_Activate)

14

)������ ��������� Select…Case

- ��� ��������� ��������� �� �������� If…Then- ������� ����������������� �� � � ������(selector) ������ �� ��� �������� ��� �������������

- ��������� ����� (valuelist) ���� �� ������� ������������ ������ ��� ��� ��! �������� ������ �� ������(�. 3,4,5 ��� 3 To 5 ��� Is <= 5)

Select Case selectorCase valuelist1

statements1…Case valuelist(n)

statements(n)Case Else

statements(n+1)End Select

15

*�����For…Next

- ���� � ��� ����� �������� ���� �� � ������ ��� ������������

For counter=start To end [Step step]statements

Next counter- ��������(counter) ����� �������� ��������, start ������� �������, � end �������� ��������� ��������, step ��������� �������������� �������� �� ������������ �� ��������(��� �� ��� � �������)

- ���������� ����� �� �������� �� ������������� ����������, ��� �� ���� �� ������������

- �������� ��������� �� ���� For…Next ������, �� ��� �� ��� ��������� � ������������ �� �������

- ���������������������� Exit For

16

*�����Do…Loop

1) Do While condstatements

Loop2) Do

statementsLoop While cond

3) Do Until condstatements

Loop4) Do

statementsLoop Until cond

- �������� ���� �������� � ����� ���������������� ������ � ���� �������������

- ������������ ������ �� Do…Loop ��������

- ���������������������� Exit Do- �������� ��������� �� ���� ������Do…Loop- �������� �� �������������� Ctrl+Break ��� Break ������������� �� ����������

(���� �3. �� �� ����� ������������� n ������� ��� ��.)

17

+���� �� ������������

� ����������� ����� (� �����������smart editor ���� � ��������)�. Primt, 2ka=2, a=b+

� ����� �� ��� �� ��������� �� ���������(run-time errors) - ��� �� ������ �������������� �������� ��� ����������������������� ������ ������ ������

�. varInv=1/var (��� �������� �� var 0)� ������� ����� (���� ��������� � ������ ��������� � ������ �� ������)�. av = min + max / 2

� �������� �� ������ On Error Go To line

18

'����� ...

� �� ������� �� ������������ �� Visual Basic �� ������ �:

- � �������� ���� (Strings)- ���� ����� ����� (Arrays)

� ��������� � ������ �� �������:- ������ ������ ���������������� �� Visual Basic

� ������ �� ���������� ! ������������ ��: - ��������� Visual Basic- �������� ���� �� �� Visual Basic

1

�����������(�������)

��4. ��������� ���� (Strings)

2

��������������...

� ����� ������� ��� �� ������� ��� ��� �� ��

���������� Visual Basic � ����� � ������������� (Strings)

� �������� � ������������

- ��������� (Const constname =expression) �- �������� (Dim var As type)

� ������ �������� ���������� ���������

���� String �� ���� ����������������� ��0 ��32767 ����� (���� �������, ���� � ����� ����)

� ��������� �� ��������� ������ (&)

3

������ ��������� � ������ ������

� ������ �������(������) ���� ����������(��������� ����) ���� � ������ ���� ��������

- ����� �� ��������� �: ������, �������, �����, �����, �������� �����, �����, ������� �����

� ������ �� ������������� ����������� ������ �� ������� (&) ���� ���� ���������������

� ����� ������ ��� ��� ������ ("") - ������ ����� ��������� ������ ��������, ���� 0 ������������ ��������

4

ASCII ��������� �������� (0-255)

� ������� Asc (�� ���� ASCII ������� ���������), Chr (�� ���� �������������������� �� ASCII �����)

� ������� ASCII ������: 48-57 (����� 0-9), 65-90 (����� �����), 97-122 (���� �����), 32 (���������), 34 (���������)

� �������� �� ��������� �� �������� ������

=, <, >, <=, >=, <> (� ���������ASCII ��������� ��������� �����, �������, ���.)

� (������� �� ASCII ������� � ������������� Immediate Window)

5

������� ������� �� ���������

� ������ �������

- Left, Mid, Right (���������� �������� ���� �����������)- UCase, LCase (������� �� �����, ����������� �����)- Trim, LTrim, RTrim (����������� �� ���������) - String (����������� ���������������)- Str (������� �� ������) - Format (���������� �� ������)

6

������� ������� �� ���������

� ������� ������� �� ������ ��������

- Len (������� �� ������)- InStr (������� �� �������� �� ������)

� (������� �� �������� ������� ����������� �� Immediate Window)

� (������ 4. ������ ����� �� ��������������������� ���.)

� (������ 5. ������ ����������������������.)

1

�����������(�������)

��5. ���� ���������� (Arrays)

2

��������������...

� �������� (��� ����� ��������) �� �� � ������� �� �� ������� ������������ �� ��������

� �� Dim var As type � �������� ���������������� (type = Integer, Long, Single, Double, String Boolean, Currency, Date, Byte, Variant)

� ���� �� ���������� ���� �� ������� �����, � ��� �� ������ ���� �����, ������ � ������� ����� ("_")

3

���� ���������� -���������, ���������� ���� ���������� �������� ��������������� �������

� � ��������:- ���� �� ������, - ������ ��������, - ���������� �- �������� �������� � ����� ��������

� ��������� �� ���� ���������� �� �������������:

Dim arrayName(n) As varTypeDim arrayName(m To n) As varitype (�� m<=n)

4

���� ���������� -���������, ���������� ���. (���������������)

Dim �(3) As Integer, �� ������ Integer ��������� A(0), A(1), A(2), A(3)Dim �(1 To 3) As Integer, �� ������ Integer ��������� A(1), A(2), A(3)

� ���. (���������������) Dim B(1 To 3, 2 To 4) As Integer, �� ������Integer ��������� B(1,2), B(1,3), B(1,4),B(2,2), B(2,3), B(2,4), B(3,2), B(3,3), B(3,4)

5

���� ���������� -���������, ���������� ��������� �� ���� ���������� �� ��������������� (�������� ���� ����������):1) ��������� ���� �� ��������� ����������� ������ � ������ ��������:

Dim arrayName() As varType2) � ���� � ���� ����������� �� ���������� �������� � �������� �������� � ����� ��������:

ReDim arrayName(m1 To n1, …, mk To nk) As varType3) � ������������ �� �� � ��������� ���������������:

ReDim Preserve arrayName(m1 To n1, …, mk To nk) As varType

6

����� �� ����� ����������

� �� ������ �� ����� ������ ��������

������� (����� �� �����, ��������������, ���� �����)

� �������������������������

(���������� �� ������ ��������)

� � ���������� ������ ��������

��������, ��������, ������ ���������

7

������

� ���7. ���������������������������� �������� ������ ��

����������.� ���8. ����� �� ������������������������n ����� �����.

� ���9. ������� ������ ���������� , ���

1/22

1 1|| ||

m nij

i jA a

= =

� �= � �� �� �� �

1

�����������(�������)

��6. ������ �� ������������������� �� Visual Basic

2

��������� �� Visual Basic

� ��������� �� Visual Basic ����������������� (������ �����) �� �������� ���������������� (��� �����) ������ ���������� � ������ ��� �

��������� �� � ������ ��o�� �������.� �������� � �������� � ������

�������. � ������ � ��������� � ������������.

3

�������� �� Visual Basic

� ����� �������� �� �������� �� ���������� (Toolbox) ��������� ������ �������� ���� ��� �� �� �������� �������. ������� (������� ��������) ��������:

- ��� ����� ���(Text Box) - � ������� �� �� ������ ���������� ������������,

- �������(Label) - ������� � �������� ������������� �� ����������� �� �� �� ��� ����� �� �������������� ����������� �� �� ��� �� ����������� ��, �������� ��� �� � ��������� �� ��������� �����������,

- �������� �����(Command Button) - ����������������� ���������� ��� �� �� ������� ������ ������,

- ����� ���(Picture Box) - � ������� ����������� �� ����������� �������� ����.

4

�������� �� � �����

� �� ���������� ���������� (Properties Window) ��������� ��� ������ ������ ������� (����������) ������ �� �� ������������ ���

� !������ �������� ��������

- �� TextBox �: Text, Font, Enabled, Visible, …- �� Label �: Caption, Font, Alignment, Visible, …- �� Command Button �: Caption, Font, Enabled, Visible, …- �� Picture Box �: Picture, Font, Visible, …

� ��������� �� Visual Basic � ������������� ���: �������������(interface), ������ �� �� ��� ���������.

� �������� �� ���������� �� � ���� ��� �� ����������� ��������.

5

"���� �� � �����

� ������ ����� ��� � ������ �� � ����� � ��� �����Text1, Text2, …, Label1, Label2, …, Command1, Command2, …, Picture1, Pictire2,…

� "��� �� � �������� �� � ����� �� ������ ���������� �� ��� ����� Name �� ������ � ���#� ������������������ �� �������� �� ������������ ���.

� ������������� �� ������� �� � ����� ���� ��� ����� � �� ��� �� �������� �� ���������� ���� ���� ����� ������� � �����, ����

- �� Text Box � ������� �����txt, �� ���� txtPrezime- �� Label � ������� �����lbl, �� ���� lblNaslov- �� Command Button � ������� �����cmd, �� ����

cmdPresmetaj- �� Pictute Box � ������� �����pic, �� ����

picPrikaz- �� Form � ������� �����frm, �� ���� frmVlez

6

!������ �� Visual Basic

� ���� � �������� ��� Visual Basic �������, ��������� ���������������� � ��������� ����. !���� � � ������ � ����� ��������������� ������ ������, ���� �� ���������� �� ����� �������. $������ ������ �������� �� ���.

� $�� ����� �� �������� �� Visual Basic ��o�����:

- ������ �� ����e���������� (interface): �������� �� � ����� �� �������,

- �������� �� ����� �������� ������������ �� ������� �����,

- ������ �� ���������� � �� � ������������ % � ����� �����������.

7

������� Visual Basic

� ������ ������ �������� (��������� �����) ������������������� ������ �� ��� �� ����������� �����������.

� ������ ������ ��� ������� ��� ������ �� �������� �� ������� ������ ��� �����

objectName.property = setting!� ����,

txtPrezime.Text = "" ��� cmdPresmetaj.Visible = True� ������������ �� � ������������� ������ -������� ��� ����������� ������ �� �� ��������

objectName.method [display]!� ����,

txtPrezime.SetFocus ��� picPrikaz.Print "Rezultatite se:"

8

������� Visual Basic

� ���������� � �� � �������� �� �������� ��

����������� ����� �� ������ ��

��������������� �����.Private Sub objectName_event()

statement(s)End Sub

(& ����Private �������� ��� ����������������� �� ��������� ��� �� � ����� ��

������������� �����, �� ��� ��� ������������ ������� - Public Sub)

9

�������� �� Visual Basic� ������������ ����������������� ��� ��� ��������

(�� ����) ������ ����� �������� (���� ��) ��� � ���������� ��. &� ��� ��Visual Basic �������� �� �� ������:

- Sub ��������� �- Function ���������.

$� � ������ ��� � �������� �������� ���� �� ���� ��������������������� �� ������ ��� �� �������������� � �� ����� �������.

� Sub ��������� ������������� ���� �������� ������ ��% ������, ��� ��� ��, � ������� �� � �����������������������.

Private Sub ProcedureName ()statement(s)

End Sub

10

�������� �� Visual Basic

� Sub ��������� � ������� �� ��������Call ProcedureName

� �� ������, ��� Sub ������� �� � �� �������� ������� ������ ��� ������������ ������, � �� � �� ����� ����� �������.

� '��� Sub ������� ��� �� ����� ����� Sub ���������������������.

� &� ������� �� ��������� �� ��������� ������� ����� Sub ������� ��� �� ����������������� �� �������������� �� ����General Declarations (�������VB-������� ������ ����� �����) ��� �� ������������������ ��� ���� ��������(�������VB-������� ������ ����% ����� �����).

11

�������� �� Visual Basic

� �������������� �������, ��� �� ����������� ���� ������� ������ Functon ��������� ��� ���������� ��������� �������.

Private Function FunctionName(var1 As Type1, var2 As Type2, …) As dataType

statement(s)FunctionName = expression

End Function� Function �������� ������������� ����������������� ��� �� �� �������� ������������. Function �������� ��� �� �������������� �� ������ �� ������������ ��������� �������.

12

�������� �� Visual Basic

� Function �������� � �������������Sub �������� ������������� ���� ���������� ���. �������� � ����������� �������������� �� ������ �� ��� � � ���������� � ����� ���������, �������� ��� �����. &�������� �� Function ��������, Sub �������� � ��� �� ����������� �� ���������.

� ������� Function ������� ��� �� � ���������� Function ��� Sub �������.

(������ 10. ������������������.)(������ 11. ����������������.)

1

�����������(�������)

��7. ������� �� Visual Basic (������� ����)

2

������� ����� �� ��������

������ �� Visual Basic� ������� �� ������������������

� ������� �� �������� ����� �� �����

�� �����, ������������, �����, �������(Line, PSet, Circle)

� ��������� �� ������ ���������

���� (��������: CurrentX, CurrentY, �����: Print, TextHeight, TextWidth)

3

������� �� ������������������

� ��������� ��������� (default) �� ������������������ �� ������������������(0,0) �� �������������, x-������ ������� ����� �� ����, y-������ ������� ����� �� ����.

� �� ������ �� ��������� �� ���������� ScaleWidth, ScaleHeight, ScaleLeft, ScaleTop � �������� ������������������. �� ����, ��

Picture1.ScaleWidth = 30Picture1.ScaleHeight = - 30Picture1.ScaleTop = 15Picture1.ScaleLeft = -15

������ ��������������� �� 30 ������ � ������ �������, � ����������������� �������� �� Picture1, ����� x-������ ������� ����� �� ����, a y-������ ������� �������� ��� (�������� � ����� �� ������-).

4

������� �� ������������������

� ������ ����������� �� ����������������� �

��������� �� Scale ������:Picture1.Scale (-15, 15) - (15, -15)

��� �� ���������

Picture1.Scale (a, d) - (b, c)�� ��������� �� ��������������� ��a �� b � x-������� ��c �� d � y-������.

5

�������� �����

� ������ �� ������� ������� (x1,y1) � ������������� (x2,y2) � ���� �� ������ Line ����

Picture1.Line (x1,y1) - (x2,y2)

� ���� �� ���������� (x,y) � ������� �� ������PSet ����

Picture1.PSet (x,y)

� !��"���� �� ����� �� (x,y) � ������r � ���� �������� Circle ����

Picture1.Circle (x,y), r

6

�������� �����

�����"�� ����#� �� ��������� �����:� Picture1.Line (x1,y1) - (x2,y2), color, B[F]�� ����, ��������������������� �#������������ ����� �� (2,2) � (6,4):

Picture1.Line (2,2) - (6,4), RGB(255,0,0), BF� Picture1.PSet (x,y), color�� ����, ���� ����� �� ���������� (-3,2):

Picture1.PSet (-3,2), RGB(0,255,0)� Picture1.Circle (x,y), r, color, start, end, aspect�� ����, ���� ���� �� ����� �� (0,0), �=2.5, b=5

Picture1.Circle (0,0), 5, RGB(0,0,255), , , 1/2 ������� �#�����"����������"���� �� ����� �� (0,0) �������5, ��������Pi/6 �� ������Pi/3

Picture1.Circle (0,0), 5, RGB(0,0,255), -Pi/6 , - Pi/3 (��� Pi ������������� �������� Pi=3.141592653…)

7

���������� �� ����

� �� ������� ����o��� �� ���������� CurrentX CurrentY���"������� ���������� �� ������� �� ��������� (CurrentX, CurrentY) ����� �������� ���������� �� �������� Print ������ (������������� �� ��������������� ������). �� ����,

Picture1.CurrentX = 13Picture1.CurrentY = 1Picture1.Print "y=0"

� �������� ����������� �� ������� ���� �� ������TextHeight � TextWidth.�� ����,

Picture1.CurrentX = 13 - Picture1.TextWidth("y=0") / 2Picture1.CurrentY = 1 - Picture1.TextHeight("y=0") / 2Picture1.Print "y=0“

(�����12. ������� ��������.)(�����13. ����������� �� ����� (��������������).)

1

�����������(�������)

��8. ������ �� ������� �� Visual Basic (������� ����)

2

K��������� �������� ���� �������

� ��������� � ���� ������� ���������� ��

Dim var As String * n� �� ���������� �� �������� ��������������������� �� ������� ��� �� � ������� �������������� ��

[Private ��� Public] Type TypeNameTypeElement1 As Type1TypeElement2 As Type2…

End Type� ����������� ������� ������� ����� � ����������� ����� �� ������� �� �������� ���� �� �� ������������������, �� ������� ������� ����������. ������, ���������� �� �� ������ (�������� ������������ Student).

3

������� �� ������ �����

(Random Access Files)� ����������� �������� ������� ��� ������

(Records) ��� � ���� ��� ���������, ������� �������������� �������� ����

�������. �� ����, ������ ���������� (��, ����, ������ �����, �����).

� ����������� ������ ������� ���� ���� ��

����� ���������� �� ����. ����� ���������� �� 1, 2, 3, �.�.�., � ��� ������ �� ������� ���������� ��� ����.

� ���������� ������� �� ������ �����

Open "filespec" For Random As #n Len = Len(record)

4

������� �� ������ �����

(Random Access Files)� ������������ �������� ������������ record �������� ��br ������ ����������� ������� ������n

Put #n, br, record� �������� �������� ��br ������ ������������������ ������n � �������� �� ���������� ��������� ���������� record

Get #n, br, record� !������ ������ �������� �� ��������� ������� ������

n � ������� �� ���������LOF(n), ���� ������ ������� �� ��� ������� �� ������ �����

numberOfRecords = LOF(n) / Len(record)� ����������� ���������

Close #n(������ 14. �� ������ � ���� (��������, �����������, ������������������- ���� �������).)