Dim NamesArr() As String ' array
Dim MaxNum As Integer 'How many values the user wishes to enter
Dim index As Integer '
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnEnter.Enabled = False ' Initialize retry button to disable
btnSearch.Enabled = False ' Initialize Search button to disable
End Sub
Private Sub btnNames_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNames.Click
btnEnter.Enabled = False ' Initialize retry button to disable
btnSearch.Enabled = False ' Initialize Search button to disable
Dim count As Integer
Dim TestNumber As String
lstNames.Items.Clear()
TestNumber = txtNumberNames.Text
If IsNumeric(TestNumber) = True Then
MaxNum = Val(txtNumberNames.Text) 'Get how many numbers the user will enter
If MaxNum >= 0 Then
ReDim NamesArr(MaxNum)
While count < MaxNum 'Keep going until MaxNum is reached
For index = LBound(NamesArr) To UBound(NamesArr) - 1
NamesArr(index) = InputBox("Please enter name number " & count + 1)
count = count + 1
Next index
btnEnter.Enabled = True ' Initialize retry button to invisible
End While 'End While count < MaxNum
'Loop ends when count = the number of values user wanted to enter
Else
MsgBox("Please enter a number greater than 0")
txtNumberNames.Focus()
txtNumberNames.Clear()
End If
Else
MsgBox("Please enter a real Number")
txtNumberNames.Focus()
txtNumberNames.Clear()
End If
End Sub
Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
For index = LBound(NamesArr) To MaxNum - 1
lstNames.Items.Add(NamesArr(index))
Next index
btnSearch.Enabled = True
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim Message As String
Message = InputBox("Enter your search term")
index = LBound(NamesArr)
Dim running As Boolean
While running = False And index <= UBound(NamesArr)
If NamesArr(index) = Message Then
running = True
Else
index = index + 1
End If
End While
If running = True Then
MsgBox(" The name" & " " & Message & " has been found in cell # " & " " & index + 1)
ElseIf running = False Then
MsgBox(" The name was not found")
End If
txtNumberNames.Focus()
txtNumberNames.Clear()
End Sub
Private Sub btnSort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSort.Click
Dim temp As String
Dim i As Integer
Dim j As Integer
For i = 0 To (UBound(NamesArr) - 1)
For j = 1 To (UBound(NamesArr))
If NamesArr(j) < NamesArr(j - 1) Then
temp = NamesArr(j)
NamesArr(j) = NamesArr(j - 1)
NamesArr(j - 1) = temp
End If
Next j
Next i
End Sub
End Class
I need to preserve the array and be able to add names to it. I also need to be able to sort it alphabetically.

New Topic/Question
Reply



MultiQuote






|