Days of The Week Listbox
Days of The Week Listbox
procedure TForm1.GenerateRandomDay;
var
randomIndex: Integer;
selectedDay: string;
begin
// Generate a random index
randomIndex :=
Random(ListBox1.Items.Count);
// Select the day at the random index
ListBox1.ItemIndex := randomIndex;
// Get the selected day
selectedDay :=
ListBox1.Items[randomIndex];
// Check if the selected day is a weekday
or a weekend
if (selectedDay = 'Sunday') or
(selectedDay = 'Saturday') then
Edit1.Text := 'Weekend'
else
Edit1.Text := 'Weekday';
end;
procedure TForm1.Button1Click(Sender:
TObject);
begin
GenerateRandomDay;
end;
```
In this code, `ListBox1` refers to the list box
control that contains the days of the week,
and `Edit1` refers to the edit box control
where the result will be displayed. The
`GenerateRandomDay` procedure
generates a random index, selects the
corresponding day in the list box, and
checks if it falls on a weekend or a
weekday. The result is then displayed in
the edit box.
You can call the `GenerateRandomDay`
procedure in the `OnClick` event of a
button (e.g., `Button1Click`) to trigger the
random selection and display of the day.