Fórum Embaralhar linhas de um Listbox??? #293662
30/08/2005
0
Alguem pode me ajudar?
Valew
O4pr3ndiz
Curtir tópico
+ 0Posts
30/08/2005
O4pr3ndiz
Gostei + 0
30/08/2005
Massuda
Gostei + 0
01/09/2005
O4pr3ndiz
Agora estou precisando de um codigo delphi q embaralhe as linhas de um listbox... tipo linha por linha aleatoriamente, ou de 5 a 5 linhas de uma vez só..... Preciso terminar um projeto de faculdade e to me matando pra fazer isto..
Obrigado...
Gostei + 0
01/09/2005
Motta
procedure TForm1.Button1Click(Sender: TObject); var i,j,k : integer; s : string; begin Randomize; for k := 1 to 100 do begin i := Random(ListBox1.Items.Count-1); j := Random(ListBox1.Items.Count-1); s := Listbox1.Items[i]; Listbox1.Items[i] := Listbox1.Items[j]; Listbox1.Items[j] := s; end; end;
Gostei + 0
01/09/2005
Sandra
Acredito que tenha se enganado quanto ao ´ListBox1.Items.Count-1´. Se a variável [b:031b1a3f9b]k[/b:031b1a3f9b] começa cum [b:031b1a3f9b]1[/b:031b1a3f9b], então ´ListBox1.Items.Count´ (se começasse com 0, seria Count-1). :wink:
Fiz uma adaptação para o código que montou:
procedure TForm1.Button1Click(Sender: TObject); var i,j,k : integer; s : string; begin Randomize; for k := 1 to ListBox1.Items.Count do begin i := Random(ListBox1.Items.Count); j := Random(ListBox1.Items.Count); s := Listbox1.Items[i]; Listbox1.Items[i] := Listbox1.Items[j]; Listbox1.Items[j] := s; end; end;
:D
Gostei + 0
01/09/2005
Martins
procedure TForm1.Button2Click(Sender: TObject); var a,b,c : integer; l : string; begin Randomize; for c := 1 to LBox.Items.Count do begin a := Random(LBox.Items.Count); b := Random(LBox.Items.Count); l := LBox.Items[a]; LBox.Items[a] := LBox.Items[b]; LBox.Items[b] := l; end; end;
Ok!
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)