0% found this document useful (0 votes)
14 views2 pages

Days of The Week Listbox

The provided Delphi code defines a procedure that generates a random day from a list box containing the days of the week. It checks if the selected day is a weekend or a weekday and displays the result in an edit box. The procedure can be triggered by a button click event.

Uploaded by

mavislossie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Days of The Week Listbox

The provided Delphi code defines a procedure that generates a random day from a list box containing the days of the week. It checks if the selected day is a weekend or a weekday and displays the result in an edit box. The procedure can be triggered by a button click event.

Uploaded by

mavislossie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

```delphi

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.

You might also like