bensalahriadh
Messages postés17Date d'inscriptionmardi 5 décembre 2006StatutMembreDernière intervention 3 mai 2008
-
10 avril 2008 à 02:17
bensalahriadh
Messages postés17Date d'inscriptionmardi 5 décembre 2006StatutMembreDernière intervention 3 mai 2008
-
14 avril 2008 à 15:08
Salut,
voila mon problème:
J'ai utilisé le "stringGrid" et j'ai comparé deux nombres puis j'ai calculer leur somme .
Voilàle le codeque j'ai tapé :
if ( StringGrid1.cells[0,0] >= StringGrid1.cells[1,0] ) then
begin
pl2:=Strtofloat(StringGrid1.cells[0,0])+ 2;
StringGrid1.cells[2,01]:=floattostr(pl2);
end;
exmple:
lorsque je tape 7 et 5 le resultat est 9
mais lorsque je tape 9 et 14 (je tape n'importe quel valeur de deux chiffres ou plus) le resultat est 11
Cirec
Messages postés3833Date d'inscriptionvendredi 23 juillet 2004StatutModérateurDernière intervention18 septembre 202250 13 avril 2008 à 17:18
Toujours pas réglé ce problème ?
Commence déjà par modifier ceci :
procedure TForm1.Button3Click(Sender: TObject);
var k,l,i,n : integer;
var j,a,pl1,pl2,pl: Integer;
begin
if (edit5.Text= '') or (edit6.Text='') or (edit1.Text='') then
begin
showmessage ('remplir les champs S.V.P ');
//Application.Run; ceci n'a rien à faire ici
// remplace le par :
Exit;
end
else
.....
puis tu change tous les StrToFloat en StrToInt et tous les FloatToStr en IntToStr
et regarde si ça fonctionne comme ça
Mais tu devrait réecrire ton code en séparant plus les défférentes étapes ... parce que là c'est un peut le wide (le bordel)
bensalahriadh
Messages postés17Date d'inscriptionmardi 5 décembre 2006StatutMembreDernière intervention 3 mai 2008 10 avril 2008 à 12:41
j'ai remplacé if ( StringGrid1.cells[0,0] >= StringGrid1.cells[1,0] ) then
par if ( strtofloat(StringGrid1.cells[0,0]) >= strtofloat(StringGrid1.cells[1,0] ) ) then
bensalahriadh
Messages postés17Date d'inscriptionmardi 5 décembre 2006StatutMembreDernière intervention 3 mai 2008 10 avril 2008 à 12:52
j'ai ajouté le "else"
if ( strtofloat(StringGrid1.cells[0,0]) >= strtofloat(StringGrid1.cells[1,0] ) ) then
begin
pl2:=Strtofloat(StringGrid1.cells[0,0])+ 2;
StringGrid1.cells[2,01]:=floattostr(pl2);
end
else
begin
pl2:=Strtofloat(StringGrid1.cells[i-1,n+1])+Strtofloat(fabbac.Items[n]);
StringGrid1.cells[i,n+1]:=floattostr(pl2);
end;
bensalahriadh
Messages postés17Date d'inscriptionmardi 5 décembre 2006StatutMembreDernière intervention 3 mai 2008 10 avril 2008 à 12:52
j'ai ajouté le "else"
if ( strtofloat(StringGrid1.cells[0,0]) >= strtofloat(StringGrid1.cells[1,0] ) ) then
begin
pl2:=Strtofloat(StringGrid1.cells[0,0])+ 2;
StringGrid1.cells[2,01]:=floattostr(pl2);
end
else
begin
pl2:=Strtofloat(StringGrid1.cells[i-1,n+1])+Strtofloat(fabbac.Items[n]);
StringGrid1.cells[i,n+1]:=floattostr(pl2);
end;
bensalahriadh
Messages postés17Date d'inscriptionmardi 5 décembre 2006StatutMembreDernière intervention 3 mai 2008 10 avril 2008 à 12:55
je suis desolé pour le message précedant
voila le code correcte :
if ( strtofloat(StringGrid1.cells[0,0]) >= strtofloat(StringGrid1.cells[1,0] ) ) then
begin
pl2:=Strtofloat(StringGrid1.cells[0,0])+ 2;
StringGrid1.cells[2,01]:=floattostr(pl2);
end
else
begin
pl2:=Strtofloat(StringGrid1.cells[0,0])+4;
StringGrid1.cells[2,01]:=floattostr(pl2);
end;
bensalahriadh
Messages postés17Date d'inscriptionmardi 5 décembre 2006StatutMembreDernière intervention 3 mai 2008 10 avril 2008 à 13:21
le probleme qu'avec cette condition
if ( strtofloat(StringGrid1.cells[0,0]) >= strtofloat(StringGrid1.cells[1,0] ) ) then
il n'y a aucune resultat (cad lorsque on ajoute le "strtofloat ")
bensalahriadh
Messages postés17Date d'inscriptionmardi 5 décembre 2006StatutMembreDernière intervention 3 mai 2008 10 avril 2008 à 14:08
lorsque je tape ce code :
if ( StringGrid1.cells[0,0]) >= StringGrid1.cells[1,0] ) ) then
begin
pl2:=Strtofloat(StringGrid1.cells[0,0])+ 2;
StringGrid1.cells[2,1]:=floattostr(pl2);
end
else
begin
pl2:=Strtofloat(StringGrid1.cells[1,0])+4;
StringGrid1.cells[2,1]:=floattostr(pl2);
end;
lorsque je tape deux valeurs composé chacun d'un seul chiffre le resultat est correcte ( 8 et 6 le resultat est 10)
mais lorsque je tape deux valeurs ,le premier est composé d'un seul chiffre et le deuxieme de deux chiffres le resultat est fausse ( 9 et 12 le resultat est 11 car la comparaison est faite entre 9 et la premiere chiffre du deuxieme valeur ( 1 ))
Cirec
Messages postés3833Date d'inscriptionvendredi 23 juillet 2004StatutModérateurDernière intervention18 septembre 202250 10 avril 2008 à 14:35
Salut,
1° il est placé ou ton code (dans quel évènement) ? (le problème peut venir de là)
2° si c'est que des entiers que tu entres dans les cellules, tu peux remplacer
StrToFloat par StrToInt
et bien sur pl2 est de Type Integer. (Var pl2 : Integer)
Cirec
Messages postés3833Date d'inscriptionvendredi 23 juillet 2004StatutModérateurDernière intervention18 septembre 202250 10 avril 2008 à 19:44
c'est toi qui demande un peut de clareté alors que tout le monde te demande plus de précision, tu nous remets toujours le même morceau de code ... c'est le monde à l'enver
C'est pourtant simple ...
ce code se trouve bien dans une procedure, et c'est, généralement, un évènement (OnClick, OnKey etc etc) ... donne nous le nom de la procedure
encore mieux donne nous la procedure complète.
et c'est pas la peine d'écrire en gros et en gras on est pas aveugle
bensalahriadh
Messages postés17Date d'inscriptionmardi 5 décembre 2006StatutMembreDernière intervention 3 mai 2008 10 avril 2008 à 22:05
voilà tout le code de mon programme :
procedure TForm1.Button3Click(Sender: TObject);
var k,l,i,n : integer;
var j,a,pl1,pl2,pl:real;
begin
if (edit5.Text='') or (edit6.Text='') or (edit1.Text='') then
begin
showmessage ('remplir les champs S.V.P ');
Application.Run;
end
else
ListBox1.Items.add(refart.Text);
ListBox2.Items.add(Edit5.Text);
nbrebac.Items.add(Edit6.Text);
listbox3.Items.add(mach.Text);
ListBox7.Items.add(Edit1.Text);
j:=((60/(StrToInt(Edit5.Text)))*StrToInt(Edit1.Text))/60;
fabbac.Items.add(floattostr(j)) ;
for i:=0 to listbox1.Count-1 do
begin
a:=(strTofloat(nbrebac.Items[i])*strTofloat(fabbac.Items[i])) ;
chargeart.Items[i]:= floattostr(a);
end;
for l:=0 to fabbac.Count-1 do
begin
StringGrid1.Cells[0,l+1]:=listbox3.Items[l];
StringGrid1.Cells[1,0]:='Bac N°1';
pl:=pl + (Strtofloat(fabbac.Items[l]));
StringGrid1.cells[1,l+1]:=floattostr(pl);
for k:=2 to col do
begin
StringGrid1.Cells[k,0]:='Bac N°'+inttostr(k);
pl1:=Strtofloat(StringGrid1.cells[k-1,1])+Strtofloat(fabbac.Items[0]);
StringGrid1.cells[k,1]:=floattostr(pl1);
end;
for n:=1 to fabbac.Count-1 do
begin
for i:=2 to col do
if (StringGrid1.cells[i,n]) >= (StringGrid1.cells[i-1,n+1])then
begin
pl2:=Strtofloat(StringGrid1.cells[i,n])+Strtofloat(fabbac.Items[n]);
StringGrid1.cells[i,n+1]:=floattostr(pl2);
end
else
begin
pl2:=Strtofloat(StringGrid1.cells[i-1,n+1])+Strtofloat(fabbac.Items[n]);
StringGrid1.cells[i,n+1]:=floattostr(pl2);
end;