I'm keeping track of some things that are numbered and others that are lettered; while NumericUpDown is perfect for selecting numbered things, I need an analogue for selecting lettered things.
The obvious choice would be a listbox that just contains all the letters of the alphabet. But I need to show only the appropriate range of letters, so if I want to use a listbox, I need to write a function that populates the listbox with the first n letters of the alphabet; if n > 26, it should continue with aa, ab, and so on. How do I do this?
here's a custom userControl. it ranges from A to ZZZ:
Interesting!
Loaded it into VB10 and it says... Using the iteration variable in a lambda expression may have unexpected results. Instead, create a local variable within the loop and assign it the value of the iteration variable.
EDIT Changed it like this and Warnings went away.
Code:
For a As Integer = 0 To 25
Dim aa As Integer = a
Dim alphabet2Chars() As String = Enumerable.Range(0, 26).Select(Function(x) alphabet(aa) & Chr(65 + x)).ToArray
alphabetString = alphabetString.Concat(alphabet2Chars).ToArray
Next
For a1 As Integer = 0 To 25
For a2 As Integer = 0 To 25
Dim aa1 As Integer = a1
Dim aa2 As Integer = a2
Dim alphabet3Chars() As String = Enumerable.Range(0, 26).Select(Function(x1) alphabet(aa1) & alphabet(aa2) & Chr(65 + x1)).ToArray
alphabetString = alphabetString.Concat(alphabet3Chars).ToArray
Next
Next
Last edited by Edgemeal; Apr 2nd, 2012 at 05:40 PM.
Reason: remove image
If the control is in a single file you can just import it into your project using the solution explorer on the right and compile. It should appear in the tool box after with a generic purple icon.
C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter
There's just no reason to use garbage like InputBox. - jmcilhinney
The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber
Adding the blank value shifts everything so blank is 1, A is 2, B is 3, etc. How do I change it so that blank is 0, A is 1, etc? (Changing the control's minimum to 0 and the maximum and minimum properties accordingly is part of it, but what else do I need to do?)
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
If alphabetString.Length = 0 Then Return
TextBox1.Text = alphabetString(CInt(NumericUpDown1.Value) - 1)
End Sub