Click here to Skip to main content
15,895,746 members
Articles / Programming Languages / Visual Basic 10

Having fun with custom collections!

Rate me:
Please Sign up or sign in to vote.
4.91/5 (71 votes)
14 Oct 2011CPOL44 min read 187.5K   2.9K   121  
Creating custom collections from IEnumerable(T) to IDictionary(T) and everything in between!
Imports Alphabet

Public Class frmAlphabet

	Private _alphabet As WesternAlphabet

	Private Sub frmAlphabet_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		_alphabet = New WesternAlphabet
	End Sub

	Private Sub btnGetAlphabet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetAlphabet.Click
		' Clear the Text of the Control.
		txtAlphabet.Text = String.Empty

		' Get the count of characters in the alphabet.
		' Notice that Count is an Extension Method!
		Dim count As Integer = _alphabet.Count
		For i As Integer = 0 To count - 2
			txtAlphabet.Text += _alphabet(i) & ", "
		Next
		' Omit the comma after the last character.
		txtAlphabet.Text += _alphabet(count - 1)
	End Sub

	Private Sub txtIndex_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtIndex.Validating
		Dim index As Integer
		If Integer.TryParse(txtIndex.Text, index) AndAlso index >= 0 Then
			errorProvider.SetError(txtIndex, String.Empty)
		Else
			errorProvider.SetError(txtIndex, "Please provide a valid zero-based index.")
			e.Cancel = True
		End If
	End Sub

	Private Sub btnGetChar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetChar.Click
		' Show the character at the specified index.
		' The Text in txtIndex has already been validated.
		If txtIndex.Text <> String.Empty Then
			txtChar.Text = _alphabet(CInt(txtIndex.Text))
		End If
	End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO JUUN Software
Netherlands Netherlands
Sander Rossel is a Microsoft certified professional developer with experience and expertise in .NET and .NET Core (C#, ASP.NET, and Entity Framework), SQL Server, Azure, Azure DevOps, JavaScript, MongoDB, and other technologies.

He is the owner of JUUN Software, a company specializing in custom software. JUUN Software uses modern, but proven technologies, such as .NET Core, Azure and Azure DevOps.

You can't miss his books on Amazon and his free e-books on Syncfusion!

He wrote a JavaScript LINQ library, arrgh.js (works in IE8+, Edge, Firefox, Chrome, and probably everything else).

Check out his prize-winning articles on CodeProject as well!

Comments and Discussions