Bah, ça résoud un système d'équations à 2 inconnues avec la méthode apprise en classe de 3è !
Source en VB 3 mais compatible VB 6.
Le ZIP contient :
- la feuille (présentée ci-dessous)
- le module (idem)
- le fichier FRX (l'icone)
- l'icone
- l'EXE
- le projet .MAK
taille : 6,32 Ko (2 sec max)
Source / Exemple :
MODULE :
Option Explicit
Sub CenterForm (x As Form)
centerformtop x
centerformleft x
End Sub
Sub centerformleft (x As Form)
x.Left = screen.Width / 2 - x.Width / 2
End Sub
Sub centerformtop (x As Form)
x.Top = (screen.Height * .9) / 2 - x.Height / 2
End Sub
Fichier FRM :
VERSION 2.00
Begin Form Feuille1
BackColor = &H8000000F&
BorderStyle = 3 'Trait double fixe
Caption = "Résoluteur de système de deux équations à deux inconnues"
ClientHeight = 3555
ClientLeft = 2070
ClientTop = 1875
ClientWidth = 5970
Height = 3960
Icon = FE1_1.FRX:0000
Left = 2010
LinkTopic = "Feuille1"
ScaleHeight = 237
ScaleMode = 3 'Pixel
ScaleWidth = 398
Top = 1530
Width = 6090
Begin Frame CadreSol
BackColor = &H8000000F&
Caption = "Solutions"
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 1545
Left = 90
TabIndex = 0
Top = 1890
Width = 5775
Begin Label lblfraz
AutoSize = -1 'True
BackStyle = 0 'Transparent
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 195
Left = 180
TabIndex = 1
Top = 990
Width = 5415
WordWrap = -1 'True
End
Begin Label lbly
AutoSize = -1 'True
BackStyle = 0 'Transparent
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 195
Left = 180
TabIndex = 2
Top = 630
Width = 45
End
Begin Label lblx
AutoSize = -1 'True
BackStyle = 0 'Transparent
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 195
Left = 180
TabIndex = 3
Top = 360
Width = 45
End
End
Begin Frame CadreCmd
BackColor = &H8000000F&
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 1545
Left = 4140
TabIndex = 14
Top = 90
Width = 1725
Begin CommandButton CmdGraph
Caption = "&Tracer"
Enabled = 0 'False
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 375
Left = 270
TabIndex = 16
Top = 900
Width = 1185
End
Begin CommandButton CmdRes
Caption = "&Résoudre"
Default = -1 'True
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 375
Left = 270
TabIndex = 15
Top = 270
Width = 1185
End
End
Begin Frame CadreSys
BackColor = &H8000000F&
Caption = "Système"
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 1545
Left = 90
TabIndex = 4
Top = 90
Width = 3705
Begin TextBox txtc
Alignment = 1 'Justifié à droite
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 285
Index = 1
Left = 2610
TabIndex = 12
Top = 990
Width = 555
End
Begin TextBox txtb
Alignment = 1 'Justifié à droite
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 285
Index = 1
Left = 1710
TabIndex = 11
Top = 990
Width = 555
End
Begin TextBox txta
Alignment = 1 'Justifié à droite
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 285
Index = 1
Left = 720
TabIndex = 10
Top = 990
Width = 555
End
Begin TextBox txtc
Alignment = 1 'Justifié à droite
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 285
Index = 0
Left = 2610
TabIndex = 8
Top = 360
Width = 555
End
Begin TextBox txtb
Alignment = 1 'Justifié à droite
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 285
Index = 0
Left = 1710
TabIndex = 7
Top = 360
Width = 555
End
Begin TextBox txta
Alignment = 1 'Justifié à droite
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 285
Index = 0
Left = 720
TabIndex = 6
Top = 360
Width = 555
End
Begin Label lblfnd
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "x + y ="
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 9.75
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 240
Index = 1
Left = 1350
TabIndex = 13
Top = 1020
Width = 1215
End
Begin Label lblfnd
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "x + y ="
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 9.75
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 240
Index = 0
Left = 1350
TabIndex = 9
Top = 390
Width = 1215
End
Begin Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "{"
FontBold = 0 'False
FontItalic = 0 'False
FontName = "Times New Roman"
FontSize = 48
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 1095
Index = 0
Left = 180
TabIndex = 5
Top = 180
Width = 465
End
End
End
Option Explicit
Sub BonneValeur (TB As TextBox)
TB = IIf(TB = "", 1, Val(TB))
End Sub
Sub CmdRes_Click ()
On Error GoTo Err_CmdRes_Click
Dim i%
For i = 0 To 1
BonneValeur Txta(i)
BonneValeur Txtb(i)
BonneValeur Txtc(i)
Next
Dim valx#, valy#, tmp%, mul0#, mul1#
mul0 = Val(Txtb(1))
mul1 = Val(Txtb(0))
mul0 = IIf(mul0 < 0 Eqv mul1 < 0, -mul0, mul0)
valx = (Val(Txtc(0)) * mul0 + Val(Txtc(1)) * mul1) / (Val(Txta(0)) * mul0 + Val(Txta(1)) * mul1)
valy = (Val(Txtc(0)) - Val(Txta(0)) * valx) / Val(Txtb(0))
lblx = "x = " & valx
lbly = "y = " & valy
lblfraz = "Le couple (" & valx & ";" & valy & ") est solution du système."
Exit Sub
Err_CmdRes_Click:
lblx = ""
lbly = ""
lblfraz = "Erreur n° " & Err
Select Case Err
Case 6
lblfraz = lblfraz & " : dépassement de capacités"
Case 11
lblfraz = lblfraz & " : impossible de résoudre"
End Select
Exit Sub
End Sub
Sub Form_Load ()
CenterForm Me
End Sub
Conclusion :
Ben, il ne reste plus qu'à tracer la droite !
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.