.


:




:

































 

 

 

 





, .

3.1. ,

x = 1-z t = (x+1)2

, .

y x a t z y x a t z

Sub Pr3_1 ()

Dim y As Single, x As Single, a As Single

Dim t As Single, z As Single

a = InputBox(" ")

z = InputBox(" z")

x = 1 - z

t = (x + 1) ^ 2

y = x + Abs (a + 2 * t)

MsgBox " :" & Chr(13) & _

"a=" & a & " z=" & z & Chr(13) & _

" :" & Chr(13) & _

"x=" & x & " t=" & t & Chr(13) & _

":" & Chr(13) & "y=" & y,, ""

End Sub

x t, y , .

:

/
a z x t y
1 2 3 1 2 -5 3 13 -8 -2 -12 9 1 121 100 1 232 204

.3.2.

4.

( ) If. , () .

VBA If:

1. If Then

2. If If Then Else

3. If Then ElseIf

 

4.1. IfThen

, .. , True - .

.

:

If <> Then <>

, :

If x>5 Then y=3*x+1.5

If c<=a+b*x-1.2 Then MsgBox

, ,

1. , :;

2. If Then.

, .. .

:

If <> Then

< >

End If

, IfThen:

If A>10 Then x=A+1: y=B+2: Z=C+3

If A>10 Then

x=A+1

y =B+2

z= C+3

End If

 

4.2. IfThenElse

 

. True , , ( False ) . .

:

If <> Then <> Else <>

:

If <> Then

< >

Else

< >

End If

:

 

If a > 5 Then b = b + a Else b = b a

 

If a > 5 Then

b = b + a

Else

b = b - a

End If

.

If x>0 Then

y=x+1

f=1

Else

f=2

End if

If x>0 Then y=x+1: f=1 Else f=2

 

.

 

 

4.3. IfThenElseIf

 

. . If Then If Then Else. Else , IfThenElseIf.

:

if <_1> Then

< _1>

ElseIf <_2> Then

< _2>

ElseIf <_3> Then

< _3>

[Else

< >]

End If

:

If g > 10 Then

z=5

ElseIf g<5 Then

z=1

End If

If x > 5 Then

y = x + 2

f =1

ElseIf x < -10 Then

y = 2 * x

f=2

Else

y = x - 5

f=3

End If

- IfThenElse

4.4. If

4.1.

y=

.

y x y x f

:

:

x y
1. 2. 3. 1 10 15 0 9 31 2 2 1 x<10 x=10 x>10

.4.1., .4.2.

 

Sub Pr4_1()

Dim y As Single, x As Single

Dim f As Byte

'

x= InputBox(" ")

'

If x > 10 Then y = 2 * x + 1: f = 1 Else y = x - 1: f = 2

MsgBox " =" & x & Chr(13) & _

" y =" & y & Chr(13) & _

" - " & f,, ""

End Sub

4.2. , . :

>4

3<= . <=4

<3

.

fiz mat rus Sr S P Integer Int

:

,
fiz, mat, rus <1 >5

 

Sr:

fiz mat rus Sr
1. 2. 3. 4. 5. 6. 7. 8. 0 5 3 5 4 3 3 3 5 6 4 4 4 4 3 2 4 5 -1 5 4 4 3 3 4,7 4,0 3,7 3 2,7
               

.4.3., .4.4.

Sub Pr4_2()

Dim fiz As Byte, mat As Byte, rus As Byte

Dim Sr As Single, S As String, P As Integer

'

fiz = InputBox(" ")

mat = InputBox(" ")

rus = InputBox(" ")

If (fiz < 1 Or fiz > 5) Or (mat < 1 Or mat > 5) Or (rus < 1 Or rus > 5) Then

MsgBox " " & Chr(13) & _

" - " & fiz & Chr(13) & _

" - " & mat & Chr(13) & _

" - " & rus

Else

'

Sr = (fiz + mat + rus) / 3

If Sr > 4 Then ' P

S = "": P = vbExclamation ' .

ElseIf Sr < 3 Then '

S = "": P = vbCritical

Else

S = "": P = vbQuestion

End If

' .

MsgBox S & Chr(10) & " = " & Sr & _

Chr(13) & " - " & fiz & _

Chr(13) & " - " & mat & _

Chr(13) & " - " & rus, P

End If

End Sub





:


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


:

:

, .
==> ...

1378 - | 1205 -


© 2015-2024 lektsii.org - -

: 0.043 .