salve a tutti,
Premetto che non sono molto esperto di programmazione.
Dopo aver compilato il file vb, per il disegno di una parabola, lasciando i valori già preimpostati, mi viene segnalato un errore"di routine o argomento non valido" nella parte di codice in cui calcola la raice del delta. Per sicurezza metto tutto il codice, e evidenzio di rosso l'errore.
Option Explicit
Dim xMin As Double, xMax As Double
Dim yMin As Double, ymax As Double
Dim a As Double, b As Double, c As Double
Dim delta As Double, x As Double
Public Function radice(delta As Double) As Double
radice = Sqr(delta)
End Function
Public Sub Intersezione()
If delta < 0 Then
interx.Caption = "IMP"
intery.Caption = "IMP"
interx2.Caption = "IMP"
intery2.Caption = "IMP"
End If
If delta = 0 Then
x = -b / (2 * a)
interx.Caption = x
intery.Caption = 0
interx2.Caption = "//"
intery2.Caption = "//"
Else
x = (-b - radice(delta)) / (2 * a)
interx.Caption = x
intery.Caption = 0
x = (-b + radice(delta)) / (2 * a)
interx2.Caption = x
intery2.Caption = 0
End If
End Sub
Public Function delt(a As Double, b As Double, c As Double) As Double
delt = (b ^ 2) - (4 * a * c)
End Function
Public Sub ImpostaVariabili()
If IsNumeric(txtxmin.Text) Then 'se il valore inserito è numerico allora...
xMin = txtxmin.Text
Else 'altrimenti...
MsgBox "Valore non corretto, verrà impostato un valore di default", vbExclamation
xMin = -10
txtxmin.Text = xMin
End If
If IsNumeric(txtxmax.Text) Then 'se il valore inserito è numerico allora...
xMax = txtxmax.Text
Else
MsgBox "Valore non corretto, verrà impostato un valore di default", vbCritical
xMax = 10
txtxmax.Text = xMax
End If
If IsNumeric(txtymin.Text) Then 'se il valore inserito è numerico allora...
yMin = txtymin.Text
Else
MsgBox "Valore non corretto, verrà impostato un valore di default", vbCritical
yMin = -10
txtymin.Text = yMin
End If
If IsNumeric(txtymax.Text) Then 'se il valore inserito è numerico allora...
ymax = txtymax.Text
Else
MsgBox "Valore non corretto, verrà impostato un valore di default", vbExclamation
ymax = 10
txtymax.Text = ymax
End If
If IsNumeric(Txta.Text) Then 'se il valore inserito è numerico allora...
a = Txta.Text
Else
MsgBox "Valore non corretto, verrà impostato un valore di default", vbExclamation
a = 2
Txta.Text = a
End If
If IsNumeric(Txtb.Text) Then 'se il valore inserito è numerico allora...
b = Txtb.Text
Else
MsgBox "Valore non corretto, verrà impostato un valore di default", vbExclamation
b = 2
Txtb.Text = b
End If
If IsNumeric(Txtc.Text) Then 'se il valore inserito è numerico allora...
c = Txtc.Text
Else
MsgBox "Valore non corretto, verrà impostato un valore di default", vbExclamation
c = 2
Txtc.Text = c
End If
CmdDati.Enabled = True 'Posizionare in CmdConferma Enabled = False, così fino a quando non si convalidano i valori questo pulsante rimane inattivo
End Sub
Private Sub cmdConferma_Click()
Dim y As Double
Dim x As Double
Dim incremento As Double
picGrafico.Scale (txtxmin.Text, txtymax.Text)-(txtxmax.Text, txtymin.Text)
picGrafico.Cls
incremento = (txtxmax.Text - txtxmin.Text) / 1000
picGrafico.Line (txtxmin.Text, 0)-(txtxmax.Text, 0), vbGreen
picGrafico.Line (0, txtymin.Text)-(0, txtymax.Text), vbGreen
picGrafico.Circle (vx(0).Caption, vy(1).Caption), 8 * incremento, &HFF00FF
picGrafico.Line (txtxmin.Text, Dirett.Caption)-(txtxmax.Text, Dirett.Caption), vbBlue
picGrafico.Line (asse.Caption, txtymin.Text)-(asse.Caption, txtymax.Text), &H80800
picGrafico.Circle (interx.Caption, 0), 8 * incremento, &HFF00FF
picGrafico.Circle (interx2.Caption, 0), 8 * incremento, &HFF00FF
picGrafico.Circle (fx.Caption, fy.Caption), 8 * incremento, &HFF00FF
y = (txtxmin.Text * txtxmin.Text) * Txta.Text + txtxmin.Text * Txtb.Text + Txtc.Text
picGrafico.PSet (txtxmin.Text, y), vbRed
For x = txtxmin.Text + incremento To txtxmax.Text Step incremento
y = (x * x) * Txta.Text + x * Txtb.Text + Txtc.Text
picGrafico.Line -(x, y), vbRed
Next x
CmdDati.Enabled = False
CmdConferma.Enabled = False
End Sub
Private Sub CmdDati_Click()
Dim IntersezioneX As Double
If a > 0 Then
conc(1).Caption = "alto"
Else
conc(1).Caption = "basso"
End If
vx(0).Caption = -b / (2 * a)
vy(1).Caption = (-b ^ 2 + 4 * a * c) / (4 * a)
fx.Caption = -b / (2 * a)
fy.Caption = (1 / (4 * a)) + vy(1).Caption
asse.Caption = -b / (2 * a)
Dirett.Caption = (-1 / (4 * a)) + vy(1).Caption
CmdConferma.Enabled = True
delta = delt(a, b, c)
D.Caption = delta
Intersezione
End Sub
Private Sub cmdConvalida_Click()
ImpostaVariabili
End Sub
Private Sub picGrafico_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
txtx = x
txty = y
End Sub