Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 20-03-2014
Olenkaguilar Olenkaguilar is offline
Miembro
NULL
 
Registrado: may 2013
Posts: 20
Poder: 0
Olenkaguilar Va por buen camino
Suma de Edit

Buenas tarde mi consulta es la siguiente tengo 3 Edit, al ingresar un (valor en el Edit1 * valor en el Edit2)+70 = Edit3, osea que automaticamente me aparesca el resultado en el Edit3. Bueno lo intenté al compilar me da un error Project Project1.exe raised exception class EconvertError with Message''''is not a valide integer value., acepto los errores y me funciona bien pero no puedo sumarle el 70

Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
var
 opcion: integer;
begin
 opcion:= StrToInt(Edit1.Text);

 case opcion of
  1: begin
    Edit3.Text := FloatToStr(0.2 * StrToFloatDef(Edit2.Text,0)); // aquí quiero sumarle 70
  end;
  2: begin
    Edit3.Text := FloatToStr(0.35 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    3: begin
    Edit3.Text := FloatToStr(0.5 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    4: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    5: begin
    Edit3.Text := FloatToStr(0.68 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    6: begin
    Edit3.Text := FloatToStr(0.7 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    7: begin
    Edit3.Text := FloatToStr(0.7 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    8: begin
    Edit3.Text := FloatToStr(0.7 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    9: begin
    Edit3.Text := FloatToStr(0.68 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    10: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    11: begin
    Edit3.Text := FloatToStr(0.5 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    12: begin
    Edit3.Text := FloatToStr(0.35 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    13: begin
    Edit3.Text := FloatToStr(0.25 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    14: begin
    Edit3.Text := FloatToStr(0.15 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    15: begin
    Edit3.Text := FloatToStr(0.05 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    16: begin
    Edit3.Text := FloatToStr(0.15 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    17: begin
    Edit3.Text := FloatToStr(0.2 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    18: begin
    Edit3.Text := FloatToStr(0.25 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    19: begin
    Edit3.Text := FloatToStr(0.5 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    20: begin
    Edit3.Text := FloatToStr(0.55 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    21: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    22: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    23: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    24: begin
    Edit3.Text := FloatToStr(0.65 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    25: begin
    Edit3.Text := FloatToStr(0.67 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    26: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    27: begin
    Edit3.Text := FloatToStr(0.5 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    28: begin
    Edit3.Text := FloatToStr(0.45 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    29: begin
    Edit3.Text := FloatToStr(0.28 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    30: begin
    Edit3.Text := FloatToStr(0.18 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    31: begin
    Edit3.Text := FloatToStr(0.1 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
    32: begin
    Edit3.Text := FloatToStr(0.1 * StrToFloatDef(Edit2.Text,0));// aquí quiero sumarle 70
  end;
 end;

end;

end.
Responder Con Cita
  #2  
Antiguo 20-03-2014
Avatar de kapcomx
kapcomx kapcomx is offline
Miembro
 
Registrado: jun 2007
Ubicación: Puebla México
Posts: 350
Poder: 17
kapcomx Va por buen camino
form create

te da ese error por que lo estas programando en el evento form create
__________________
un tipo al cual la sociedad no le tiene el mas mínimo respeto no puede ser presidente....
Responder Con Cita
  #3  
Antiguo 20-03-2014
Avatar de radenf
radenf radenf is offline
Miembro
 
Registrado: oct 2007
Ubicación: Viña del Mar,Chile
Posts: 608
Poder: 17
radenf Va por buen camino
Hola Olenkaguilar:

Para corregir tu problema te sugiero que en vez de utilizar un Edit como Edit1 uses un SpinEdit de la paleta samples ( si quieres lo puedes llamar Edit1 y así no necesitas modificar tu código) y le asignes como minvalue 1 y como maxvalue 32, que son tus opciones y que asignes tu código además al evento OnChange del SpinEdit.
Para sumar 70 sólo debes incluir +70 en el valor del Edit2, de la siguiente manera:

Código Delphi [-]
Edit3.Text := FloatToStr(0.35 * StrToFloatDef(Edit2.Text,0)+70);

Ojalá te haya podido ayudar

Salu2
Responder Con Cita
  #4  
Antiguo 20-03-2014
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Olenkaguilar.

Lo que te sugiere radenf es muy buena opción, sobre todo por que te ahorras controlar los valores de un edit.

Y para organizár y reducir el código podes hacer:
Código Delphi [-]
//(*)
procedure TForm1.FormCreate(Sender: TObject);
begin
  with SpinEdit1 do
  begin
    MinValue:= 1;
    MaxValue:= 32;
    Increment:= 1;
    OnChange:= SpinAndEditChange;
  end;
  Edit2.Text:= '1'; // o cero...
  Edit2.OnChange:= SpinAndEditChange;
end;

procedure TForm1.SpinAndEditChange(Sender: TObject);
const
   VEC: array[1..32] of Single =
   (0.2 , 0.35, 0.5 , 0.6 , 0.68, 0.7 , 0.7 , 0.7 ,
    0.68, 0.6 , 0.5 , 0.35, 0.25, 0.15, 0.05, 0.15,
    0.2 , 0.25, 0.5 , 0.55, 0.6 , 0.6 , 0.6 , 0.65,
    0.67, 0.6 , 0.5 , 0.45, 0.28, 0.18, 0.1 , 0.1);
begin
  Edit3.Text:= FormatFloat('0.000', (VEC[SpinEdit1.Value]*StrToFloatDef(Edit2.Text, 0))+70);
end;

(*) Todo el código del evento OnCreate lo podes evitar configurando las propiedades en tiempo de diseño con el Object Inspector.

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #5  
Antiguo 21-03-2014
Olenkaguilar Olenkaguilar is offline
Miembro
NULL
 
Registrado: may 2013
Posts: 20
Poder: 0
Olenkaguilar Va por buen camino
Hola de nuevo

Muchas a radenf y a ecfisa, lo que me indico randenf está bien, pero yo cometí un error en dar mi code, es por eso que me perdí al ver el code de ecfisa. vuelvo a colocar mi código:

Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
begin
   with SpinEdit1 do
  begin
    MinValue:= 1;
    MaxValue:= 32;
    Increment:= 1;
    OnChange:= SpinAndEditChange;
  end;

  Edit2.OnChange:= SpinAndEditChange;
end;

procedure TForm1.SpinAndEditChange(Sender: TObject);
var                                                    //
 opcion: integer;
begin                                                 //
 opcion:= StrToInt(SpinEdit1.Text);

 case opcion of
  1: begin
    Edit3.Text := FloatToStr(0.2 * StrToFloatDef(Edit2.Text,0)+70);
  end;
  2: begin
    Edit3.Text := FloatToStr(0.35 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    3: begin
    Edit3.Text := FloatToStr(0.5 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    4: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    5: begin
    Edit3.Text := FloatToStr(0.68 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    6: begin
    Edit3.Text := FloatToStr(0.7 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    7: begin
    Edit3.Text := FloatToStr(0.7 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    8: begin
    Edit3.Text := FloatToStr(0.7 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    9: begin
    Edit3.Text := FloatToStr(0.68 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    10: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    11: begin
    Edit3.Text := FloatToStr(0.5 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    12: begin
    Edit3.Text := FloatToStr(0.35 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    13: begin
    Edit3.Text := FloatToStr(0.25 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    14: begin
    Edit3.Text := FloatToStr(0.15 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    15: begin
    Edit3.Text := FloatToStr(0.05 * StrToFloatDef(Edit2.Text,0)+70);
  end;
    16: begin
    Edit3.Text := FloatToStr(70 - 0.15 * StrToFloatDef(Edit2.Text,0));
  end;
    17: begin
    Edit3.Text := FloatToStr(70 - 0.2 * StrToFloatDef(Edit2.Text,0));
  end;
    18: begin
    Edit3.Text := FloatToStr(70 - 0.25 * StrToFloatDef(Edit2.Text,0));
  end;
    19: begin
    Edit3.Text := FloatToStr(70 - 0.5 * StrToFloatDef(Edit2.Text,0));
  end;
    20: begin
    Edit3.Text := FloatToStr(70 - 0.55 * StrToFloatDef(Edit2.Text,0));
  end;
    21: begin
    Edit3.Text := FloatToStr(70 - 0.6 * StrToFloatDef(Edit2.Text,0));
  end;
    22: begin
    Edit3.Text := FloatToStr(70 - 0.6 * StrToFloatDef(Edit2.Text,0));
  end;
    23: begin
    Edit3.Text := FloatToStr(70 - 0.6 * StrToFloatDef(Edit2.Text,0));
  end;
    24: begin
    Edit3.Text := FloatToStr(70 - 0.65 * StrToFloatDef(Edit2.Text,0));
  end;
    25: begin
    Edit3.Text := FloatToStr(70 - 0.67 * StrToFloatDef(Edit2.Text,0));
  end;
    26: begin
    Edit3.Text := FloatToStr(70 - 0.6 * StrToFloatDef(Edit2.Text,0));
  end;
    27: begin
    Edit3.Text := FloatToStr(70 - 0.5 * StrToFloatDef(Edit2.Text,0));
  end;
    28: begin
    Edit3.Text := FloatToStr(70 - 0.45 * StrToFloatDef(Edit2.Text,0));
  end;
    29: begin
    Edit3.Text := FloatToStr(70 - 0.28 * StrToFloatDef(Edit2.Text,0));
  end;
    30: begin
    Edit3.Text := FloatToStr(70 - 0.18 * StrToFloatDef(Edit2.Text,0));
  end;
    31: begin
    Edit3.Text := FloatToStr(70 - 0.1 * StrToFloatDef(Edit2.Text,0));
  end;
    32: begin
    Edit3.Text := FloatToStr(0.1 * StrToFloatDef(Edit2.Text,0)+70);
  end;


 end;  //

end;
end.

Osea en algunos les estoy agregando 70 y en otros al 70 le estoy restando( por ejemplo en la opción 31 le estoy restando al 70 y en la opción 32 le estoy agregando 70)
Ahora le eh puesto 2 radiobuttons. quisiera que al iniciar el programa siempre este seleccionado el radiobutton1 y que ejecute el código de arriba y si cambio al radiobutton2 ejecute este código( es lo mismo si no que cambia a lo que estado agregando 70, al 70 ahora le estan restando y viceversa):

Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
begin
   with SpinEdit1 do
  begin
    MinValue:= 1;
    MaxValue:= 32;
    Increment:= 1;
    OnChange:= SpinAndEditChange;
  end;

  Edit2.OnChange:= SpinAndEditChange;
end;

procedure TForm1.SpinAndEditChange(Sender: TObject);
var                                                    //
 opcion: integer;
begin                                                 //
 opcion:= StrToInt(SpinEdit1.Text);

 case opcion of
  1: begin
    Edit3.Text := FloatToStr(70 - 0.2 * StrToFloatDef(Edit2.Text,0));
  end;
  2: begin
    Edit3.Text := FloatToStr(70 - 0.35 * StrToFloatDef(Edit2.Text,0));
  end;
    3: begin
    Edit3.Text := FloatToStr(70 - 0.5 * StrToFloatDef(Edit2.Text,0));
  end;
    4: begin
    Edit3.Text := FloatToStr(70 - 0.6 * StrToFloatDef(Edit2.Text,0));
  end;
    5: begin
    Edit3.Text := FloatToStr(70 - 0.68 * StrToFloatDef(Edit2.Text,0));
  end;
    6: begin
    Edit3.Text := FloatToStr(70 - 0.7 * StrToFloatDef(Edit2.Text,0));
  end;
    7: begin
    Edit3.Text := FloatToStr(70 - 0.7 * StrToFloatDef(Edit2.Text,0));
  end;
    8: begin
    Edit3.Text := FloatToStr(70 - 0.7 * StrToFloatDef(Edit2.Text,0));
  end;
    9: begin
    Edit3.Text := FloatToStr(70 - 0.68 * StrToFloatDef(Edit2.Text,0));
  end;
    10: begin
    Edit3.Text := FloatToStr(70 - 0.6 * StrToFloatDef(Edit2.Text,0));
  end;
    11: begin
    Edit3.Text := FloatToStr(70 - 0.5 * StrToFloatDef(Edit2.Text,0));
  end;
    12: begin
    Edit3.Text := FloatToStr(70 - 0.35 * StrToFloatDef(Edit2.Text,0));
  end;
    13: begin
    Edit3.Text := FloatToStr(70 - 0.25 * StrToFloatDef(Edit2.Text,0));
  end;
    14: begin
    Edit3.Text := FloatToStr(70 - 0.15 * StrToFloatDef(Edit2.Text,0));
  end;
    15: begin
    Edit3.Text := FloatToStr(70 - 0.05 * StrToFloatDef(Edit2.Text,0));
  end;
    16: begin
    Edit3.Text := FloatToStr(0.15 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    17: begin
    Edit3.Text := FloatToStr(0.2 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    18: begin
    Edit3.Text := FloatToStr(0.25 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    19: begin
    Edit3.Text := FloatToStr(0.5 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    20: begin
    Edit3.Text := FloatToStr(0.55 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    21: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    22: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    23: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    24: begin
    Edit3.Text := FloatToStr( 0.65 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    25: begin
    Edit3.Text := FloatToStr(0.67 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    26: begin
    Edit3.Text := FloatToStr(0.6 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    27: begin
    Edit3.Text := FloatToStr(0.5 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    28: begin
    Edit3.Text := FloatToStr(0.45 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    29: begin
    Edit3.Text := FloatToStr(0.28 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    30: begin
    Edit3.Text := FloatToStr(0.18 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    31: begin
    Edit3.Text := FloatToStr(0.1 * StrToFloatDef(Edit2.Text,0) + 70);
  end;
    32: begin
    Edit3.Text := FloatToStr(70 - 0.1 * StrToFloatDef(Edit2.Text,0));
  end;


 end;  //

end;
end.
Responder Con Cita
  #6  
Antiguo 21-03-2014
Olenkaguilar Olenkaguilar is offline
Miembro
NULL
 
Registrado: may 2013
Posts: 20
Poder: 0
Olenkaguilar Va por buen camino
Me olvidaba

En un SpinEdit no puedo agregar manualmente los números, me sale error al parecer no puede estar vacío
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Armar Edit a partir de otros Edit giulichajari Varios 5 13-03-2014 21:15:11
Suma en un Edit lily21 Varios 7 11-01-2010 11:01:52
Suma StrToInt para Edit vacios cocke C++ Builder 8 28-11-2006 09:19:40
problemas con el el .Edit: qryCONSULTA.Edit McRose Conexión con bases de datos 3 07-06-2005 15:46:39
mostrar suma alachaise PHP 1 14-04-2005 15:57:05


La franja horaria es GMT +2. Ahora son las 00:02:04.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi