GARANTIR DESCONTO

Fórum Ordenar valores em Edits... #242875

13/07/2004

0

Tenho 6 Edits, onde dentro de cada edit, o computador vai sortear um número aleatoriamente de 1 a 100. Quero ordenar os Valores nos Edits do Menor para o Maior(o Problema é este). Consegui indentificar o Menor Número dentre os 6 Edits, onde ele estiver... O problema maior é ordena-los.


Código que acha o menor numero dentre os 6 Edits:
Procedure TForm1.Ordena; Var Temp: array[1..6] of Integer; I: Integer; Begin Temp[1] := StrToInt(Dez_1.Text); Temp[2] := StrToInt(Dez_2.Text); Temp[3] := StrToInt(Dez_3.Text); Temp[4] := StrToInt(Dez_4.Text); Temp[5] := StrToInt(Dez_5.Text); Temp[6] := StrToInt(Dez_6.Text); // 1º Dezena if (Dez_1.Text < Dez_2.Text) and ( Dez_1.Text < Dez_3.Text) and (Dez_1.Text < Dez_4.Text) and (Dez_1.Text < Dez_5.Text) and (Dez_1.Text < Dez_6.Text) Then Apo_1.Text := IntToStr(Temp[1]); if (Dez_2.Text < Dez_1.Text) and ( Dez_2.Text < Dez_3.Text) and (Dez_2.Text < Dez_4.Text) and (Dez_2.Text < Dez_5.Text) and (Dez_2.Text < Dez_6.Text) Then Apo_1.Text := IntToStr(Temp[2]); if (Dez_3.Text < Dez_1.Text) and ( Dez_3.Text < Dez_2.Text) and (Dez_3.Text < Dez_4.Text) and (Dez_3.Text < Dez_5.Text) and (Dez_3.Text < Dez_6.Text) Then Apo_1.Text := IntToStr(Temp[3]); if (Dez_4.Text < Dez_1.Text) and ( Dez_4.Text < Dez_2.Text) and (Dez_4.Text < Dez_3.Text) and (Dez_4.Text < Dez_5.Text) and (Dez_4.Text < Dez_6.Text) Then Apo_1.Text := IntToStr(Temp[4]); if (Dez_5.Text < Dez_1.Text) and ( Dez_5.Text < Dez_2.Text) and (Dez_5.Text < Dez_3.Text) and (Dez_5.Text < Dez_4.Text) and (Dez_5.Text < Dez_6.Text) Then Apo_1.Text := IntToStr(Temp[5]); if (Dez_6.Text < Dez_1.Text) and ( Dez_6.Text < Dez_2.Text) and (Dez_6.Text < Dez_3.Text) and (Dez_6.Text < Dez_4.Text) and (Dez_6.Text < Dez_5.Text) Then Apo_1.Text := IntToStr(Temp[6]);



Alves

Alves

Responder

Posts

13/07/2004

Beppe

Jogue-os numa stringlist e use a ordenação da lista.


Responder

Gostei + 0

13/07/2004

Alves

mas depois posso coloca-los nos edits novamente ??

Jogue-os numa stringlist e use a ordenação da lista.



Responder

Gostei + 0

13/07/2004

Beppe

Sim...Edit1.Text := StringList1[0];
Edit2.Text := StringList1[1];
...


Responder

Gostei + 0

13/07/2004

Alves

Valeu Beppe, vou testar... Até +

Sim...Edit1.Text := StringList1[0]; Edit2.Text := StringList1[1]; ...



Responder

Gostei + 0

13/07/2004

Marcelo Saviski

Tem uma outra dica p/ ordenar um array de inteiros [url=http://delphiforum.icft.com.br/forum/viewtopic.php?t=34514&highlight=ordenar+inteiros]aqui[/url] mesmo no fóruns, já que vc joga os valores num array pode ser útil, já que p/ a string list
´20´ > ´100´

[2]0
[1]00


Responder

Gostei + 0

14/07/2004

Alves

Dei uma boa olhada na sua dica tbem Marcelo, mas achei bem mais simples usar a TStringList, ficou perfeito com o eu queira fazer.

Abaixo segue o código básico de como ficou. O Apo_1.text .. Apo_6.text, é onde coloco os valores ja ordenados.

Procedure TForm1.Ordena; Var Lista: TStringList; Begin Try Lista := TStringList.Create; Lista.Add(Dez_1.Text); Lista.Add(Dez_2.Text); Lista.Add(Dez_3.Text); Lista.Add(Dez_4.Text); Lista.Add(Dez_5.Text); Lista.Add(Dez_6.Text); Lista.Sort; ShowMessage(Lista.Text); Apo_1.Text := Lista[0]; Apo_2.Text := Lista[1]; Apo_3.Text := Lista[2]; Apo_4.Text := Lista[3]; Apo_5.Text := Lista[4]; Apo_6.Text := Lista[5]; Finally Lista.Free; end; end;



Responder

Gostei + 0

14/07/2004

Marcelo Saviski

se deu certo blz, é que dependendo do formato do número, pode dar problemas, se eles tiverem numeros de casas decimais diferentes, tipo:

20 > 1000000

pq p/ a string, ela ordena 1º pelo carater inicial, depois pelo 2º....

se der problema, só formate o número, p/ todos os valores terem o mesmo número de casas decimais, tipo 00020

experimente colocar manualmente 50 em um edite e 9 em outro, talvez diga que o 9, sem zero na frente, é maior que o 50


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar