.


:




:

































 

 

 

 


MsgBox

4

VISUAL BASIC

4.1. VISUAL BASIC

: . , , '. ' .

: 0, 1, , 9

=
>
<
>=
<=
<>, ><

+
- ̳
*
/ ij
\ ֳ
^ ϳ

 

( ): () ;:.,?!

: # @ $ & %

1.2.

. . () :

123105 123E5
-15,7810-8 -15.78E-8
0,00007 7E-5
109 1E9

̲

' ', ' () .

, (!. $, @, %, &), . ≤ 20 . ' , Visual Bas, .

. ' .

:

:

Public / Private / Dim <' > [As <' >]

' . / "".

:

Public (), ;

Private ;

Dim 򳺿 , '.

. Visual Basic , .

, . . ' ', , , . Dim.

(General) (Declarations) (, ).

(General) (Declarations) . Dim Public. . , , (. 2). ', . .

 

1. Visual Basic

ij
Byte ( ) 1 ³ 0 255 Byt  
Integer (ֳ) 2 ³ -32 768 32 767 Int %
Long Integer ( ) 4 ³ -2147483648 2147483647 Lng &
Single-precision Floating point ( ) 4 ³ -3.402823 38 3.402823 38 Sng
Double precision Floating point ( ) 8 ³ 1.797693134862320308 1.797693134862320308 Dbl #
Currency ( ) 8 ³-922337203685477.5808 922337203685477.5807 Cur @
String () 1 ³ 0 65 535 Str $
Boolean   True False Bln  
Date () 16 ³ 1.01. 100 31. 12.999 Dtm  
Variant () ( ) 22 + 1 ( ) Vnt(var)  

2.

ֳ Dim x AS Integer Dim x %
ij Dim x As Single Dim x!
ij Dim x AS Double Dim x #
Dim x  

! Dim ( ) : =- 5.6; ="".

 

' , Visual Basic .

. , .

1) Dim x AS Double, AS Double ' ij

=1.78631598770806 =1.959426478990327

2) Dim x!, ! '

x= 1.786316 = 1.959427

3) Dim x@, @ '

=1.79 =1.96

4) Dim x AS Integer, AS Integer '

=2 =2

 

: ̲Ͳ, ʲ ̲

 

, , . ', , , . ij 䳺 , . Const.

:

Public/ Private I Const < ' > [ AS < ' > | = < >

.

Const Pi=3.14159

, , Public .

.

Public Const As Single Pi=3.142

 

ֲ VISUAL BASIC

 

 

, 䳿 . , .

Visual Basic 6.0 , Visual Basic.

:

- ;

;

;

;

;

;

;

.

Visual Basic , - (. 3).

 

3.

Visual Basic
|| Abs(x)
arctg x Atn(x)
cos x Cos(x)
sin x Sin(x) ѳ
tg x Tan(x)
ex Exp(x)
ln x Log (x)
Sqr(x)

 

, , . : α=α π/180.

 

4. , Visual Basic

visual basic
sec x 1/Cos(x) ,
cosec x 1/Sin(x) ,
ctg x 1/Tan(x) ,
arcsinx Atn(x/Sqr(l-x^2)) ,
arccosx Atn(Sqr(l-x^2)/x) ,
log a x Log(x) / Log(a)
lgx Log(x) / Log(10)

 

Visual Basic .5. .

5.

' ,
Asc ( ) ASCII-
Chr ( ) , ASCII-
Instr ( , -_1, _2) 2 1. , ( , )
Lcase (Po ) ,
Left ( , ʳ ) , -,
Len ( /' ) ,
LTrim ( ) -
Mid ( , []) (), , ,
Right ( , ) , ,
RTrim ( ) , -,
Space ()
Str ( )
Val ( )

 

& '

 

/ . , Date-1 .

Date , . 6.

6.

Now '
Date '
Year () г ""
Month () ̳ ""
Day ()
WeekDay () "" ( 1, 7)
DateAdd (, , ) ,
DateDiff (, 1, 2) ʳ

 

 

! DateAdd DateDiff , . 7.

 

 

7.

yyyy г w
q ww
m ̳ h
y n
d s

 

 

, DateAdd ("m", 3, Date) , DateDiff ("ww", #l,01.2001#, Date) .

 

. (, ), . , . VB , . 8 ( ).

 


8.

l () Boolean CInt (x) Integer
CByte (x) Byte CLng(x) Long
CCur (x) Currency CSng(x) Single
CDate (x) Date CVar(x) Variant
CDbl (x) Double CStr(x) String

 

 

9. Visual Basic

Fix(x) , ' , ≥
Int(x) , ≤
Rnd(x) , (0,1) . , Randomize
Round(x,[a]) , '. (), , -'. ʳ . , .
Sgn(x) -1, <0, 0, =0, 1, >0
Str(x) , ' ""
Val(x) , . Double.

 

Rnd(x). Rnd(x) . [, ] Int((B-A+l)*Rnd(x))+A.

, [0, 9] Int(10*Rnd(x)).

x , Int(10*Rnd).

 

Ͳ

 

, , ' ( ) . . .

:

1. ();

2. ;

3. (^);

4. ' ;

5. (*, /);

6. (\);

7. (Mod);

8. (+,-);

9. (&).

. 10.

 

10.

visual basic
(a-b)/(a+b)
(Abs(Al-Be)^(1/3)+ (Atn(X^2))^3)/ (Sqr(X-Y)+10.5E2*A)
sin2x3+l,5-25y ln|x-y| (Sin(x ^ 3))^2+1.5-2^5*) / Log (Abs (x - ))

 

 

òͲ

 

, , , ' , .

Visual Basic :

Not ,(⌐)

And ' ( ), (v)

Or ' ( ), (Λ)

r ("" '),()

, ó

Imp , →

, , , , , . : True () 1, False () 0.

11.

11.

x y Not x And y x r y Xr r x Jrnp
               
               
               
               

 

:

1) ( );

2) ;

3) :

Not

And

Or, Xor

Imp

Eor

. 12.

12.

Visual Basic
x [a,b] x >= a and x <= b
x (∞,a] Λ x [ b, ∞] x <= a Or x >= b
y+x v x2 y Λ x+y >B y+x And ^2- Or x+y > b

 

.

(x > y) V - >2Λ - 0,5<4, = 1,5; = 0,6.

Visual Basic :

Not(x > y)And - > 2 Or - 0.5<4

:

1) > → True (1):

2) - = 1,5 - 0,6 = 0,9 => 0,9 >2 → False (0);

3) -0,5= 1,5-0.5=1 => 1 <4 →True(1);

4) Not (True) → False (0);

5) False (0) And False (0) = False (0);

6) False (0) Or True (1) = True (1).

³: True (1).

While-Wend, Do-Loop if, Elseif Select Case.

 

 

4.2. ²Ͳ

Visual Basic . ' , . 䳿 . .

䳿 Visual Basic (.1). 䳿:

1. ³ Visual Basic.

2. .

, ', . ³ 1-1 () (.1).

 

 

1. ³

 

, ' ' , 䳿 Visual Basic. . ' () 䳿 (), . ' ' ' 䳿, "", ' . ' ' 䳿. ̳ 䳿.

. ϳ ' 1 䳿 Click, Private Sub 1_Click (. 1). ҳ () End Sub.

Visual Basic 6.0. (). Visual Basic.

. . (:). . (_). .

 

! . , 䳿 . .

 

: , .

, .

' , . . Enter. , Ctrl+Enter, .

. , . Options Editor Tool.

ϳ ( ) .

. End . ϳ End .

 

VISUAL BASIC

 

Private Sub Form_<> ([])

1

2

..

n

End Sub

, Visual Basic.

 

3. VISUAL BASIC

 

Visual Basic .

- Visual Basic, , , , , Visual Basic.

, .

 

: =,

X ;

A .

=

X=X+2 , , 2 . .

13.

 

13.

Visual Basic
Y=3*(Atn(x^2)+Cos(x)^3)/abs(x-a)^(1/3)
a=(Sqr(x^2+y^2)-1.5E2*x)/(cos(x^3)^2+sin(y^3)^2)

 

Visual Basic , . : (). .

InputBox

:

InputBox (<>,[<>], [<>], [<0, 0>]),

<> <> (");

<> - , ;

<> - ;

<> ;

<x0,y0> ;

- , .

. x = InputBox (" x = ",,, 4000, 400)

.

 

! , .

 

' . InputBox , . ( (Cansel) ).

. = InputBox( , )

 

 

2. ³ InputBox

 

MsgBox

:

MsgBox (< > [, +] [, ])

:

1. ( ).

2. Str(a) .

Str : ) ; ) .

() . () , .

' + &.

+ , ( 14).

³ .

. x+sinx.

1. MsgBox (" = " +Str () + " " + "+sin() =" + Str(x+Sin())

2. MsgBox (" = " & Str () &" " & " + 8() = " & Str ( + Sin()))

14. MsgBox

vbOKOnly   ҳ ʻ
vbOKCancel   ʻ
vbAbortRetryIgnore   ,
vbYesNoCancel   ,
vbYesNo  
vbRetryCancel  
vbCritical  
vbQuestion  
vbExclamation  
vbInformation  

 

, , ͳ , : vbYesNo + vbInformation 4 + 64.

MsgBox , ( 15).

15.

,
vbOK   ʻ
vbCancel  
vbAbort  
vbRetry  
vbIgnore  
vbYes  
vbNo  

, MsgBox . , .

.

MsgBox 8-1, 64,

, ..., ʻ (. 3)

 

 

3. ³ MsgBox

 

Print ( , Spc, String$)

:

[Form n]. Print [ ],

:

;

( );

;

;

, Spc, String$.

Form n n.

ij: Print .

(,) (;). (,) ( 14 ). (;) .

, Visual Basic . . .

:

(n),

n .

Print , (0.01; 999999). .

Spc:

Spc(n),

n , Print.

String $:

String(n," "),

n , Print.

Print .

. Print.

,

x=1.5; y=-5.

Print ( ) 䳿:

1. ³ .

2. Command Button, General . :

) Command Button ( );

) , ;

) .

1.

3. , . , , , . Caption () 1 ( Name) .

4. ' 1 (Form1). ' Properties () ' 1 (Form1). Properties () ' . ( ) ( ).

5. , Properties () Font, , , .

6. ' Autoredraw (True).

7. . ' :

Private Sub _Click()

 

End Sub.

8. ϳ ( ).

9. , .

10. 1 . z . (. 4).

Private Sub _Click()

Dim x!, y!, z!, p!

x = 1.5: y = -5

z = sqr(abs(x ^ 2 - y ^ 2)) / Tan(x)^2

p = ((y^2-x^2) ^ (1 / 3) + Log(Abs(x /y))) / Cos(z) ^ 2

Print "x="; x, "y="; y

Print

Print "z="; z, "p="; p

End Sub

, z p Print

 

4. ³

 

11. , .

12. .

13. (Save Project) (Save As Project).

 

 

. , , .

Y=x2+sinz+tg2(z+x), x=3.4; z=5.6.

1. ³ Visual Basic

2. .

3. 1 .

4. ³ 1 1 ().

ϳ ' ᒺ Form ' 䳿 Load, Form_ Load()

5. ҳ () Private Sub Form_Load() End Sub.

Private Sub Form1_Load()

Dim x!, y!, z!

x=Val(InputBox(x=))

z=Val(InputBox(x=))

y=x^2+sin(z)+tan(z+x)^2

Print x, y, z

End sub

5.

6. .

7. ' =. 3.4 Ok Enter.

8. ' z =. 5.6 Ok Enter. ' :

=3.4 z=5.6 =11.13332.

 

( , , , ) TextBox, Label, ComboBox, ListBox, FlexGrid.

' TextBox

. ' TextBox.

' TextBox ( ) . :

1. ' TextBox ' .

2. .

3. ' ( Name); ' Text1, Text2

4. , , : (Backcolor), (Forecolor), (Font), (Alignment) .

, , Text. :

_!_ᒺ_._

.

L Text ' :

L = Val(.Text).

Val(x) x .

S :

.Text = S.

' Label

( ) ' Label. ϳ , , , , . ' Label. ̳ , .

̳ . , , . TextBox. , ' Label . , . Caption (), , .

 

. TextBox , - ( 1).

1. ³ .

2. 4 TextBox. VB 1, 2, 3, 4. , , . 1 . 1.

3. Text 1. 1. 1 2, 1 - 2, Text. . TextBox.

4. ˳ Label (̳). ³ 1. Caption () 1 (.). 2. -1 -2. (Caption) 2 (). : 3 г , 4 (.).

 

6.

 

5. 1 (Caption) 1 . .

6. 4, 1, 2, 3 4 4.

. 1 . ³ 11(). ³ 4. ³ GotFocus.

11()

Private Sub 4_GotFocus()

 

End Sub,

.

Private Sub 4_GotFocus()

Dim B!,T!,p!,S!

B=Val(1.Text)

t= Val(2.Text)

p= Val(3.Text)

S=B*(1+p/100)^t

4.Text=S

End Sub

. , Text TextBox, , .

. 8.

 

8. ³

 

Ͳ

1. ? ?

2. ?

3. ?

4. ?

5. ?

6. ? ?

7. ? ?

8. ? ?

9. Visual Basic?

10. Dim?

11. Visual Basic?

12. ?

13. - ? ? .

14. Visual Basic ?

15. ? .

 



<== | ==>
|
:


: 2017-02-11; !; : 894 |


:

:

, ; , .
==> ...

1753 - | 1516 -


© 2015-2024 lektsii.org - -

: 0.334 .