OVH Cloud OVH Cloud

Faire communiquer dans les deux sens deux TextBox(s).

3 réponses
Avatar
Patrick
Bonjour à tous
Je n'arrive pas bien à faire communiquer deux TextBoxs,j'aimerai pouvoir
écrire indifféremment dans:
PVHT.Text pour avoir le résultat dans PVTTC.Txt ou faire le contraire mais
il y à des parasites dans mon code!
Merci.

Public TVA As Double

Private Sub EFFACER_Click()
PAHT.Text = ""
PVHT.Text = ""
PVTTC.Text = ""
VALEURTVA.Text = ""
MARGEBRUTE.Text = ""

End Sub

Private Sub FERMER_Click()
Unload Form1
End Sub

Private Sub Form_Load()
TVA = 1.055
End Sub

Private Sub PAHT_KeyPress(KeyAscii As Integer) 'TextBox
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Or KeyAscii = 44 Then
'8 = TOUCHE RET ARR
'46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
Else
If KeyAscii = 46 Then
KeyAscii = 44
Else
KeyAscii = 0
End If
End If
End Sub

Private Sub PVHT_Change() ' TextBox
If PVHT = "" Then PVTTC = "": VALEURTVA.Text = ""
On Error GoTo lasuite
PVTTC.Text = Round((PVHT * TVA), 3)
VALEURTVA.Text = PVTTC.Text - PVHT.Text
lasuite:
End Sub

Private Sub PVHT_KeyPress(KeyAscii As Integer) 'TextBox
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Or KeyAscii = 44 Then
'8 = TOUCHE RET ARR
'46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
Else
If KeyAscii = 46 Then
KeyAscii = 44
Else
KeyAscii = 0
End If
End If

End Sub



Private Sub PVTTC_Change() 'TextBox
If PVTTC.Text = "" Then PVHT.Text = "": VALEURTVA.Text = ""
On Error GoTo fin
PVHT.Text = Round((PVTTC.Text / TVA), 3)
VALEURTVA.Text = PVTTC.Text - PVHT.Text
fin:

End Sub

Private Sub PVTTC_KeyPress(KeyAscii As Integer) 'TextBox
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Or KeyAscii = 44 Then
'8 = TOUCHE RET ARR
'46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
Else
If KeyAscii = 46 Then
KeyAscii = 44
Else
KeyAscii = 0
End If
End If
End Sub

Private Sub TVA196_Click() 'CheckBox
On Error GoTo SUITE
If TVA196.Value = 1 Then
TVA55.Value = 0
TVA196.SetFocus
TVA = 1.196
PVTTC.Text = PVHT.Text * 1.196
Else
TVA = 1.055
TVA55.Value = 1
PVTTC.Text = PVHT.Text * 1.055
End If
SUITE:
End Sub

Private Sub TVA55_Click() 'CheckBox
On Error GoTo SUITE
If TVA55.Value = 1 Then
TVA196.Value = 0
TVA55.SetFocus
TVA = 1.055
PVTTC.Text = PVHT.Text * TVA
Else
TVA = 1.196
TVA196.Value = 1
PVTTC.Text = PVHT.Text * TVA
End If
SUITE:
End Sub

Private Sub VALEURTVA_Change() 'TextBox
On Error GoTo fin
VALEURTVA.Text = Round(VALEURTVA.Text, 3)

fin:
End Sub

3 réponses

Avatar
LE TROLL
Salut,

Y a des truc pas optimisés, genre checkBox avec un choix, et suelement
un, on prend des optionButton

Idem, ta marge brute (ttc vente - ttc achat) je présume, mais dans
l'absolu c'est faux, car tu peux acheter à 5,5 et revendre à 19,6, alors il
faudrait la tva achat et la tva vente...

En plus, tu as 4 textBox, mets les en boucle, ça va plus vite text(i)

Pour ma part, je ne suis pas le seul, je ne donne pas de noms aux
objets, car si quelqu'un reprend derrière toi, c'est le cas, il doit mettre
fastidieusement chaque nom, au lieu de laisser en l'état... (test1,
test2...).

Pour tes tests, un select case est plus clair, et si tu avais déclaré en
boucle les textBox, tu n'en aurais qu'un à faire...

Tu fais des opération directement avec les textBox, ce n'est pas
recommandé, faire les opérations avec des variables... De là peut venir une
erreur...

Ton contrôle des saisie n'est pas assez élaboré, si tu le contrôle en
saisie, fais le à fond, donc en 1ere position, pas de "," ni vide= " ", ni =
0, pas +d'1 foit la "," etc...
---------------------

"Patrick" a écrit dans le message de news:

Bonjour à tous
Je n'arrive pas bien à faire communiquer deux TextBoxs,j'aimerai pouvoir
écrire indifféremment dans:
PVHT.Text pour avoir le résultat dans PVTTC.Txt ou faire le contraire mais
il y à des parasites dans mon code!
Merci.

Public TVA As Double

Private Sub EFFACER_Click()
PAHT.Text = ""
PVHT.Text = ""
PVTTC.Text = ""
VALEURTVA.Text = ""
MARGEBRUTE.Text = ""

End Sub

Private Sub FERMER_Click()
Unload Form1
End Sub

Private Sub Form_Load()
TVA = 1.055
End Sub

Private Sub PAHT_KeyPress(KeyAscii As Integer) 'TextBox
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Or KeyAscii = 44 Then
'8 = TOUCHE RET ARR
'46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
Else
If KeyAscii = 46 Then
KeyAscii = 44
Else
KeyAscii = 0
End If
End If
End Sub

Private Sub PVHT_Change() ' TextBox
If PVHT = "" Then PVTTC = "": VALEURTVA.Text = ""
On Error GoTo lasuite
PVTTC.Text = Round((PVHT * TVA), 3)
VALEURTVA.Text = PVTTC.Text - PVHT.Text
lasuite:
End Sub

Private Sub PVHT_KeyPress(KeyAscii As Integer) 'TextBox
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Or KeyAscii = 44
Then
'8 = TOUCHE RET ARR
'46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
Else
If KeyAscii = 46 Then
KeyAscii = 44
Else
KeyAscii = 0
End If
End If

End Sub



Private Sub PVTTC_Change() 'TextBox
If PVTTC.Text = "" Then PVHT.Text = "": VALEURTVA.Text = ""
On Error GoTo fin
PVHT.Text = Round((PVTTC.Text / TVA), 3)
VALEURTVA.Text = PVTTC.Text - PVHT.Text
fin:

End Sub

Private Sub PVTTC_KeyPress(KeyAscii As Integer) 'TextBox
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Or KeyAscii = 44
Then
'8 = TOUCHE RET ARR
'46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
Else
If KeyAscii = 46 Then
KeyAscii = 44
Else
KeyAscii = 0
End If
End If
End Sub

Private Sub TVA196_Click() 'CheckBox
On Error GoTo SUITE
If TVA196.Value = 1 Then
TVA55.Value = 0
TVA196.SetFocus
TVA = 1.196
PVTTC.Text = PVHT.Text * 1.196
Else
TVA = 1.055
TVA55.Value = 1
PVTTC.Text = PVHT.Text * 1.055
End If
SUITE:
End Sub

Private Sub TVA55_Click() 'CheckBox
On Error GoTo SUITE
If TVA55.Value = 1 Then
TVA196.Value = 0
TVA55.SetFocus
TVA = 1.055
PVTTC.Text = PVHT.Text * TVA
Else
TVA = 1.196
TVA196.Value = 1
PVTTC.Text = PVHT.Text * TVA
End If
SUITE:
End Sub

Private Sub VALEURTVA_Change() 'TextBox
On Error GoTo fin
VALEURTVA.Text = Round(VALEURTVA.Text, 3)

fin:
End Sub




Avatar
Patrick
Bonjour à tous et merci pour la réponse.

"LE TROLL" <le a écrit dans le message de news:

Salut,



Y a des truc pas optimisés, genre checkBox avec un choix, et suelement
un, on prend des optionButton


J'ai changé les deux CheckBox pour des OptionButton.

Idem, ta marge brute (ttc vente - ttc achat) je présume, mais dans
l'absolu c'est faux, car tu peux acheter à 5,5 et revendre à 19,6, alors
il faudrait la tva achat et la tva vente...


Oui mais là c'est juste pour faire un PVHT ; PVTTC ; TM ...

En plus, tu as 4 textBox, mets les en boucle, ça va plus vite text(i)


Donne moi un exemple stp pour que je puis le faire.

Pour ma part, je ne suis pas le seul, je ne donne pas de noms aux
objets, car si quelqu'un reprend derrière toi, c'est le cas, il doit
mettre fastidieusement chaque nom, au lieu de laisser en l'état... (test1,
test2...).


J'ai rechangé le nom de tous les objets.

Pour tes tests, un select case est plus clair, et si tu avais déclaré
en boucle les textBox, tu n'en aurais qu'un à faire...


Donne moi un exemple stp pour que je puis le faire.

Tu fais des opération directement avec les textBox, ce n'est pas
recommandé, faire les opérations avec des variables... De là peut venir
une erreur...



Ton contrôle des saisie n'est pas assez élaboré, si tu le contrôle en
saisie, fais le à fond, donc en 1ere position, pas de "," ni vide= " ", ni
= 0, pas +d'1 foit la "," etc...


Oui effectivement la virgule mais je ne suis pas arrivé à faire un espace!
Je vais essayé de voir comment eviter de répéter cette virgule .

Encore merci pour cette reponse voici mon nouveau code, il faut que je
travaille la gestion des erreurs plus tard.
A +

Public TVA As Double

Private Sub TEXT5_Change()
'COEFFICIENT
On Error GoTo fin
Text5.Text = Round(Text5.Text, 3)
fin:
End Sub

Private Sub Command1_Click()
' EFFACER
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
End Sub

Private Sub Command2_Click()
'FERMER
Unload Form1
End Sub

Private Sub Form_Load()
TVA = 1.055
End Sub

Private Sub Option1_Click()
'TVA
On Error GoTo SUITE

'TVA 5.5 % Option1
If Option1.Value = True Then
Option2.Value = False
'Option1.SetFocus
TVA = 1.055
Text4.Text = Round((Text2.Text * TVA), 3)


End If
Text6.Text = Text4.Text - Text2.Text
Text8.Text = ((Text2.Text - Text1.Text) / Text4.Text * 100)
Text5.Text = Text4.Text / Text1.Text
SUITE:
End Sub

Private Sub Option2_Click()
'TVA
On Error GoTo fin
'TVA 19,6 % Option2
If Option2.Value = True Then
Option1.Value = False
' Option2.SetFocus
TVA = 1.196
Text4.Text = Round((Text2.Text * TVA), 3)

End If

Text6.Text = Text4.Text - Text2.Text
Text8.Text = ((Text2.Text - Text1.Text) / Text4.Text * 100)
Text5.Text = Text4.Text / Text1.Text
fin:
End Sub

Private Sub Text1_Change()
'PAHT
If Text1.Text = "" Then Text3.Text = "": Text7.Text = "": Text8.Text = "":
Text5.Text = ""
End Sub

Private Sub TEXT1_KeyPress(KeyAscii As Integer)
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Or KeyAscii = 44 Then
'8 = TOUCHE RET ARR
'46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
Else
If KeyAscii = 46 Then
KeyAscii = 44
Else
KeyAscii = 0
End If
End If
End Sub
Private Sub TEXT1_KeyUp(KeyCode As Integer, Shift As Integer)
'PAHT
On Error GoTo fin
Text3.Text = ((Text2.Text - Text1.Text) / Text2.Text * 100)
Text8.Text = ((Text2.Text - Text1.Text) / Text4.Text * 100)
Text7.Text = Text2.Text - Text1.Text
Text5.Text = Text4.Text / Text1.Text

fin:
End Sub

Private Sub TEXT2_Change()
'PVHT
If Text2.Text = "" Then Text4.Text = "": Text3.Text = "": Text6.Text = "":
Text7.Text = "": Text8.Text = "": Text5.Text = ""
On Error GoTo lasuite
Text3.Text = ((Text2.Text - Text1.Text) / Text2.Text * 100)
lasuite:
End Sub

Private Sub TEXT2_KeyPress(KeyAscii As Integer)
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Or KeyAscii = 44 Then
'8 = TOUCHE RET ARR
'46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
Else
If KeyAscii = 46 Then
KeyAscii = 44
Else
KeyAscii = 0
End If
End If

End Sub

Private Sub TEXT2_KeyUp(KeyCode As Integer, Shift As Integer)
'PVHT
On Error GoTo fin:

Text4.Text = Round((Text2.Text * TVA), 3)
Text6.Text = Text4.Text - Text2.Text
Text8.Text = ((Text2.Text - Text1.Text) / Text4.Text * 100)
Text7.Text = Text2.Text - Text1.Text
Text5.Text = Text4.Text / Text1.Text
fin:
End Sub

Private Sub TEXT4_Change()
'PVTTC
If Text4.Text = "" Then Text2.Text = "": Text6.Text = "": Text5.Text = ""
On Error GoTo fin

fin:

End Sub

Private Sub TEXT4_KeyPress(KeyAscii As Integer)
If IsNumeric(Chr(KeyAscii)) = True Or KeyAscii = 8 Or KeyAscii = 44 Then
'8 = TOUCHE RET ARR
'46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
Else
If KeyAscii = 46 Then
KeyAscii = 44
Else
KeyAscii = 0
End If
End If
End Sub

Private Sub TEXT4_KeyUp(KeyCode As Integer, Shift As Integer)
'PVTTC
On Error GoTo fin
Text2.Text = Round((Text4.Text / TVA), 3)
Text6.Text = Text4.Text - Text2.Text

Text8.Text = ((Text2.Text - Text1.Text) / Text4.Text * 100)
Text7.Text = Text2.Text - Text1.Text
Text5.Text = Text4.Text / Text1.Text
fin:
End Sub

Private Sub TEXT3_Change()
'TAUX DE MARQUE
On Error GoTo fin
Text3.Text = Round(Text3.Text, 2)
fin:
End Sub

Private Sub Text7_Change()
'MARGE BRUTE
End Sub

Private Sub TEXT8_Change()
'TM GC
On Error GoTo fin
Text8.Text = Round(Text8.Text, 2)
fin:
End Sub

Private Sub TEXT6_Change()
'VALEUR TVA
On Error GoTo fin
Text6.Text = Round(Text6.Text, 3)

fin:
End Sub
Avatar
LE TROLL
Salut,

-1- Pour mettre les 4 textBox en boucle:
Tu déclares le 1er (text1), puis tu fais dessus: copier / coller, il va te
dire qu'il existe déjà et te demander si tu veux l'indexer, tu réponds
"oui", et tu va avoir text1(0), et text1(1)
Etc.. jusqu'à 3, (0 à 3 = 4), ou jusqu'à 4 et tu supprimer le text1(0)
ensuite, ainsi c'est plus claire, tout commence à 1 (text1(1) à (4)...
Donc, quand tu t'adresseras au TextBox ce sera dans le style:
text1(i)

-2- Tu as je crois deux fois 2 CheckBox, alors ça fait 4, et 4, si tu mets
des optionButton, un seul va marche, alors comme ils vont par groupe de 2,
il faut les grouper 2 par 2 en mettant ces paires dans 2 Frames...

-3- Le select Case avec des Text indexés, une seule procédure:
Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
select case keyascii
case 48 to 57: goto ok
case 46
keyascii = 48
goto ok
case 44: goto ok
end select
keyascii = 0
ok:
End Sub

-4- Pour ton contrôle de saisie, ce qu'il manque:
- Déjà si ça fait une longueur < 1 tu peux refuser la saisie:
if len(text1(i) < 1 then exit sub
- Pour la virgule, il faut examiner chaque octet de la saisie, si le 1er
octet a une virgule, tu rejettes. Ensuite, tu cherche les virgules, si tu en
trouves plus d'une tu rejettes..
- Il faut aussi retasser text1(i) = trim(text1(i) pour enlever les blancs
Etc...
---> Mais tu as choisis la forme la plus compliquée, généralement on met un
bouton, et on ne calcule que quand on veut le faire grâce au bouton, car le
calcul automatique ça oblige à tout contrôler car celui qui saisit ne va pas
obligatoirement le faire dans l'ordre, par exemple, on peut imaginer dans la
logique, que si tu choisis la TVA tu as déjà saisi le HT, mais justement, si
le HT n'a pas encore été saisi, soit tu vas sortir en erreur, ou il te
faudra tester le contenu de la zone HT avant d'afficher le TTC, pour la
raison que la zone HT peut être vide, alors qu'avec un bouton tu fais ça en
séquence ensuite, testant chaque textBox, et rejetant si non conforme, ceci
avant tout calcul...
-> IsNumeric ça marche pas à tous les coups, je ne m'en sers pas, j'ai déjà
eu des problèmes, je ne sais plus dans quelle circonstance...