Нужна помощь в создании идентификатора пользователя на основе имени и фамилии пользователя.
I have to create a program for school that allows the user to type their full name and age and when they click the add button the full name will be separated into first and last name listboxes. The age will also go into its own listbox but what i need help with is that when the add button is clicked a user ID, ex. Sally West's ID would be swest001, needs to be created using a function procedure and every time the same user ID appears the number at the end of the username has to be increased by one using a sub procedure. also, the program has remove button that clears the selected user's info, first/last name and age and user ID, but i can't get the age to be removed together with the other info. Btw, just to make it clear, i just need help with the user ID and completing the remove button. If anyone can help me with this, i would greatly appreciate it.
Что я уже пробовал:
Public Class LA55Form Private NumberOfUsers As Integer Private AgeInteger As Integer Private TotalAge As Integer Private Sub AddButton_Click(sender As Object, e As EventArgs) Handles AddButton.Click Dim FullNameString As String Dim UserIDNameString As String Dim FirstNameString As String Dim LastNameString As String Dim AgeString As String Dim CommaPositionInteger As Integer 'Read fullname FullNameString = FullNameTextBox.Text 'Read age AgeString = AgeTextBox.Text If Integer.TryParse(AgeTextBox.Text, AgeInteger) Then If AgeInteger < 15 Or AgeInteger > 90 Then MessageBox.Show("Age must be greater than 15 or less than 90.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Information) With AgeTextBox .Focus() .SelectAll() End With Exit Sub End If Else MessageBox.Show("Quantity must be numeric.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Information) With AgeTextBox .Focus() .SelectAll() End With Exit Sub End If 'Trim fullname FullNameString = FullNameString.Trim() 'Check for no input If FullNameString = String.Empty Then ' Display error message MessageBox.Show("No name entered - retry", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If 'Search for ", " CommaPositionInteger = FullNameString.IndexOf(", ") 'Check for missing comma and space If CommaPositionInteger = -1 Then ' Display error message MessageBox.Show("Missing comma and space in name", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If 'Extract LastName LastNameString = FullNameString.Substring(0, CommaPositionInteger) 'Extract Firstname FirstNameString = FullNameString.Substring(CommaPositionInteger + 2) 'place names in list boxes LastNameListBox.Items.Add(LastNameString) FirstNameListBox.Items.Add(FirstNameString) 'place Age in list box AgeListBox.Items.Add(AgeString) NumberOfUsers += 1 TotalAge += AgeInteger End Sub Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click Dim averageDecimal As Decimal Dim output As String = "" averageDecimal = TotalAge / NumberOfUsers output = "Total Number of Users: " & NumberOfUsers.ToString() & vbCrLf & "Average Age of Users: " & averageDecimal.ToString() MessageBox.Show(output, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) Close() End Sub Private Sub FirstNameListBox_Click(sender As Object, e As EventArgs) Handles FirstNameListBox.Click 'activate remove button RemoveButton.Enabled = True End Sub Private Sub RemoveButton_Click(sender As Object, e As EventArgs) Handles RemoveButton.Click 'check for item selected If FirstNameListBox.SelectedIndex <> -1 Then LastNameListBox.Items.RemoveAt(FirstNameListBox.SelectedIndex) FirstNameListBox.Items.RemoveAt(FirstNameListBox.SelectedIndex) AgeListBox.Items.RemoveAt(FirstNameListBox.SelectedIndex) End If RemoveButton.Enabled = False End Sub End Class