Excel TextBox fonction à 3 inconnus

essenge11 Messages postés 14 Date d'inscription lundi 4 mai 2009 Statut Membre Dernière intervention 11 février 2011 - 5 mai 2009 à 00:12
essenge11 Messages postés 14 Date d'inscription lundi 4 mai 2009 Statut Membre Dernière intervention 11 février 2011 - 5 mai 2009 à 16:43
Bonjour,je débute dans le Language VBA et j'ai une fonction mathématique à 2 inconnus=C ou à 3 inconnu=1,soit f(A,B)=C ou f(A,B,C)=1,J'ai fait un UserForm ayant 2 Textbox :Textbox1=A et Textbox2=B dont je saisi mes variables A et B sur Textbox1 et Textbox2,et donne le résultat C à un MsgBox=C.Je
Voudrais rendre ma fonction plus pratique en donnant le résultat sur un TextBox3 au lieu de MsgBox.Je préfère y aller par étape? mais pour être encore plus pratique,il faudrais que je puisse saisir au moins 2 des 3 variables(A,B.C),n'importe quelle,et que le résultat sorte sur le Textbox correspondant?mais pour l'instant je n'arrive pas.J'appréci à
l'avance,merci.
Cordialement essenge11

Option Explicit
'##### Ici je définis toutes les variables #####
Dim a As Double, b As Double, c As Double
Private Sub UserForm_Click()
'#####j'autorise uniquement la saisie de valeurs numériques dans un
?TextBox.'avec la virgule valide(décimale)#####
On Error Resume Next
If Not IsNumeric(Right(TextBox1, 1)) And Right(TextBox1, 1) <> "," Then
MsgBox "Le caractere saisi n'est pas valide"
TextBox1 = Left(TextBox1, Len(TextBox1) - 1)
End If
If Not IsNumeric(Right(TextBox2, 1)) And Right(TextBox1, 1) <> "," Then
MsgBox "Le caractere saisi n'est pas valide"
TextBox2 = Left(TextBox2, Len(TextBox2) - 1)
End If
`##########
UserForm2.Show
`##########
a = UserForm2.TextBox1().Text
b = UserForm2.TextBox2().Text
?#####j'indique un calcul à 2 inconnus#####
c = (a + b ) ^ 0.5
MsgBox c
End Sub

1 réponse

essenge11 Messages postés 14 Date d'inscription lundi 4 mai 2009 Statut Membre Dernière intervention 11 février 2011
5 mai 2009 à 16:43
Private Sub UserForm_Click()
Dim A As Double
Dim B As Double
Dim C As Double
On Error Resume Next
If Not IsNumeric(Right(TextBox1, 1)) And Right(TextBox1, 1) <> "," Then
MsgBox "Le caractere saisi n'est pas valide"
TextBox1 = Left(TextBox1, Len(TextBox1) - 1)
End If
If Not IsNumeric(Right(TextBox2, 1)) And Right(TextBox2, 1) <> "," Then
MsgBox "Le caractere saisi n'est pas valide"
TextBox2 = Left(TextBox2, Len(TextBox2) - 1)
End If
A = UserForm2.TextBox1().Text
B = UserForm2.TextBox2().Text
C = (A+B) ^ 0.5
UserForm2.TextBox3() = C
If Not IsNumeric(Right(TextBox3, 1)) And Right(TextBox3, 1) <> "," & "" Then
MsgBox "Le caractere saisi n'est pas valide"
TextBox3 = Left(TextBox3, Len(TextBox3) - 1)
End If
If TextBox1.Text < 0 Then
MsgBox "Il n'y a pas de résultat"
End If
If TextBox2.Text < 0 Then
MsgBox "Il n'y a pas de résultat"
End If
If TextBox3.Text < 0 Then
MsgBox "Il n'y a pas de résultat"
End If
TextBox1.Text = Format(A, "0.0")
TextBox2.Text = Format(B, "0.0")
TextBox3.Text = Format(C, "0.00")
UserForm2.Show
End Sub
-Désolé,je corrige,C'est ce que j'ai trouver à fonction 2 inconnus,merci
pour les exemples,mais fonction à 3...
0
Rejoignez-nous