Introduction:
Welcome to a tutorial on how to create a reminder tool in Visual Basic.
Steps of Creation:
Step 1:
First we want to create a form with;
Button1 - to add a new reminder
Label2 - to store the current time
Textbox1 - to store the text of a new reminder
Textbox2 - to store the time of a new reminder
Step 2:
Next we want to create some custom functions, the titles of each explain exactly what they do...
Private Function updateShowingTimer()
Dim time As Date =TimeValue(Now)
Label2.Text = time
End Function
Private Function checkExistings()
If (ListBox1.Items.Count()) Then
For Each l As String In ListBox1.Items
Dim t As String() = l.Split(" Starts At ")
Dim time As String = l.Substring(0, 9)
Dim msg As String = l.Substring(19, l.Count() - 19)
If (TimeValue(Now) = time) Then
MsgBox(msg)
End If
Next
End If
End Function
Private Function constaUpdate()
Do While True
updateShowingTimer()
checkExistings()
Threading.Thread.Sleep(1000)
Loop
End Function
Private Function isRightTimeForamat(ByVal s As String)
If (s.Contains(":")) Then
Dim total As Integer = 0
For Each c As Char In s
If (c = ":") Then total += 1
Next
If (total = 2) Then
Dim all As String() = s.Split(":")
Dim isRight As Boolean = True
For Each a As String In all
If (Not a.Count() = 2) Then isRight = False
Next
If (isRight) Then
Return True
Else : Return False
End If
End If
End If
Return False
End Function
Step 3:
On form load we want to disable CheckForIllegalCrossThreadCalls to avoid errors when trying to set the current time from a new thread, which we also create on form load, which deals with the secondly updating of the current time label.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
CheckForIllegalCrossThreadCalls = False
Dim trd As Threading.Thread = New Threading.Thread(AddressOf constaUpdate)
trd.IsBackground = True
trd.Start()
updateShowingTimer()
End Sub
Step 4:
Finally, we want to make the add new reminder button function. This is where our custom made functions come in to play...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (isRightTimeForamat(TextBox2.Text)) Then
If (Not TextBox1.Text = Nothing) Then
ListBox1.Items.Add(TextBox2.Text & " Starts At " & TextBox1.Text)
End If
End If
End Sub
Project Complete!
Below is the full source code and download to the project files.
Public Class Form1
Private Function updateShowingTimer()
Dim time As Date =TimeValue(Now)
Label2.Text = time
End Function
Private Function checkExistings()
If (ListBox1.Items.Count()) Then
For Each l As String In ListBox1.Items
Dim t As String() = l.Split(" Starts At ")
Dim time As String = l.Substring(0, 9)
Dim msg As String = l.Substring(19, l.Count() - 19)
If (TimeValue(Now) = time) Then
MsgBox(msg)
End If
Next
End If
End Function
Private Function constaUpdate()
Do While True
updateShowingTimer()
checkExistings()
Threading.Thread.Sleep(1000)
Loop
End Function
Private Function isRightTimeForamat(ByVal s As String)
If (s.Contains(":")) Then
Dim total As Integer = 0
For Each c As Char In s
If (c = ":") Then total += 1
Next
If (total = 2) Then
Dim all As String() = s.Split(":")
Dim isRight As Boolean = True
For Each a As String In all
If (Not a.Count() = 2) Then isRight = False
Next
If (isRight) Then
Return True
Else : Return False
End If
End If
End If
Return False
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
CheckForIllegalCrossThreadCalls = False
Dim trd As Threading.Thread = New Threading.Thread(AddressOf constaUpdate)
trd.IsBackground = True
trd.Start()
updateShowingTimer()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (isRightTimeForamat(TextBox2.Text)) Then
If (Not TextBox1.Text = Nothing) Then
ListBox1.Items.Add(TextBox2.Text & " Starts At " & TextBox1.Text)
End If
End If
End Sub
End Class
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.