Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSub UseFonction() Dim Prm1 as integer, Prm2 as Integer, Resultat as Integer if not Integer.TryParse(TextBox1.Text,Prm1) Then 'Pas bon End If ... Resultat=MaFonction(Prm1,Prm2) ... End Sub
Function integrale(ByVal a As Double, ByVal b As Double) As Double Dim ok As Boolean, h, u0, v0, v1, q As Double fonction = TextBox18.Text fonction = LCase(fonction) k = 1 t = 1 e1 = 0 e2 = 1 S = 0 ok = True If a > b Then h = a a = b b = h ok = False End If If a = b Then q = 0 Return q Exit Function End If u0 = a S = 0 distributeur(u0, 1, 1, 1) v0 = S S = 0 h = 0.01 'h = PI / 10 Do While u0 <= b 'distributeur(u0 + h, 1, 1, 1) 'v1 = S distributeur(u0 + h / 2, 1, 1, 1) v1 = S 'q += (h / 2) * (v0 + v1) q += h * v1 'v0 = v1 S = 0 u0 += h Loop If ok = True Then Return q Else Return -q End If q = 0 End Function
Sub distributeur(ByVal a As Object, ByVal i As Integer, ByVal t As Integer, ByVal e As Integer) Dim n As Integer If fonction = "" Then MsgBox("vous devez entrer une fonction au clavier") Exit Sub End If If Mid(fonction, 1, 1) = "-" Then If i = 1 Then i = 2 End If End If If i > 1 Then If Mid(fonction, i - 1, 1) = "(" Then If Mid(fonction, i, 1) = "-" Then i += 1 End If End If End If If Mid(fonction, i, 1) = ")" Then 'MsgBox(k) If k > 0 Then If Mid(fonction, k, 1) = "-" Then k = -1 Else k = 1 End If Else 'MsgBox(k + 1) k = 1 End If ' If i <> 1 Then ' If Mid(fonction, i - 1, 1) <> "(" Then If e = 2 Then 'fractiontrigo() If z = 0 Then If e1 = 1 Then 'MsgBox("ouais2") S3 = Sin(S) If S3 = 0 Then S3 = 0.0001 End If S = S0 + k * (S2 / S3) Label2.Text = S Else 'S = 0 S1 = k * Sin(S) 'MsgBox(S1) S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If Else S1 = k * z * Sin(S) ' S = 0 S = S0 + S1 Label2.Text = S 'z = 0 S0 = 0 e = e0 z = z0 End If ElseIf e = 3 Then 'fractiontrigo() If z = 0 Then If e1 = 1 Then S3 = Cos(S) If S3 = 0 Then S3 = 0.0001 End If S = S0 + k * (S2 / S3) Label2.Text = S 'MsgBox("ok") Else 'S = 0 S1 = k * Cos(S) S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If Else S1 = k * z * Cos(S) ' S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If ElseIf e = 4 Then 'fractiontrigo() If z = 0 Then If e1 = 1 Then S3 = Exp(S) If S3 = 0 Then S3 = 0.00001 End If S = S0 + k * (S2 / S3) Label2.Text = S 'MsgBox("ok") Else S1 = k * Exp(S) 'S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If Else S1 = k * z * Exp(S) ' S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If ElseIf e = 5 Then 'fractiontrigo() If z = 0 Then If e1 = 1 Then If S = 0 Then S3 = -20 ElseIf S > 0 Then S3 = Log(S) End If If S3 = 0 Then S3 = 0.0001 End If S = S0 + k * (S2 / S3) Label2.Text = S 'MsgBox("ok") Else If S = 0 Then S1 = -20 * k ElseIf S > 0 Then S1 = k * Log(S) End If ' S1 = k * Log(S) 'S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If Else If S = 0 Then S1 = -20 * k * z ElseIf S > 0 Then S1 = k * z * Log(S) End If 'S1 = k * z * Log(S) ' S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If ElseIf e = 10 Then 'fractiontrigo() If z = 0 Then If e1 = 1 Then S3 = th(S) If S3 = 0 Then S3 = 0.0001 End If S = S0 + k * (S2 / S3) Label2.Text = S 'MsgBox("ok") Else S1 = k * th(S) 'S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If Else S1 = k * z * th(S) ' S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If ElseIf e = 11 Then 'fractiontrigo() If z = 0 Then If e1 = 1 Then S3 = sh(S) If S3 = 0 Then S3 = 0.0001 End If S = S0 + k * (S2 / S3) Label2.Text = S 'MsgBox("ok") Else S1 = k * sh(S) 'S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If Else S1 = k * z * sh(S) ' S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If ElseIf e = 12 Then 'fractiontrigo() If z = 0 Then If e1 = 1 Then S3 = ch(S) If S3 = 0 Then S3 = 0.0001 End If S = S0 + k * (S2 / S3) Label2.Text = S 'MsgBox("ok") Else S1 = k * ch(S) 'S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If Else S1 = k * z * ch(S) ' S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If ElseIf e = 6 Then 'fractiontrigo() If z = 0 Then If e1 = 1 Then S3 = Tan(S) If S3 = 0 Then S3 = 0.0001 End If S = S0 + k * (S2 / S3) Label2.Text = S 'MsgBox("ok") Else S1 = k * Tan(S) 'S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If Else S1 = k * z * Tan(S) ' S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If ElseIf e = 7 Then 'fractiontrigo() If z = 0 Then If e1 = 1 Then If S >= 0 Then S3 = Sqrt(S) Else : S3 = 0 End If If S3 = 0 Then S3 = 0.0001 End If S = S0 + k * (S2 / S3) Label2.Text = S 'MsgBox("ok") Else If S >= 0 Then S1 = k * Sqrt(S) Else : S1 = 0 End If 'S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If Else If S >= 0 Then S1 = k * z * Sqrt(S) Else : S1 = 0 End If ' S = 0 S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If ElseIf e = 8 Then If z = 0 Then If S3 = 0 Then S3 = 0.0001 End If S1 = k * (S2 / S3) 'S = 0 S = S0 + S1 + s4 Label2.Text = S S0 = 0 e = e0 z = z0 Else If S3 = 0 Then S3 = 0.0000001 End If S1 = k * z * (S2 / S3) ' S = 0 S = S0 + S1 + s4 Label2.Text = S S0 = 0 e = e0 z = z0 End If ElseIf e = 9 Then 'fractiontrigo() If z = 0 Then If e1 = 1 Then 'MsgBox("ouais2") S3 = Abs(S) If S3 = 0 Then S3 = 0.0001 End If S = S0 + k * (S2 / S3) Label2.Text = S e = e0 Else 'S = 0 S1 = k * Abs(S) S = S0 + S1 Label2.Text = S S0 = 0 e = e0 z = z0 End If Else S1 = k * z * Abs(S) ' S = 0 S = S0 + S1 Label2.Text = S 'z = 0 S0 = 0 e = e0 z = z0 End If End If If Mid(fonction, i + 1, 1) = ")" Then 'MsgBox("ok") If Mid(fonction, e2, 1) = "/" Then S3 = S If z = 0 Then If S3 = 0 Then S3 = 0.0001 End If S = k * (S2 / S3) S = S0 + s4 + S 's4 = S Label2.Text = S s4 = 0 z = z0 distributeur(a, i + 2, t, e) Exit Sub Else If S3 = 0 Then S3 = 0.0001 End If S = k * z * (S2 / S3) S = S0 + s4 + S 's4 = S Label2.Text = S s4 = 0 z = z0 distributeur(a, i + 2, t, e) Exit Sub End If Else distributeur(a, i + 1, t, e) Exit Sub End If ElseIf Mid(fonction, i + 1, 1) = "/" Then e2 = i + 1 'e1 = 1 S2 = S i += 2 S = 0 distributeur(a, i, t, e) Exit Sub Else i += 2 e2 = 1 End If k = 0 'distributeur(a, i, t, e) End If 'End If 'End If If Mid(fonction, i, 1) = "x" Then polynome(a, i, 1, 1, e) Exit Sub End If If Mid(fonction, i, 1) = "s" Then If Mid(fonction, i + 1, 1) = "i" Then test(i) e0 = e k = i - 1 S0 = S S = 0 sinus(a, i, 1, 1) Exit Sub ElseIf Mid(fonction, i + 1, 1) = "h" Then test(i) e0 = e k = i - 1 S0 = S S = 0 sinh(a, i, 1, 1) Exit Sub End If End If If Mid(fonction, i, 1) = "c" Then If Mid(fonction, i + 1, 1) = "o" Then test(i) e0 = e k = i - 1 S0 = S S = 0 cosinus(a, i, 1, 1) Exit Sub ElseIf Mid(fonction, i + 1, 1) = "h" Then test(i) e0 = e k = i - 1 S0 = S S = 0 cosh(a, i, 1, 1) Exit Sub End If End If If Mid(fonction, i, 1) = "e" Then test(i) e0 = e k = i - 1 S0 = S S = 0 exponentielle(a, i, 1, 1) Exit Sub End If If Mid(fonction, i, 1) = "l" Then test(i) e0 = e k = i - 1 S0 = S S = 0 logarithme(a, i, 1, 1) Exit Sub End If If Mid(fonction, i, 1) = "t" Then If Mid(fonction, i + 1, 1) = "h" Then test(i) e0 = e k = i - 1 S0 = S S = 0 tanh(a, i, 1, 1) Exit Sub 'End If ' End If ElseIf Mid(fonction, i + 1, 1) = "a" Then test(i) e0 = e k = i - 1 S0 = S S = 0 tangente(a, i, 1, 1) Exit Sub End If End If If Mid(fonction, i, 1) = "r" Then test(i) e0 = e k = i - 1 S0 = S S = 0 racine(a, i, 1, 1) Exit Sub End If If Mid(fonction, i, 1) = "f" Then test(i) e0 = e k = i - 1 s4 = S S0 = S S = 0 S0 = 0 fraction(a, i, 1, 1) Exit Sub End If If Mid(fonction, i, 1) = "a" Then test(i) e0 = e k = i - 1 S0 = S S = 0 valeur_absolue(a, i, 1, 1) Exit Sub End If For n = 0 To 9 If Val(Mid(fonction, i, 1)) = n Then If i = 1 Then b = 1 ElseIf i <> 1 Then If Mid(fonction, i - 1, 1) = "+" Then b = 1 ElseIf Mid(fonction, i - 1, 1) = "-" Then b = -1 ElseIf Mid(fonction, i - 1, 1) = "" Then b = 1 ElseIf Mid(fonction, i - 1, 1) = "(" Then b = 1 End If End If For j = i To Len(fonction) If Mid(fonction, j, 1) = "*" Then If Mid(fonction, j + 1, 1) = "x" Then t = Val(Mid(fonction, i, j - i)) i = j + 1 polynome(a, i, t, b, e) Exit Sub ElseIf Mid(fonction, j + 1, 1) = "s" Then If Mid(fonction, j + 2, 1) = "i" Then If i > 1 Then k = i - 1 Else k = 0 End If z = Val(Mid(fonction, i, j - i)) i = j + 1 S0 = S S = 0 sinus(a, i, t, b) Exit Sub ElseIf Mid(fonction, j + 2, 1) = "h" Then If i > 1 Then k = i - 1 Else k = 0 End If z = Val(Mid(fonction, i, j - i)) i = j + 1 S0 = S S = 0 sinh(a, i, t, b) Exit Sub End If ElseIf Mid(fonction, j + 1, 1) = "c" Then If Mid(fonction, j + 2, 1) = "o" Then If i > 1 Then k = i - 1 Else k = 0 End If z = Val(Mid(fonction, i, j - i)) i = j + 1 S0 = S S = 0 cosinus(a, i, t, b) Exit Sub ElseIf Mid(fonction, j + 2, 1) = "h" Then If i > 1 Then k = i - 1 Else k = 0 End If z = Val(Mid(fonction, i, j - i)) i = j + 1 S0 = S S = 0 cosh(a, i, t, b) Exit Sub End If ElseIf Mid(fonction, j + 1, 1) = "e" Then If i > 1 Then k = i - 1 Else k = 0 End If z = Val(Mid(fonction, i, j - i)) i = j + 1 S0 = S S = 0 exponentielle(a, i, t, b) Exit Sub ElseIf Mid(fonction, j + 1, 1) = "l" Then If i > 1 Then k = i - 1 Else k = 0 End If z = Val(Mid(fonction, i, j - i)) i = j + 1 S0 = S S = 0 logarithme(a, i, t, b) Exit Sub ElseIf Mid(fonction, j + 1, 1) = "t" Then If Mid(fonction, j + 2, 1) = "a" Then If i > 1 Then k = i - 1 Else k = 0 End If z = Val(Mid(fonction, i, j - i)) i = j + 1 S0 = S S = 0 tangente(a, i, t, b) Exit Sub ElseIf Mid(fonction, j + 2, 1) = "h" Then If i > 1 Then k = i - 1 Else k = 0 End If z = Val(Mid(fonction, i, j - i)) i = j + 1 S0 = S S = 0 tanh(a, i, t, b) Exit Sub End If ElseIf Mid(fonction, j + 1, 1) = "r" Then If i > 1 Then k = i - 1 Else k = 0 End If z = Val(Mid(fonction, i, j - i)) i = j + 1 S0 = S S = 0 racine(a, i, t, b) Exit Sub ElseIf Mid(fonction, j + 1, 1) = "f" Then If i > 1 Then k = i - 1 Else k = 0 End If z = Val(Mid(fonction, i, j - i)) i = j + 1 S0 = S S = 0 fraction(a, i, t, b) Exit Sub ElseIf Mid(fonction, j + 1, 1) = "a" Then If i > 1 Then k = i - 1 Else k = 0 End If z = Val(Mid(fonction, i, j - i)) i = j + 1 S0 = S S = 0 valeur_absolue(a, i, t, b) Exit Sub End If End If If Mid(fonction, j, 1) = "+" Then t = Val(Mid(fonction, i, j - i)) i = j + 1 ' i = i + j S = S + b * t Label2.Text = S distributeur(a, i, t, e) Exit Sub End If If Mid(fonction, j, 1) = "/" Then e2 = j t = Val(Mid(fonction, i, j - i)) i = j + 1 ' i = i + j S = S + b * t S2 = S 'e1 = 1 Label2.Text = S S = 0 distributeur(a, i, t, e) Exit Sub End If If Mid(fonction, j, 1) = "-" Then t = Val(Mid(fonction, i, j - i)) i = j + 1 'i = i + j S = S + b * t distributeur(a, i, t, e) Exit Sub End If If Mid(fonction, j, 1) = ")" Then t = Val(Mid(fonction, i, j - i)) i = j 'i = i + j S = S + b * t S3 = S 'S += s4 distributeur(a, i, t, e) Exit Sub End If If Mid(fonction, j + 1, 1) = "" Then t = Val(Mid(fonction, i, j - i + 1)) If InStr("+", fonction) 0 Or InStr("-", fonction) 0 Or InStr("*", fonction) = 0 Or InStr("/", fonction) = 0 Then 'If Mid(fonction, 1, 1) = "-" Then 'S = -t 'End If 'Else S += b * t Label2.Text = S Exit Sub End If 'If Mid(fonction, j + 1, 1) = "+" Then 'Or "" Then 'MsgBox("yes") 'p = j 'k = j + 1 'p = Val(Mid(fonction, i + 2, j - i - 1)) ' S = S + b * t * a ^ p 'i = j + 2 'distributeur(a, i) 'Label2.Text = S 'End If Exit For End If Next j 'S += e * b * t 'Label2.Text = S ' Exit Sub 'End If If Mid(fonction, i - 1, 1) = "-" Then S = S - t i = j Label2.Text = S 'distributeur(a, i) End If If Mid(fonction, i - 1, 1) = "+" Then S = S + t i = j Label2.Text = S 'distributeur(a, i) Exit Sub End If ' If i = 1 Then ' If Mid(fonction, i + 1, 1) = "" Then 'Label2.Text = Val(TextBox1.Text) 'End If 'End If ' Next j End If Next n End Sub
Lors de la compilation, un message d'erreur m'informe qu'il est impossible de convertir f(x) en type numérique. J'ai déja un programme que j'ai téléchargé sur le site qui calcul l'integrale mais les algorithmes se different en plus je ne veux pas faire de copier coller dans mon projet