Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit On
- Option Infer Off
- Option Strict On
- Public Class Form1
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- lstNames.Items.Add("Arnold,Craig")
- lstNames.Items.Add("Schwarzenegger,Arnold")
- End Sub
- Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
- Dim s As String = ""
- Dim c As Integer = 0
- s = txtName.Text.Trim
- For i As Integer = 0 To s.Length - 1 Step 1
- If s.Substring(i, 1) = " " Then
- c = c + 1
- End If
- Next
- If c = 1 Then
- lstNames.Items.Add(convertomatic(s, 0))
- ElseIf c = 0 Then
- MsgBox("You didn't enter a last name, please try again.", MsgBoxStyle.Critical, "Error")
- Else
- MsgBox("You may only enter One last name, please try again.", MsgBoxStyle.Critical, "Error")
- End If
- End Sub
- Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
- Dim i As Integer
- If lstNames.SelectedIndex >= 0 Then
- i = lstNames.SelectedIndex
- lstNames.Items.RemoveAt(i)
- lstNames.SelectedIndex = i - 1
- Else
- MsgBox("No name is selected", MsgBoxStyle.Critical, "Error")
- End If
- End Sub
- Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
- If lstNames.SelectedIndex >= 0 Then
- MsgBox(convertomatic(lstNames.SelectedItem.ToString, 1), MsgBoxStyle.OkOnly, "Name Gotten")
- Else
- MsgBox("No name is selected", MsgBoxStyle.Critical, "Error")
- End If
- End Sub
- Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
- Dim checks As Boolean = False
- Dim s As String = ""
- Do While checks = False
- s = InputBox("Please enter the name you are looking for", "Search").Trim
- If s = "" Then
- MsgBox("You didnt enter a name, try again.", MsgBoxStyle.Critical, "Error")
- ElseIf s.contains(" ") = True Then
- MsgBox("You may only enter a last name, try again.", MsgBoxStyle.Critical, "Error")
- Else
- checks = True
- End If
- Loop
- If searchomatic(s) = True Then
- MsgBox("The last name " & s & " was found.", MsgBoxStyle.OkOnly, "Name found")
- Else
- MsgBox("The last name " & s & " was not found.", MsgBoxStyle.OkOnly, "Name not found")
- End If
- End Sub
- Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click
- Me.Close()
- End Sub
- Private Sub txtName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtName.KeyPress
- If ((e.KeyChar < "a" OrElse e.KeyChar > "z") AndAlso (e.KeyChar < "A" OrElse e.KeyChar > "Z") AndAlso e.KeyChar <> " " AndAlso e.KeyChar <> ControlChars.Back) Then
- e.Handled = True
- End If
- End Sub
- Function convertomatic(ByVal s As String, ByVal i As Integer) As String
- Dim s1 As String
- Dim s2 As String
- If i = 0 Then
- s1 = s.Substring(0, s.IndexOf(" "))
- s2 = s.Substring(s.IndexOf(" ") + 1, (s.Length - 1) - s.IndexOf(" "))
- Return s2 & "," & s1
- ElseIf i = 1 Then
- s1 = s.Substring(0, s.IndexOf(","))
- s2 = s.Substring(s.IndexOf(",") + 1, (s.Length - 1) - s.IndexOf(","))
- Return s2 & " " & s1
- ElseIf i = 2 Then
- s2 = s.Substring(s.IndexOf(" ") + 1, (s.Length - 1) - s.IndexOf(" "))
- Return s2
- ElseIf i = 3 Then
- s1 = s.Substring(0, s.IndexOf(" "))
- Return s1
- Else
- Return ""
- End If
- End Function
- Function searchomatic(ByVal s As String) As Boolean
- Dim checks As Boolean = False
- For i As Integer = 0 To lstNames.Items.Count - 1 Step 1
- If convertomatic(convertomatic(lstNames.Items.Item(i).ToString, 1), 2).ToLower = s.ToLower Then
- Return True
- End If
- Next
- Return False
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement