From a6900e3fd7062b31cb0f2d7244163e0f24c8c293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raymond=20Lei=28=E9=9B=B7=E8=8F=A9=E5=AE=87=29?= Date: Thu, 26 Dec 2024 22:55:29 -0500 Subject: [PATCH] Add files via upload --- Friends'Manager.linq | 106 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Friends'Manager.linq diff --git a/Friends'Manager.linq b/Friends'Manager.linq new file mode 100644 index 0000000..09bbac8 --- /dev/null +++ b/Friends'Manager.linq @@ -0,0 +1,106 @@ + + +Sub Main + +End Sub + +Public Class Form1 + + ' A list to store friends' details + Private friendsList As New List(Of String) + + + ' Add Friend Button Click + + Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click + + Dim name As String = txtName.Text + + Dim birthday As String = txtBirthday.Text + + + If String.IsNullOrWhiteSpace(name) OrElse String.IsNullOrWhiteSpace(birthday) Then + + MessageBox.Show("Please enter both name and birthday.", "Error") + + Return + End If + + + ' Add friend to the list + + Dim friendInfo As String = $"Name: {name}, Birthday: {birthday}" + + friendsList.Add(friendInfo) + + MessageBox.Show($"{name} added to your friends list!", "Success") + + + ' Clear input fields + + txtName.Clear() + + txtBirthday.Clear() + + End Sub + + + ' View Friends Button Click + + Private Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click + ' Clear the list box + lstFriends.Items.Clear() + + ' Display all friends + + For Each friend In friendsList + lstFriends.Items.Add(friend) + Next + + End Sub + + Private Sub btnCheckBirthday_Click(sender As Object, e As EventArgs) Handles btnCheckBirthday.Click + Dim today As String = DateTime.Now.ToString("MM/dd") + Dim birthdayFriends As New List(Of String) + + For Each friendInfo In friendsList + Dim parts As String() = friendInfo.Split(","c) + If parts.Length > 1 Then + Dim birthday As String = parts(1).Replace("Birthday: ", "").Trim() + If birthday.StartsWith(today) Then + birthdayFriends.Add(parts(0).Replace("Name: ", "").Trim()) + End If + End If + Next + + If birthdayFriends.Count > 0 Then + MessageBox.Show($"Today is the birthday of: {String.Join(", ", birthdayFriends)}", "Birthday Reminder") + Else + MessageBox.Show("No birthdays today!", "Birthday Reminder") + End If + End Sub + + + Private Sub btnCheckBirthday_Click(sender As Object, e As EventArgs) Handles btnCheckBirthday.Click + Dim today As String = DateTime.Now.ToString("MM/dd") + Dim birthdayFriends As New List(Of String) + + For Each friendInfo In friendsList + Dim parts As String() = friendInfo.Split(","c) + If parts.Length > 1 Then + Dim birthday As String = parts(1).Replace("Birthday: ", "").Trim() + If birthday.StartsWith(today) Then + birthdayFriends.Add(parts(0).Replace("Name: ", "").Trim()) + End If + End If + Next + + If birthdayFriends.Count > 0 Then + MessageBox.Show($"Today is the birthday of: {String.Join(", ", birthdayFriends)}", "Birthday Reminder") + Else + MessageBox.Show("No birthdays today!", "Birthday Reminder") + End If + End Sub + + +End Class