Вы находитесь на странице: 1из 68

..

Visual Basic

2007

32.973-018.1

- 2 .

17
:
.
. .., , .. ..
.
. .., , . ..
.

Visual Basic. . - , 2007. 64.




,
-
VB6. ,
,
. ,
.
Visual Basic 6.0 ,
, Net.


. ,
, ,
.

.

Maximov
Nicolay
2

Digitally signed by Maximov


Nicolay
DN: CN = Maximov Nicolay, C
= RU, O = Maximoff, OU =
Home
Reason: Welcome to ComPit!
Date: 2009.01.29 21:06:00
+03'00'

..


1. ? .......................................................................................4
1.I. ................................................................................................................. 4
1.II. : ............................................................................. 8
1. .................................................................................................... 9

1.III. ......................................................... 10
2. .................................................................................................. 11

2. ...........................................................................12
2.I. .......................................................................................... 12
2.II. ................................................................................................ 13
3. .................................................................................................. 16

2.III. Visual Basic ............................................................ 17


4. .................................................................................................. 19

3. ...................................................................................20
3.I. ....................................................................................................... 20

4. .........................................................................20
4.I. , ................................................... 21
4.II. .................................................................................................. 22
5. .................................................................................................. 24

4.III. - Select Case ............................................................... 25


6. .................................................................................................. 27

5. ......................................................................28
5.I. For Next .......................................................................................... 28
7. .................................................................................................. 30

5.II. DO ... LOOP ............................................................................... 32


8. .................................................................................................. 36

5.III. ...................................................................................................................... 36
9. .................................................................................................. 42
10. ................................................................................................ 43
11. ................................................................................................ 44

5.IV. .................................................................................................. 45
12. ................................................................................................ 51

6. ................................................52
13. ................................................................................................ 55

7. .........................................................................................56
1. ............................................................................................ 56
2. ..................................................................................... 56
3.
( ): ................................................................................................. 56
4. .................................................................................................................. 56
5. ............................................................................................ 58
6. ............................................................................................. 59
7. ............................................................................................................ 61
8. , , ........................... 63

......................................................64

1. ?
Sapienti sat 1
1.I.


VB6, .
:
:\Program files\Microsoft Visual Studio\ \VB98\VB6.exe.
.

Vb6.exe

Microsoft Visual Basic 6.0 (. 1):

. 1.

,
. ,
VB6 ,

, 2
Form1 (. 2)
,
in English:
1 ().
2

.. ?. , .12, .327

. 2. Visual Basic

4,
()

.
,


.

( )
Visual Basic 6.0.

,

.
. ()
,
(Command Button):
( ) ()
5

. :
: .
:
( )
.
(. ).
.
, Command1, Command2, Command3, . , Text1,
Text2, TextN ..

.
(
Caption)

. ,

!
.
:

,
Back Color (
).
,
Caption.

3.
, ,
?
, ,
10
, , ,
. ,

.
Style (),

. (1-Graphical)
.
, 2 , :
?

3

,
, .
.
6

(
)4.
. ,
,
() ( )
. ,
.
1.
Print
, !!!.

2. End.
.

, ,
. .

.


(
).
, ,
, .

!
4

,
, .
: !, , !
!!! ,
!
7

1.II.

,
.
TextBox.
, .
1. abl Text1
Text2, Text ,
Text1-2 .
2.

Commahd3-4,

3-4.
.
3. 3 4
:
text1.text= 3
text2.text= 4
, ,
Text1. ,


text,
Tab.
,


.
4.
.

5. ,
3 4,

.


,

: ,
, ,
.
.

.
,

1.
h ,

.
Private Sub Command1_Click ()
Form1.BackColor = vbRed
End Sub
.
Form1.BackColor = vbYellow
Form1.BackColor = vbGreen
Form1.BackColor = vbBlue

,

,
.

-
.

Command1_Click ().

:
Form_Load() ,
TextBox
Text2_Change(),

Option1_Click(Index
As Integer) ..
9

1.III.

,
-
.
, 4 .
,
Text3, Label3 =.

Textbox,
, ,
Val( )
- Value .
, .

. 3. 1

.
1. Label1-3, Text1-3, Command1-5 . 3.
.
2.
. 4. +
Textbox, ,
MsgBox.
3. ,
. ,
.
. . 5.
Form1 Caption
1.
4.
.exe: (File)
(Make) 1.exe
.
10

, VB6. VB6
.
.

. 4. 1

. 5. 1

2.

: 1 , 2 TextBox - (A= =), 4


TextBox - (+=, -=, *=, /=).
Label1-6.
h

11

2.

,
. ,
.
.
2.I.



, ,
. ()
( ).
() ,
(
). .
(
).
_(), :
.;
255;

() (
!);
.
Visual Basic
.
.
Variant VB6 .
,
-
.

:
Dim [ As ]
: Dim A as Long, Dim Strok_Simvolow as String


:
Dim,

; ,
Oklad, Name, Zarplat ..
[ ] ,
.
.
12

( )

Boolean

Byte

Integer

Long

True False (
, 0 1)
1 255
-215 +215 ( -32768
+32767)
-231 +231

Currency

-263*10-4 263*10-4

Single

-2129 +2148 -1

Double

-21024 +21024 -1

)
(

)

Date

String

Variant

Object

8
1

16+1

01.01.100 31.12.9999
216 .
231


,

,
. , Dim
Const :
Const Pi as Single = 3.141592
.
..,
...
.
#,
/: #03/11/1955#. : 11.03.1955
2.II.

- ,
.
- .
, ( ) 3
( ):
1.
2.
3.
13

.
3 .
:
A = 25 B = 12.75 Tekst = Dt = 11:03
TextBox:
A = Val(Text1.text) (Val , )
Tekst = Text1.text Tekst = Str(Text1.text) (Str )
InputBox:
A = Val(Inputbox( ) )
Tekst = Inputbox( ) !!!
.
Print
Print A=; A ( = ) Print Tekst
MsgBox
Msgbox =& Msgbox !& Tekst
( & () )
TextBox:
Text1.text = Text1.text = Tekst
,
. ,

V=R2H,

- =3.14, R - , H .
,
:

V=3.14*R^2*H V=Pi*R^2*H
: +, -, *, /, ^


1-3 ( ).
General.
, General Option Explicit
ToolsOptionsEditor (Require variable
Declaration). .

Option Explicit
Dim R, H, V as Single

Const Pi as Single = 3.141592 General
14

1.
Private Sub Command1_Click()
R = Val(InputBox(" "))
H = Val(InputBox(" "))
V = 3.14 * R ^ 2 * H
MsgBox " =" & V &
End Sub
2. ,
Private Sub Command2_Click()
R = 6
H = 15
V = 3.14 * R ^ 2 * H
Print " =" ; V
End Sub
3.
Private Sub Command3_Click()
R = Val(Text1.Text)

H = Val(Text2.Text)

V = Pi * R ^ 2 * h

Text3.Text = Str(V)

End Sub
h , 3
(Command3.
ToolTipText = ), :
? . 6.

. 6.

(Property) Font

.
Tools()OptionsEditor Format. . 7.
15

. 7.

3.
h

: = 1 *-1 + 2*-2.
, .

() ,
-
. -
, ,
( ),
.
,
, :
Ctrl + C , Ctrl + V .
VB6.
.

: , .. .exe-.
, VB6.
,
.
:
ToolsOptionsEditor (Require
variable Declaration). General Option Explicit.

, VB6
,
++ ,
.

!
16

2.III. Visual Basic

,
. , 4
( ),
..
. ( !) 2-4.

+
*
/
\
Mod
^

4+5
7-4
3*6
5/4
5\4

9
3
18
1.25
1

5 Mod 4

2 ^ 4

16


:
1. (^);
2. () (/);
3. (\);
4.
5. (+) (-).

. (A-B/2)+A^2
: 1. B/2 2. A-B/2 3. A^2 4. A-B/2)+A^2

(True False)
True
True
False
False
False

>
>=
<
<=
=

>B
>=B
<B
<=B
=B

<>

<>B

True

And
Or
Not

>B And C>B


>B Or C>B
Not (C>B)

False
True
True
17

=5
B=4
3.

C=3 .

(True) (False).
( ) ,
. >B And C>B
, :
1. >B True
2. C>B False
3. True And False False ( 1 0 0)

: (>B And C>B) Or <>B. = True



, .
, .. ,
. . 4
.

4

Sin(x)
Cos(x)
Tg(x)
ArcTan(x)

Sin(x)
Cos(x)
Tan(x)
Atn(x)

Sin(0)
Cos(0)
Tan(0.785)))
Atn(1)

0
1
1
0.785

Ln(x)

Log(x)

Log(10)

2.302585

|x|
ex

Abs(x)
Exp(x)
Sqr(x)
Fix(x)

Abs(-12)
Exp(1)
Sqr(9)

Int(x)

12
2.818282
3
Fix(-12.34)
-12
Int(-12.34)
Int(12.34)

,
:
. ()

Declaration.
18

-13
12

4.
.

1. Y=A2+B3-Sqr(B2-4)/B2
2. Y=Sin((A-B)^3+(B-A)^2)
3. Y=Sin(A2-B2)/Cos(B2-A2)
4. Y=(Sqr(B2-C2))^2
5.

Y=Sqr(Abs(A2-C2))+2AC

6. Y=Tan(A2-B2)/Log(B2+A2)
7.

Z=Log(Sqr(B2+A2))/Sqr(Log(B2+A2))

8.

Z=Sin(Sqr(B3+A1/2))/(Sqr(Log(B2+A4))+1)

9.

Z=Exp(Sqr(B+A2))/Sqr(Log(B4+A2))

10.

Y=Sqr(Abs(A3-C2))+2AC2

11. Z=Exp(A2-B2)/Log(B2+A2)
12. Y=Tan(A3-B2)/Log(B2+A2)
13. Y=Sin(A2-B2)/Log(B2+A3)
14.

Z=Cos(Sqr(B3+A1/3))/(Sqr(Log(B2+A4))+1)

15.

Y=Sin(Sqr(B2+A1/2))/(Sqr(Log(B2+A3))+5)
3

16. Y = x 2 + x 4
17.

y = sin( x 3 x 2 ) /cos(x+y)

18. y=

4x 4 + 2x 2 - x


, ,
. ,
. ,
Znam, Chisl.
8- :
Znam = Sin();

Chisl = (Sgr());

Z= Znam / Chisl

Textbox
, Msgbox Inputbox
TextBox
text,
.
, ,
.
19

3.
3.I.


,
.

, .
:
1. ().

.

;
2. . ,


;
3. . ,

;
4. .
,
()
.
5. .
(
!).

.
: , -,
, , .

(-) .
-
,
(),

,
, .
- Microsoft Office:
-, Word Excel.


:
20


()
()
,
, .
.
. S Pr
. .
.
:
S
Pr
:
Snew
:
:
Snew = S + S* (Pr/100)
: 2 Command1-2 , 3 TextBox1-3


1. S Pr
2. Snew = S + S* (Pr/100)
3.

S Pr

Snew = S + S* (Pr/100)
Snew

Option Explicit
Dim S, Snew, Pr As Double
Private Sub Command1_Click()
S = Val(Text1.Text)
Pr = Val(Text2.Text)
Snew = S + S * (Pr / 100)
Text3.Text = Snew
End Sub
Private Sub Command2_Click()
End
End Sub

h .

Single . :

!
21

4.
,

( - ).
,

.
:
, !

Dim A,B,X as Single


A=Val(InputBox(" A"))
B=Val(InputBox(" B"))

,B

1.
A>B


2.
,
If A>B then X=A*A+B*B else X=A^3+B^3
,
(..
X=A3+B3
X=A2+B2

)

3.
()
,,
A,B,X

Print A= & A; B= & B; X= & X

. 8. -
20

4.I.

- :

. 9. -
() ,
: ( - true ) ( - false ).
1, +, , - 0, -, .

If Then 1N [Else 2N]


.
:. ,
, Then
.
EndIf. .

If A>=B Then C=A-B: D=A+B Else C=B-A: D=A*B: ?


If A>=B Then


C=A-B
D=A+B

Else
C=B-A : D=A*B
Print
Print ?
End If
h . 8. -
, , TextBox1-3.

, VB6
.
.
1.
.
, () .
: , ,
. -
21


.
2.
. ,
,
( )
. :
). ( -.
)
).
VB6 ( )

3.
.
, ,

4.
(
,
).
.
,
, Visual Basic
.

, ()
() (
), . . .
..
, Visual Basic.
4.II.

1. .
3000, 2%; 3000 10000, 3%;
10000, 5%. .
U ( !),
- .

Z=Val(text1.text)
3000
Z<3000
Z<10000

Pr=Z*0.05

Pr=Z*0.03

Pr=Z*0.02

-
22

If Z<3000 then
Pr=Z*0.02
Else
If Z<10000 then
Pr=Z*0.03
Else
Pr=Z*0.05
End if
End if

3 , 2 .
( 3000),
. 0 ,
(3000 10000), .
, If . If Endif
(: ).
() .
255 , .

-:
.
Z = Val(Text1.Text)
If Z < 3000 Then Pr = Z * 0.02
If Z >= 3000 And Z <= 10000 Then Pr = Z * 0.03
If Z > 10000 Then Pr = Z * 0.05
Text2.Text = Pr
-
.

(
, )
, , .
h

( -)
( 2 ). .

2. 4 A, B, C, D. .

a) . AB .
b) . .
c) AB .
h - !

Option Explicit
Dim A, B, C, D, AB, CD, Max As Single
Dim Name1, Name2, Nam As String
Private Sub Command1_Click()
A = Val(Text1.Text)
B = Val(Text2.Text)
C = Val(Text3.Text)
D = Val(Text4.Text)
If A > B Then AB = A: Name1 = "A" Else AB = B: Name1 = "B"
If C > D Then CD = C: Name2 = "C" Else CD = D: Name2 = "D"
If AB> CD Then Max=AB: Nam=Name1 Else Max=CD: Nam = Name2
Print " " & Nam & " = " & Max
End Sub
,
. > >=, .

23


( ) .

5.
h -

, . :
1 . , ,
D . - 5 . 22.
2 . ,
Else :
if A>B and A>C and A>D then
h , .

,,

>C

>B

Max=A :
TM=A

B>C

Max=C :
TM=C

Max=B :
TM=B

Max, TM

. 10.

If A>B then
If A>C then
Max=A
Else
Max=C
End if
Else
If B>C then
Max=B
Else
Max=C
End if
End if
.
24

: TM=A
: TM=C

: TM=B
: TM=C



If End if

4.III. - Select

Case


() . :

Ball

Ball=1,2

Ball=3

Ball=4

Ball=5

Y=

Y=

Y=

Y=.

Y=

. 11. - Select

Case

(- 3)
:
Select Case
Case () 1
() 1

Case () 2.
() 2
... .. ..

Case () N.
() N
... .. ..
25

Case Else
() N+1
... .. ..

End Select

,
Case Else. (Else)
, Select Case
( - . 11 ).
,
: Case 1, 2, 7 to 12 ; : Case Is < 0
3. .
Option Explicit
Dim Ball As Byte, Tekst_Ball As String
Private Sub Command1_Click()
Ball = Val(Text1.Text)
Select Case Ball
Case 1, 2
Tekst_Ball = "!"
Case 3
Tekst_Ball = ""
Case 4
Tekst_Ball = "!"
Case 5
Tekst_Ball = "!"
Case Else
Tekst_Ball = " "
End Select
Text2.Text = Tekst_Ball
End Sub
h , ,

( VB6
6 ()).

26

. Text2 ForeColor, BackColor ,

Font ,

6.
Case, :
1.
2.
3.
4.
5.
6.
7. -
8.
9. ( 10 )
10. ,
11.

12.
13.
14.
15.
16.
17.
18.
19. () , ,

ToolTipText (
) Text -
! ,
!
Case 11 to 20 -
Case Is > 31 -

. , ..
.. .
,
, , ,
.
27

5.
.
, ,
.
( )
.
, .
,
.

().
5.I.

For Next

I=M, N [, Step]

. 12. - For Next

:
For <> = <> <> [Step <>]
< >
Next [<>]


. , , ,
.
().
1.
-: I , M , N
, Step .
1 10
4.
.
:
: S
: I
: S = S + I , S
I, I

.
2 , 1 S
28


S=0

I = 1, 10

S=S+I
I

S, I

. 13. -


1.
2.
3.
4.

S
I 1
I 1 10
I , S I ,
7
5. I ( 1)
6. 3
7. S I

, 2-6
For Next, .
I


Option Explicit
Dim I, S As Integer

_______________________________________________________________________________________________________________________________-----

Private Sub Command1_Click()


S = 0
For I = 1 To 10 Step 1
S = S + I

Print " I=" & I
Next I
Print " I=" & I
Text1.Text = S
End Sub

29

h ( ) .

, :
1. 1 20 ( 2).
2. 1 20

. 14.

,

, ,
. ,
, . ,
, .
,
.
,
i , j, k, l
( ),
.
,

(
=+1). ,
: For I = N1 to N2 Step N3
h

7.
For Next InputBox, :
1. 8
2. 7
3. 8
4. 7
30

5. 5
6.
7.
8.
9.
10.
11. , (
4)
10
12. ,
8 ( 1)
13. ,
9 ( 7)
14. ,
8 ( 3)
15. , ( 4)
7

X
:
For i=1 to N
Z = Val(InputBox( ))
If I = X then Zrabotnikax =Z -


S = S + Z
_____________________________________________________________

Clipboard.Clear -
Clipboard.SetText (Text4.Text)
Text4.text
Text2.Text = Clipboard.GetText
- Text2.text

Picture1.Picture = Clipboard.GetData -


Format.
S = 12.345
Format(S, "0.00\0") ' "12.350"
Format(S, "0.\0\0") ' "12.00"
Format(0.55, "#.0\0") ' ".60", 0
Print
Format(S, #.##) S

12.36 ,
, .. >=5, 12.344 12.34

31

5.II.

DO ... LOOP


,
. (
) (
).
DO...LOOP.
, :
While ( ) Until ( ).
( )

) Do While < >


< >
Loop

) Do Until < >


< >
Loop

.
Do While Per > 0

Loop

(1)

Do Until Per <= 0

Loop

(2)

, Per 0,
, Per 0.

32

, (1 2) ?


) Do

< >

Loop While < >

) Do

< >

Loop Until < >

.
.
.
Do
(3)

Loop While Per > 0

Do
(4)

Loop Until Per <= 0


1 , ,
Per 0, 1 ,
, Per 0.

(3 4) ?
33

, :

,
- .
Per.

5. . ,

.
.
: Ves_tov () ,
Gr_pod
: S
:
: S = S + Ves_tov

.
2 : ,
2


1. S
2. .
, ,

S < Gr_pod

Ves_tov
S = S + Ves_tov

. 15.
, S .
,
Ctrl + Break
34

Furgon
Option Explicit
Dim Ves_tov, Gr_pod, S As Single
Private Sub Command1_Click()

S = 0
Gr_pod = Val(Text1.Text)
Do While S < Gr_pod
Ves_tov = Val(InputBox(" "))
S = S + Ves_tov
Text2.Text = Str(S)
Loop
If S > Gr_pod Then S=S-Ves_tov ' ?
Text2.Text = Str(S)
MsgBox (" ")

End Sub

h ,


. -.

,
, .
, .
.
Private Sub Command1_Click()

S = 0 : Text2.Text = ""
Gr_pod = Val(Text1.Text)
Do
Ves_tov = Val(InputBox(" "))
S = S + Ves_tov
Text2.Text = Str(S)
Loop Until S>=Gr_pod Or Ves_tov=0 '
( Or - )
If S > Gr_pod Then S = S - Ves_tov: MsgBox ("!
")
Text2.Text = Str(S)
MsgBox (" ")
End Sub

. 16.
35

8.

1. S=S+S*Pr,
S , Pr .
.. ,
?
2.


5%, 10% , . ,
?
3. 100 .
, , ,
5 ,
15 25 ?
4. ,
15 10 ,
2 1 ?
5.III.

,
, . ,
, ..
:
Dim ([ ] ) [As ]
:
Dim (1 to 15) as Single
, 15 ,
Dim (15) as Single

_(-_).
Dim (10) as String
Visual Basic , , .
. 0 , 1 .
Option Base 1 1.
(General) (Declarations).
, ,
. Dim (10) as Single
, ,
10 (1), (2),...,(10).
, ,
.
36

6. 12
.
: Ball(12), i
: Sr
: S
: S = S + Ball(i); Sr=S/12

.
3 : , ,
Sr Ball(i)


1.
2.
3.
4.
5.
6.

S, Sr
InputBox Ball(12)



,

S, Sr=0
I = 1, 12
Ball(i)

I = 1, 12

S=S+Ball(i)

I = 1, 12
Ball(i)

Sr=S/12
Sr

. 17. - 6
37


Option Explicit
Dim i, S As Integer
Dim Sr As Single
Dim Ball(12) as Integer

_______________________________________________________________________________________________________________________________-----

Private Sub Command1_Click()


S = 0

, ,
Sr = 0 ()

For i = 1 To 12
Ball(i) = Val(InputBox( , ))
If Ball(i)>5 or Ball(i)<1 then Msgbox 1 5! : i=i-1
Next I
,
For i = 1 To 12
- !

S = S + Ball(i)
Next i
For i = 1 To 12
Print i; Ball(i)
Next i
Sr=S/12
Print " = " & Sr
End Sub
Private Sub Command3_Click()
Form1.Cls

End Sub
!!!
____________________________________________________________________

.
. ;
, , 10 .
&.
Enter .
!
h

: Input Box
(
!),
.
: RND[()],
- RND(3) RND.
0 1: 0.21456, 0.9555,
0.5395 .. :
. ,
, RND
Randomize.
9 :
38

Randomize
For i = 1 To 12
Ball(i) = Int(Rnd * 4) + 2
Next i
Int 0
3, .. 0,1,2 3. 2 (+ 2),
2 5.
X = A + RND*(B - A),
, .
, X = A + INT (RND * (B A + 1)). : INT(RND*101)
1 100; INT(RND*101) - 50 -50 50.
9 InputBox
.
Randomize ( ). .
Randomize Timer INT(RND(Timer)*n),
, n
. 0 n-1.
,
!
h

1.
7. 10
.
: (10)
: Max , Nmax
()
: i
: Max = (i), Nmax = i
.
3 : , ,


1. Max, Nmax
2. ( 1 20).

3. Max, Nmax
4.
.
, ,
Nmax.
5.
6. ,
-
39


Option Explicit
Dim i, Max, Nmax As Integer
Dim A(10) as Integer

_______________________________________________________________________________________________________________________________-----

Private Sub Command1_Click()


Max = 0 : Nmax = 0
Randomize
For i = 1 To 10
A(i) = Int(Rnd * 21)
Print i, A(i)
Next i
Max = A(1) : Nmax = 1

For i = 2 To 10
If A(i) > Max then Max = A(i) : Nmax = i
Next i
Print Print

Print " = " & Max


Print = & Nmax
End Sub
, .
-. ,

h

2.
8. (10)
()
.. .
,
( )
. N,
N-1 . , N- ,
N-1, N-2, 2, 1 , ..
. ,
, N-1
.
( !).

1. ( 1 50).

2.
i i+1 .
40

i+1 i,
. 10-1
3.
4. ,
....................................

For J= 1 To 9 ,
For i = 1 To 10-j 1
If B(i+1) > B(i) then
Prom = B(i)
Prom
B(i) = B(i+1)
B(i+1) = Prom
Endif
Next i
Next J

(
), . -.

,
1
, (.exe).

, Redim,
.
( ) :
Dim A() as Single General

Dim N as Single -

N=Val(InputBox( - )
ReDim A(N)
,
,

For i = 1 To N

,
N
h

.
1. ,
.
A(i) = 10 + Int(Rnd*11) + i*0.5
10.5 25 i 1 10
2.
,
.
.
41

Option Explicit
Dim A() As Integer
Dim N, i As Single
Private Sub Command1_Click()
N = InputBox(" ", " ")
ReDim A(N) ' N=30
Randomize
For i = 1 To N
A(i) = -10 + Int(Rnd * 11) + i * 0.5
Next i
Print "1 ", "2 ", "3 "
Print
For i = 1 To 10
Print A(i), A(i + 10), A(i + 20)
Next i
Beep
'
End Sub
.
.

9.

:
1. A(N)
2. A(N)

3. A(N)

4. A(N) ,
10
5. A(N) ,
10, 0
6. A(N)

7. A(N) ,
10 30
8. A(N)
9. A(N)
10. A(N) 4
11. A(N)

42

12. A(N)

13. A(N)

* -
14. A(N)
,
15. A(N)
16. A(N) (N),
*
17. (N)
18. (N)
*
19. (N) ,
, *
20. (N)
21. (N)
22. (N) (N) (2*N),
(N), (N)
23. (N) (N) (2*N),
: (1), (1), (2), (2),
24. (N) 2 :
, *
25. (N)

10.
. :
1.

2.
3.
4.
5.
6. *
7. *
8. ( ) *
9. ( ) *
43

10. () *
11. *
12. ?
13.
14.
15. , *
16. , *
* - ,
, - 5 20 .
-20 20, - If A(i) <5 then A(i) =0

11.
:
Day(30) Night (30). :

1.
2.
3.
4.
5. *
6. *
7. ?
8.
9.
10.
11. ?
12. ?
13. ? *
14.
15. 3 3
*
16. *
17. *
* -

44

5.IV.

Visual Basic ,
60.

( ), .
:
Dim A(10,15) as Integer ,
10 15 . , 5
25 Dim NN_61d(25,5) as Byte.

,
. Byte ( )
. NN_61d(14,2)=5 ,
14 ( ) () 5().
, .
.
9. 10 5
-.

.
: (10,5)
: S
: i , j , Prisnak

: S = S + (i,j), S = S/50

.
4 : , , ,


1. S
2. ( 2 5).

3. , ,
Prisnak = True ,
False,
5. (
) ,
( i )
( ).
4. .
5. ,

45


Timer

i = 1, 10
i

j =1, 5

Session(i,j)

S=0
i=1, 10

Prisnak=True
j =1, 5

S=S+Session(i,j)
Sess(i,j)<>5

Prisnak=False

. 18. - Session
46

Session
Option Explicit
Dim i, j As Integer
Dim Session(10,5) as Byte
Dim S as Single
Dim Prisnak as Boolean

_______________________________________________________________________________________________________________________________-----

Private Sub Command1_Click()

Randomize
Print , , ,
, ,
For i = 1 To 10

Print i,
For j = 1 To 5
Session(I,j) = Int(Rnd * 4)+ 2
Print Session(I,j),
!!
Next j
Print
Next i
End Sub

_______________________________________________________________________________________________________________________________-----

Private Sub Command2_Click()

S = 0
For i = 1 To 10
Prisnak = True
For j = 1 To 5
S = S + Session(I,j)
If Session(I,j)<>5 then Prisnak = False
Next j
If Prisnak = True then Print i, -
Next i
Print
Print " = " & S/50
End Sub

h . ,

: ! ,
2 5
, - 5 .
4 5 (. . 19).
, .
h , , ,

, . , 0.5 - 0.7 :
Session(i, j) = Int(Rnd(Timer) * 4 + 0.5) + 2
If Session(i,j) = 6

Then Session(i,j) = 5


47

. 19. Session

10. 5 4
. :
) ?
) ?
) ?

5 () 4 (),
.

.
: (5,4)
:
MaxPrib , NpredMax
Prib, NtovMax - Prib
MaxTov , NmaxStov

MinPred , NMinPred

: i , j , Stov(j)
, Spred(i)
: MaxPrib = MaxPrib + (i,j), Stov(j) = Stov(j) +
(i,j), Spred(i) = Spred(i) + (i,j)
48

.
4 : , , ,


1.
2. ( . ,
200 1000).
3.
4. .
5. ,
)
Option Explicit
Dim i, j As Integer
Dim A(5, 4), Stov(4), Spred(5) As Single
Dim MaxPrib, NpredMax, NtovMax, MaxTov, NmaxStov, MinPred, NMinPred As
Single
Private Sub Command1_Click() 200 1000
Randomize Timer
Print "", " ", " ", " ", " "
For i = 1 To 5 '
Print i,
For j = 1 To 4 '
A(i, j) = Int(Rnd(Timer) * 801) + 200
Print A(i, j),
Next j
Print '
Next i
End Sub
Private Sub Command2_Click()
MaxPrib = 0: NpredMax = 0: NtovMax = 0: MaxTov = 0: NmaxStov = 0: MinPred
=0
MaxPrib = A(1, 1): NpredMax = 1: NtovMax = 1
For i = 1 To 5
For j = 1 To 4
If A(i, j) > MaxPrib Then
MaxPrib = A(i, j): NpredMax = i: NtovMax = j
End If

Next j
Next i
Print
Print " = " & MaxPrib & " N= " &
NpredMax & " " & NtovMax
Print
End Sub

, ).
,
. - (
, ).
h

49

. 20. Coop ( )

)
Private Sub Command2_Click()
' MaxPrib = 0: NpredMax = 0: NtovMax = 0 ' ""
)
MaxTov = 0: NmaxStov = 0
' MinPred = 0: NMinPred=0 '
For i = 1 To 4
Stov(i) = 0
'
Next i
' MaxPrib = A(1, 1): NpredMax = 1: NtovMax = 1 '
For i = 1 To 5
For j = 1 To 4
Stov(j) = Stov(j) + A(i, j)
'
Next j
Next i
' ,
MaxTov = Stov(1): NmaxStov = 1 '

For i = 2 To 4
' , j i,

If Stov(i) > MaxTov Then
MaxTov = Stov(i): NmaxStov = i
End If
Next i
Print
Print " = " & MaxTov & " N= " & NmaxStov
Print ' ? ()...
End Sub

) , ) )
.
50

12.

TextBox, .

A(n,m):
1.
2.
3. -
4. L-
5.
6.
7.
,
8. -

9. -
L
10. A(n,

n) ((1,1) + (2,2) + + (n,n))


11.

A(n, n)
12. ,
A(n, n)
13. ,
A(n, n)
14. L
15. L
16.
( )

17.
18.

19.
20. A(N,N)
51

6.

,
. - ,
. ,
, . ()
.

Dim S as String :

Len

Left
Right

Mid

LTrim
RTrim
Trim

LCase

UCase

&
52

S = , !


Len(S)
Len(S)
S

Left(S,K)
Left(S,5)

S
Right(S,K)-
, Right(S,5)
S
Mid(S,N,K)-
,
Mid(S,5,10)
S,
N

LTrim(S)-
LTrim(S)

RTrim(S)-
RTrim(S)

Trim(S)-
Trim(S)


LCase(S)-
LCase(S)
S
( )
UCase(S)-
UCase(S)
S
( )

()

S & !

15 -
!

, !

,
!
, !

, !
, !

, !
!

5
Hel+lo!
Hello!
ASCII
Asc(S)
Asc
Asc(a)
97
ASCII-
S
Chr(N)-
Chr
Chr(97)
a (a )
ASCII- N
.
+

11. ,
: = ..
: 3 F,I,O
,
FIO, 4- .
Dim Fam,Im,Ot,FIO As String
Fam = Text1.Text
Im = Text2.Text
Ot = Text3.Text
FIO = Fam & " " & Mid(Im, 1, 1) & "." & Mid(Ot, 1, 1) & "."
Text4.Text = FIO

, , - . - FIO
, 3 . ,
,
. : !
Fam = Text1.Text
L_Fam = Len(Fam)
Pr = 0
' ,
For i = 1 To L_Fam
If Pr = 0 And Mid(Fam, i, 1) = " " Then
L_Fm = i - 1 ' i,
i 1
Pr = 1
'
Else
If Pr = 1 And Mid(Fam, i, 1) = " " Then
L_Im = i - 1 - L_Fm
'
Pr = 2

End If
End If
Next i
If Pr = 0 Then MsgBox ("
")
If Pr = 1 Then MsgBox (" ")
If Pr = 2 Then
,
5

,
& (). C +

53

FIO = Mid(Fam,1,L_Fm)&" "&Mid(Fam,L_Fm+2,1)&"." &


Mid(Fam,L_Fm+1+L_Im+1,1)&"."
Text4.Text = FIO
End If

12. .
.

( ),
,
8
.
..
S = Text1.Text
L = Len(S)
For i = 1 To L

If Mid(S,i,1)=" " Then K_Prob=K_Prob+1 '
If Mid(S,i,1)="" or Mid(S,i,1)="" or Mid(S,i,1)="" or
Mid(S,i,1)="" or Mid(S,i,1)="" or Mid(S,i,1)="" or
Mid(S,i,1)="" or Mid(S,i,1)="" or Mid(S,i,1)="" or
Mid(S,i,1)="" or Mid(S,i,1)="" or Mid(S,i,1)="" or
Mid(S,i,1)="" or Mid(S,i,1)="" or Mid(S,i,1)="" or
Mid(S,i,1)="" Then K_Gl=K_Gl + 1

End If
, ,
Next i
Prozent= K_Gl /(L- K_Prob)

Print & L & , & &
K_Gl & , & Prozent %

,
: Mid.
,
.
. S1 S2
( ),
.
. 21.

. ,
,
.
. . . .
. , .
. . . - . - .
.
54

S1 = text1.text
S2 = text2.text
L1=Len(S1)
L2=Len(S2)
For I =1 to L1

For j =1 to L2

Mid(S1, I ,1) =

Mid(S2, j ,1)
K=K+1

. 21.
h -

Text Box
, :
.txt .
Text Box Multiline = True SrollBars = 2Vertical.

13.
(). :
1.
2. ?
3. ( )
4.
5.
6.
7.
55

8. ( )
9. ( )
10.

11.
12. - (
)
13. ,

14. ,
15. ASCII ( )
16. ( )

7.
1.

Textbox, Text1_Change()
Textbox. 30
30
Private Sub Text1_Change()
If Val(Text1.Text) > 30 Then Text3.Text = 30 : Msgbox !
End Sub

2.
,
,
:
Command4.Visible = False
Text1.Visible = True
Text1.Enabled = False ,
3.
( ):
If A(i)/4 = A(i)\4 then print 4

If A(i) Mod 4 = 0 then .

4.
.
() Frame1
Frame2,
56

:
Frame.
OptionButton, CheckBox .
.
, .
.
0. Text1(0)-Text1(4).
Dim kd, ke, rub, d, evro As Double
Private Sub Text1_Change(Index As Integer)
kd = Val(Text1(2).Text) '
ke = Val(Text1(3).Text) '
rub = Val(Text1(1).Text) '
d = rub / kd '
evro = rub / ke '
Text1(4).Text = evro '
Text1(0).Text = d '
VB6. .

57

5.
,
.
90 .
, ..
Option Explicit
Dim A, B, C, Z, i, ball, k As Single
Private Sub Command1_Click(Index As
Integer)
k=k+1
Label4.Caption = ""
Label5.Caption = ""
Text1(6).Text = ""
Randomize
A = Int(Rnd * 9) + 1
Text1(0).Text = A
B = Int(Rnd * 8) + 2
Text1(1).Text = B
C=A*B
Command2.Visible = True
Command1(0).Visible = False
End Sub
Private Sub Command2_Click()
Z = Val(Text1(6))
Label4.Caption = Str(C)
If C = Z Then
ball = ball + 1
Label5.Caption = "!!!"
Label5.BackColor = vbGreen
Else
Label5.Caption = "! "
Label5.BackColor = vbRed
End If
58

Label11.Caption = Str(k)
Label12.Caption = Str(ball)
Label13.Caption = Str(Int((ball / k) * 100))
Command1(0).Visible = True

Command2.Visible = False
If k > 10 And Int((ball / k) * 100) >= 90 Then Command3.Visible = True
End Sub
Command3


, ,
, ,
.
6.
,
Word
. ,
.
.
Dim c As Integer '
Private Sub Command1_Click()
colpage = Val(Text1.Text) '
n1 = Val(Text2.Text) '
Text3.Text = ""
Text4.Text = ""
If colpage <= 0 Or n1 <= 0 Then MsgBox " 2 1- -
! ": GoTo kon '
goto
If colpage \ 4 <> colpage / 4 Then MsgBox "- 4 !
. Good Bye!": End
' . -

For i = 2 To colpage / 2 Step 2


Text3.Text = Text3.Text & Trim(Str(colpage + n1 + 1 - i)) & "," & Trim(Str(n1 - 2 + i)) &
","
If c = 1 Then '
Text4.Text = Text4.Text & Trim(Str(n1 - 1 + i)) & "," & Trim(Str(colpage + n1 - i)) & ","
End If
If c = 0 Then ' , 0
Text4.Text = Trim(Str(n1 - 1 + i)) & "," & Trim(Str(colpage + n1 - i)) & "," & Text4.Text
End If

Next i
' Trim - , Word
, 150
59

l1 = Len(Text3.Text)
l2 = Len(Text4.Text)
Text3.Text = Mid(Text3.Text, 1, l1 - 1) ,
Text4.Text = Mid(Text4.Text, 1, l2 - 1)
kon: Go
to. ,
End Sub
Private Sub Command2_Click() '
Text3.Text = ""
Text4.Text = ""
Text1.Text = ""
Text2.Text = ""
colpage = 0
n1 = 0
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Command4_Click()
MsgBox " freeware. .. 25.08.2004",
vbOKOnly, " "
End Sub
Private Sub Command5_Click()
If c = 1 Then c = o Else c = 1 '
Text3.Text = ""
Text4.Text = ""
colpage = 0
n1 = 0
Call Command1_Click
End Sub

Private Sub Command6_Click()


Clipboard.Clear

Clipboard.SetText (Text3.Text) '
End Sub

Private Sub Command7_Click()


Clipboard.Clear
Clipboard.SetText (Text4.Text) '

End Sub

60

7.


Dim Karman, Stavka, A1, A2, A3, Zero As Single
Private Sub Command1_Click()
Label3.Visible = False
Text3.Visible = False
Label4.Visible = False
Karman = Val(Text4.Text)
Stavka = Val(Text2.Text)
Randomize
61

A1 = Int(Rnd * 10) - 0 9, ..
A2 = Int(Rnd * 10)
A3 = Int(Rnd * 10)
Text1(0).Text = A1
Text1(1).Text = A2
Text1(2).Text = A3
If A1 = A2 And A1 = A3 Then ' ???
Zero = Stavka * 100
Label3.Visible = True
Text3.Visible = True
Text3.Text = Str(Zero)
Karman = Karman + Zero
Text4.Text = Str(Karman)
Else
Karman = Karman - Stavka
Text4.Text = Str(Karman)
Label4.Visible = True
End If
If Karman <= 0 Then Call Command2_Click
End Sub
Private Sub Command2_Click()
MsgBox " , !", vbOKOnly, "
..."
End
End Sub
Private Sub Command3_Click()
If Label5.Visible = False Then Label5.Visible = True Else Label5.Visible =
False

End Sub


62

8. , ,

63


1. . Visual
Basic:

/ ,
. . . : , 2002. 59 .
2. .

/ , . ..
, .. , .. . - : , 2005.
56 .
3. . Visual Basic. . ., , 1998. -224 .
4. . Visual Basic .NET 24 . :
. . - . : "", 2002. - 416 .
5. .VB.NET . ; . . .:
"", 2002. - 272 .: . - . . .
6. . . Visual Basic .NET. -. .: , 2003. -304 : .
7. . . Visual Basic .NET: . .:
-,2002. - 624 : .

64


. !
z

- , .

.
z
z
z
z
z
z

, .
, .
, .
,
.
- , ,
.
.


z
z
z
z
z

.
,
.
, .
.
,
.


z
z

, ,
, , .

, ,
,
.
- ,
.


z
z
z

, .
, , .
, , ,
, : .

,
; - .


, ,
.


z
.
IBM.
z .

.
z - .

65

:
DOC NC
Microsoft
OFFICE.

Excel 7.0 ...


( )

ACCESS 2000


Excel 2000

Excel 2003

Visual Basic

- " "

,
,
Microsoft.

:
428023 , . , 7
314-795
428018 , . , 22
421-024, 420-304

428003 . ,
, 6

(8352) 21-24-75, 21-08-55,


62-85-57, 62-84-91
29.01.2009. 6090/84. .
. . . 4,0. 1000 . 719. . . 41-00-83
66