Студопедия
rus | ua | other

Home Random lecture






Результаты работы программы


Date: 2015-10-07; view: 502.


Исходный код

Private Sub cmdCalculate_Click()

Dim paramA As Double

Dim paramB As Double

Dim paramC As Double

 

Dim x1 As Double

Dim x2 As Double

Dim D As Double

 

paramA = Val(txtParamA.Text)

paramB = Val(txtParamB.Text)

paramC = Val(txtParamC.Text)

 

If paramA = 0 Or paramB = 0 Or paramC = 0 Then

MsgBox "Нули в качестве коэффициентов не допускаются!", _

vbCritical

Exit Sub

End If

 

D = CalcDiscremenant(paramA, paramB, paramC)

 

If D > 0 Then

x1 = (paramB + Sqr(D)) / (2 * paramA)

x2 = (paramB - Sqr(D)) / (2 * paramA)

WriteResultsInLabels "Дискриминант: " & D, _

"Корень №1: " & x1, "Корень №2: " & x2

ElseIf D = 0 Then

x1 = paramB / (2 * paramA)

x2 = x1

WriteResultsInLabels "Дискриминант: " & D, _

"Корень №1: " & x1, "Корень №2 = Корню №1"

ElseIf D < 0 Then

WriteResultsInLabels "Дискриминант: " & D, _

"Корней нет!", ""

MsgBox "Дискриминант меньше нуля! Корней нет!", vbCritical

End If

 

End Sub

 

Public Function CalcDiscremenant(ByVal a As Double, _

ByVal b As Double, ByVal c As Double) As Double

CalcDiscremenant = (b * b) - (4 * a * c)

End Function

 

Public Sub WriteResultsInLabels(lblDCapt As String, _

lblX1Capt As String, lblX2Capt As String)

lblD.Caption = lblDCapt

lblX1.Caption = lblX1Capt

lblX2.Caption = lblX2Capt

End Sub

 

1. При D>0:

 

 

2. При D=0:

 

 

3. При D<0:

 


<== previous lecture | next lecture ==>
Постановка задачи | Talking about your job
lektsiopedia.org - 2013 год. | Page generation: 0.003 s.