Public Class Form1
Private DogNames As New List(Of String)
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
Me.Close()
End Sub
Private Sub BtnAdmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdmit.Click
Dim DogName As Integer
DogNames.Add(txtDogName.Text)
If txtDogName.Text = String.Empty Then
MessageBox.Show("Please Enter a Name", "Entry Error")
Else
DogName = DogNames.Count
End If
txtDogName.SelectAll()
txtDogName.Focus()
LblShowDogs.Text = DogName
End Sub
Private Sub BtnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCheck.Click
Dim Name As String = Trim(txtDogName.Text)
If DogNames.Contains(Name) = False Then
MessageBox.Show(Name & " is NOT in the kennel", "Non-Member")
Else
MessageBox.Show(Name & " is in the list", "Member")
End If
End Sub
Private Sub BtnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDisplay.Click
Dim Msg As String = String.Empty
For Each entry In DogNames
Msg &= entry & ", " & vbCrLf
Next
MessageBox.Show(Msg, "Current Members")
txtDogName.Focus()
End Sub
Private Sub BtnReverse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReverse.Click
Dim DogTotal As Decimal = 0
Dim dogs As Decimal
Dim message As String = "" & vbCrLf
For i As Integer = DogNames.Count - 1 To 0 Step -1
dogs = DogNames(i) 'saying this InvalidCaseException was unhandled
DogTotal += dogs
message &= dogs & vbCrLf
Next
message &= " " &
MessageBox.Show(message, "Current Members")
End Sub
Private Sub BtnEvict_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEvict.Click
Dim name As String = Trim(txtDogName.Text)
If DogNames.Remove(name) Then
MessageBox.Show(name & " has been evicted from the kennel", "Evicted Member")
Else
MessageBox.Show(name & " is NOT in the list")
End If
End Sub
Private Sub BtnEvictAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnEvictAll.Click
DogNames.Clear()
LblShowDogs.Text = String.Empty
txtDogName.Select()
End Sub
End Class
Displaying a list in Reverse order
Page 1 of 15 Replies - 624 Views - Last Post: 02 October 2012 - 10:49 AM
#1
Displaying a list in Reverse order
Posted 01 October 2012 - 08:25 PM
Trying to get btnReverse to use a message box to show the list of dogs in last to first order. Everything else is working fine but I cant get the btnReverse to work. Any Suggestions?
Replies To: Displaying a list in Reverse order
#2
Re: Displaying a list in Reverse order
Posted 01 October 2012 - 09:24 PM
DogNames is a string collection and your trying to set a decimal from a string and since it's a name it's not convertible by the compiler as a decimal.
#4
Re: Displaying a list in Reverse order
Posted 02 October 2012 - 09:33 AM
And how would I do that? I would look in my book but I am missing 50 pages lol and those 50 pages are the pages I need.
#5
Re: Displaying a list in Reverse order
Posted 02 October 2012 - 09:46 AM
Buy a new book, plus keep in mind that Google is your friend.
#6
Re: Displaying a list in Reverse order
Posted 02 October 2012 - 10:49 AM
lucky3, on 02 October 2012 - 12:36 AM, said:
List(Of T) also has Reverse method. In your case you can just create new list on BtnReverse click, and add all DogNames to it, than .Reverse this new list, and display it.
This would do what you want as far as making it easier to itterate.
Basically what you'll do is this:
'Start by creating a new List of strings Dim reverseDogList As new List(Of String) 'Now add the DogNames list to this list reverseDogList.AddRange(DogNames) 'Reverse the order reverseDogList.Reverse 'Itterate through the new list to get out the dog names For Each dog as String in reverseDogList 'since it is a list of strings dog is of type string so do what you need to to create the comma seperated list of dog names Next
This post has been edited by rgfirefly24: 02 October 2012 - 10:51 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|