Dim a#
: idem que Dim a As Double
If a = 0 Then MsgBox "a = 0 => Il n'y a pas de solution !": Exit Sub
Option Explicit
Sub Essai()
Dim s1$, s2$, a#, b#
Do
s1 = InputBox("a : ")
Loop Until s1 <> ""
Do
s2 = InputBox("b : ")
Loop Until s2 <> ""
a = Val(Replace$(s1, ",", ".")): If a = 0 Then Exit Sub
b = Val(Replace$(s2, ",", "."))
MsgBox "Solution de ax + b : " & -b / a
End Sub
Option Explicit
Sub Équation()
Dim msg$, s1$, s2$, a#, b#
Do: s1 = InputBox("Saisir la valeur de a :"): Loop Until s1 <> ""
Do: s2 = InputBox("Saisir la valeur de b :"): Loop Until s2 <> ""
a = Val(Replace$(s1, ",", "."))
If a = 0 Then MsgBox "a = 0 => Pas de solution !": Exit Sub
Const lf2 As String * 2 = vbLf & vbLf
b = Val(Replace$(s2, ",", "."))
msg = "a = " & a & lf2 & "b = " & b & lf2 _
& "Solution de ax + b = 0 :" & lf2 & "x = -b / a = " & -b / a
MsgBox msg, 0, "Infos"
End Sub
Option Explicit
Private Sub cmdRsd_Click()
Dim a#, b#, s$
If txtA = "" Then MsgBox "Vous devez donner a !": txtA.SetFocus: Exit Sub
a = Val(Replace$(txtA, ",", ".")): If a = 0 Then MsgBox "a = 0 => Pas de solution !": Exit Sub
If txtB = "" Then MsgBox "Vous devez donner b !": txtB.SetFocus: Exit Sub
b = Val(Replace$(txtB, ",", ".")): s = Replace(LTrim$(Str$(-b / a)), ".", ",")
If Left$(s, 2) = "-," Then s = "-0," & Right$(s, Len(s) - 2)
If Left$(s, 1) = "," Then s = "0" & s
txtX.Caption = s: cmdClr.SetFocus
End Sub
Private Sub cmdClr_Click()
txtX.Caption = "": txtB = "": txtA = "": txtA.SetFocus
End Sub
Private Sub txtA_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 27 Then Unload Me
End Sub