Ver Mensaje Individual
  #15  
Antiguo 06-03-2007
keikurono keikurono is offline
Miembro
 
Registrado: mar 2007
Posts: 16
Reputación: 0
keikurono Va por buen camino
aver que les parece este codigo....
Solucion al problema de la calcu en delphi!!!!!
Código Delphi [-]
 
unit calcu_Until;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
arreg1=array[1..100,1..100] of string;
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
w:boolean;
B:arreg1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
    begin
        w:=true;
    end;
procedure TForm1.Button2Click(Sender: TObject);//boton suma
    begin
       if edit1.Text<>'' then
            if W=true then
                begin
                   B[1,1]:=edit1.Text;
                   B[1,2]:='+';
                   W:=false;
                   edit1.Text:='';
                   edit1.SetFocus;
                end
           else
               begin
                     B[2,1]:=edit1.Text;
                          if B[1,2]='+' then
                                B[1,1]:=floattostr(strtofloat(B[1,1])+strtofloat(B[2,1]));
                          if B[1,2]='/' then
                                if B[2,1]<>'0' then
                                       B[1,1]:=floattostr(strtofloat(B[1,1])/strtofloat(B[2,1]))
                                else
                                       MESSAGEDLG('EL DIVIDENDO DEVE DE SER <>0',mTInformation,[mbok],0);
                          if B[1,2]='-' then
                                B[1,1]:=floattostr(strtofloat(B[1,1])-strtofloat(B[2,1]));
                          if B[1,2]='*' then
                                B[1,1]:=floattostr(strtofloat(B[1,1])*strtofloat(B[2,1]));
                    B[1,2]:='+';
                    edit1.Text:=B[1,1];
                    edit1.SetFocus;
                    W:=false;
                    B[2,1]:='';
             end;
 
end;
procedure TForm1.Button3Click(Sender: TObject);//BOTON RESTA
begin
       if edit1.Text<>'' then
              if W=true then
                  begin
                      B[1,1]:=edit1.Text;
                      B[1,2]:='-';
                      W:=false;
                      edit1.Text:='';
                      edit1.SetFocus;
                 end
             else
                  begin
                       B[2,1]:=edit1.Text;
                            if B[1,2]='+' then
                                  B[1,1]:=floattostr(strtofloat(B[1,1])+strtofloat(B[2,1]));
                            if B[1,2]='-' then
                                  B[1,1]:=floattostr(strtofloat(B[1,1])-strtofloat(B[2,1]));
                            if B[1,2]='*' then
                                  B[1,1]:=floattostr(strtofloat(B[1,1])*strtofloat(B[2,1]));
                            if B[1,2]='/' then
                                  if B[2,1]<>'0' then
                                      B[1,1]:=floattostr(strtofloat(B[1,1])/strtofloat(B[2,1]))
                                  else
                                      MESSAGEDLG('EL DIVIDENDO DEVE DE SER DISTINTO DE CERO',mTInformation,[mbok],0);                            
                            B[1,2]:='-';
                            edit1.Text:=B[1,1];
                            edit1.SetFocus;
                            W:=false;
                            B[2,1]:='';
                    end;
end;
procedure TForm1.Button4Click(Sender: TObject);//BOTON POR
     begin
         if edit1.Text<>'' then
              if W=true then 
                 begin
                     B[1,1]:=edit1.Text;
                     B[1,2]:='*';
                     W:=false;
                     edit1.Text:='';
                     edit1.SetFocus;
                 end
             else
                 begin
                      B[2,1]:=edit1.Text;
                            if B[1,2]='+' then
                                  B[1,1]:=floattostr(strtofloat(B[1,1])+strtofloat(B[2,1]));
                            if B[1,2]='-' then
                                  B[1,1]:=floattostr(strtofloat(B[1,1])-strtofloat(B[2,1]));
                            if B[1,2]='*' then
                                  B[1,1]:=floattostr(strtofloat(B[1,1])*strtofloat(B[2,1]));
                            if B[1,2]='/' then
                                   if B[2,1]<>'0' then
                                           B[1,1]:=floattostr(strtofloat(B[1,1])/strtofloat(B[2,1]))
                                   else
                                           MESSAGEDLG('EL DIVIDENDO DEVE DE SER DISTINTO DE CERO',mTInformation,[mbok],0);

                            B[1,2]:='*';
                            edit1.Text:=B[1,1];
                            edit1.SetFocus;
                            W:=false;
                            B[2,1]:='';
                   end;
end;
procedure TForm1.Button5Click(Sender: TObject);//boton entre
  begin
       if edit1.Text<>'' then
             if W=true then
                 begin
                      B[1,1]:=edit1.Text;
                      B[1,2]:='/';
                      W:=false;
                      edit1.Text:='';
                      edit1.SetFocus;
                 end
             else
                 begin
                      B[2,1]:=edit1.Text;
                           if B[1,2]='+' then
                                  B[1,1]:=floattostr(strtofloat(B[1,1])+strtofloat(B[2,1]));
                           if B[1,2]='-' then
                                  B[1,1]:=floattostr(strtofloat(B[1,1])-strtofloat(B[2,1]));
                           if B[1,2]='*' then
                                  B[1,1]:=floattostr(strtofloat(B[1,1])*strtofloat(B[2,1]));
                           if B[1,2]='/' then
                                 if B[2,1]<>'0' then
                                       B[1,1]:=floattostr(strtofloat(B[1,1])/strtofloat(B[2,1]))
                           else
                                 MESSAGEDLG('EL DIVIDENDO DEVE DE SER DISTINTO DE CERO',mTInformation,[mbok],0);
                           
                       B[1,2]:='/';
                       edit1.Text:=B[1,1];
                       edit1.SetFocus;
                       W:=false;
                       B[2,1]:='';
               end;
 
end;
procedure TForm1.Button1Click(Sender: TObject);//boton igual 
   begin
        if (B[2,1]='')and(B[1,2]<>'')then
             B[2,1]:=edit1.Text;
        if B[1,2]='+' then
             B[1,1]:=floattostr(strtofloat(B[1,1])+strtofloat(B[2,1]));
        if B[1,2]='-' then
             B[1,1]:=floattostr(strtofloat(B[1,1])-strtofloat(B[2,1]));
        if B[1,2]='*' then
             B[1,1]:=floattostr(strtofloat(B[1,1])*strtofloat(B[2,1]));
        if B[1,2]='/' then
             if B[2,1]<>'0' then
                  B[1,1]:=floattostr(strtofloat(B[1,1])/strtofloat(B[2,1]))
             else
                  MESSAGEDLG('EL DIVIDENDO DEVE DE SER DISTINTO DE CERO',mTInformation,[mbok],0);
        B[2,1]:='';
        B[1,2]:='';
        edit1.Text:=B[1,1];
        w:=TRUE;
 
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
  begin
       if not (key in ['0'..'9',#8]) then
          begin
              key:=#0;
              beep;
          end;
  end;
end.

Última edición por keikurono fecha: 10-03-2007 a las 06:36:13.
Responder Con Cita