Correction code calcul flexgrid

Gamaldiouf Messages postés 43 Date d'inscription lundi 30 octobre 2006 Statut Membre Dernière intervention 16 février 2008 - 28 avril 2007 à 03:17
amalVB Messages postés 20 Date d'inscription mardi 13 décembre 2005 Statut Membre Dernière intervention 3 mai 2007 - 28 avril 2007 à 15:11
Bonjour

je vous demande de nous corrigé ce code pour qu'on puisse avancé : j'ai grille flexgrid de 8 colonnes 25 lignes je voudrais calculer :
chaque lignes les mémes calculs (coefficient il y a un lettre et un chiffre exemple D6, D4, D9 etc...)
total = coefficient*1200    partemployé=total*20/100    partemployeur=total*80/100
et je veux calculer les totaux des colonnes     colonne 6  , colonne7,  colonne 8 j'utilise VB 6.0 chaque fois il ya débogage sur les calculs voila le code:
j'ai utilisé as variant parce que il admet pas le as double.


Dim i As Variant
Dim coefficient As Variant
Dim partemploye As Variant
Dim partemployeur As Variant
Dim total As Variant
Dim Valeur As Variant
Dim notehonoraire As Variant
Dim datedevisite As String
Dim actes As String
Dim visa As String

Private Sub grid_Click()


For i = 1 To 25 ' qui correspond à 24 lignes + une ligne pour les totaux colonnes
  'tu te places sur la colonne numéro notehonoraire
  If IsNumeric(TextMatrix(i, 3)) Then
notehonoraire = CVar(grid.TextMatrix(i, 0))
datedevisite = CStr(grid.TextMatrix(i, 1))
actes = CStr(grid.TextMatrix(i, 2))
  'tu te places sur la colonne Coeficient
coefficient = CVar(grid.TextMatrix(i, 3))
total = CVar(grid.TextMatrix(i, 4))
partemploye = CVar(grid.TextMatrix(i, 5))
partemployeur = CVar(grid.TextMatrix(i, 6))
visa = CStr(grid.TextMatrix(i, 7))
'tu calcule Total et tu l' inscrit dans ColonneTotal de la ligne en cours
 grid.TextMatrix(i, 4) = coefficient * 1200
'partemploye
 grid.TextMatrix(i, 5) = total * 20 / 100
'partemployeur
 grid.TextMatrix(i, 6) = total * 80 / 100
'2° Calcule Totaux Colonnes
'Tu te places sur la colonne dont tu veux faire le total
Next
For i = 1 To 24 'Lignes
 total = total + CVar(grid.TextMatrix(i, 4))
 'total partemploye
  partemploye = partemploye + CVar(grid.TextMatrix(i, 5))
'total partemployeur
  partemployeur = partemployeur + CVar(grid.TextMatrix(i, 6))
'total coefficient
  coefficient = coefficient + CVar(grid.TextMatrix(i, 3))
'Tu te places à la dernière ligne, et LaColonneTotal
total = total + CVar(grid.TextMatrix(i, 4))
grid.TextMatrix(24, 4) = total
partemployeur = partemploye + CVar(grid.TextMatrix(i, 4))
grid.TextMatrix(24, 5) = partemploye
partemployeur = partemployeur + CVar(grid.TextMatrix(i, 4))
grid.TextMatrix(24, 6) = partemployeur
coefficient = coefficient + CVar(grid.TextMatrix(i, 4))
grid.TextMatrix(24, 3) = coefficient
Next
 ' positionnement du textbox sur la cellule


  Text1.Left = grid.CellLeft


  Text1.Top = grid.CellTop


  ' dimensionnement du textbox aux dimensions de la cellule


  Text1.Width = grid.CellWidth


  Text1.Height = grid.CellHeight


  ' initialisation du texte avec celui contenu dan la cellule


  Text1.Text = grid.Text


  ' textbox visible avec le focus


  Text1.Visible = True


  Text1.SetFocus


End Sub
Private Sub Text1_Change()
  ' chargemant de la cellule avec le contenu du textbox
  grid.Text = Text1.Text


End Sub

3 réponses

amalVB Messages postés 20 Date d'inscription mardi 13 décembre 2005 Statut Membre Dernière intervention 3 mai 2007
28 avril 2007 à 13:35
salut
je pense que le code si dessous vas t'aider à calculer le total,coefficient,partemploye,et partemployeur ,à toi de le terminer car les autres chose je ne les ai pas compris
voila
Dim i As Variant
Dim coefficient As Variant
Dim partemploye As Variant
Dim partemployeur As Variant
Dim total As Variant
Dim Valeur As Variant
Dim notehonoraire As Variant
Dim datedevisite As String
Dim actes As String
Dim visa As String


Dim lastRowFocus, LastColFocus As Long
Dim passer As Boolean


Private Sub grid_Click()
 ' positionnement du textbox sur la cellule


  Text1.Left = grid.CellLeft


  Text1.Top = grid.CellTop


  ' dimensionnement du textbox aux dimensions de la cellule


  Text1.Width = grid.CellWidth


  'Text1.Height = grid.CellHeight


  ' initialisation du texte avec celui contenu dan la cellule


  Text1.Text = grid.Text


  ' textbox visible avec le focus


  Text1.Visible = True


  Text1.SetFocus
'calculer
LastColFocus = grid.Col
lastRowFocus = grid.Row


End Sub


Private Sub Text1_Change()
  ' chargemant de la cellule avec le contenu du textbox
 passer = True
  grid.Text = Text1.Text


End Sub


Private Sub Text1_GotFocus()
coefficient = 0
total = 0
partemploye = 0
partemployeur = 0
For i = 1 To 23
    coefficient = coefficient + Val(grid.TextMatrix(i, 3))
    grid.TextMatrix(24, 3) = coefficient
    total = total + Val(grid.TextMatrix(i, 4))
    grid.TextMatrix(24, 4) = total
    partemploye = partemploye + Val(grid.TextMatrix(i, 5))
    grid.TextMatrix(24, 5) = partemploye
    partemployeur = partemployeur + Val(grid.TextMatrix(i, 6))
    grid.TextMatrix(24, 6) = partemployeur
Next
End Sub


Private Sub Text1_LostFocus()If LastColFocus 3 And passer True Then
    grid.TextMatrix(lastRowFocus, 4) = Val(grid.TextMatrix(lastRowFocus, 3)) * 1200
    grid.TextMatrix(lastRowFocus, 5) = Val((grid.TextMatrix(lastRowFocus, 4) * 20 / 100))
    grid.TextMatrix(lastRowFocus, 6) = Val((grid.TextMatrix(lastRowFocus, 4) * 80 / 100))
   
End If
End Sub
0
Gamaldiouf Messages postés 43 Date d'inscription lundi 30 octobre 2006 Statut Membre Dernière intervention 16 février 2008
28 avril 2007 à 14:44
Bonjour AmalVB

je suis content de votre réponse je suis débutant dans la programmation depuis plus de semaine je ,n'arrive à calcul les lignes et les colonnes .
j'ai testé le code que vous m'avez envoyé mais il ya débogage à ce niveau :
vous avez définie lastRowFocus, LastColFocus au dessus mais il me dit variable non définie (LastColFocus, lastRowFocus ) dans  Private Sub grid_Click()
'calculer
LastColFocus = grid.Col
lastRowFocus = grid.Row

je vous envoi un extait du code pour la correction je sais comment le définir dand le grid merci

Dim lastRowFocus, LastColFocus As Long
Dim passer As Boolean


Private Sub grid_Click()
 ' positionnement du textbox sur la cellule


  Text1.Left = grid.CellLeft


  Text1.Top = grid.CellTop


  ' dimensionnement du textbox aux dimensions de la cellule


  Text1.Width = grid.CellWidth


  'Text1.Height = grid.CellHeight


  ' initialisation du texte avec celui contenu dan la cellule


  Text1.Text = grid.Text


  ' textbox visible avec le focus


  Text1.Visible = True


  Text1.SetFocus
'calculer
LastColFocus = grid.Col  
lastRowFocus = grid.Row
end sud
0
amalVB Messages postés 20 Date d'inscription mardi 13 décembre 2005 Statut Membre Dernière intervention 3 mai 2007
28 avril 2007 à 15:11
est ce que ça fonctionner pour toi?
0
Rejoignez-nous