I need to generate a loop that would iterate through each capital letter of the alpha开发者_StackOverflow社区bet using Visual Basic (2008). What's the cleanest way to do this?
For Each c In "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray()
...
Next
The simplest way to do this would probably be:
For ascii = 65 To 90
Debug.Print(Chr(ascii))
Next
I'm not really sure if it's the cleanest though. I haven't worked in vb.net much since I started with c#.
I figured it out. Anyone have a better solution?
To loop through the alphabet:
For i As Int16 = Convert.ToInt16("A"c) To Convert.ToInt16("Z"c)
Dim letter As Char = Convert.ToChar(i)
'Do my loop work...
Next
Letter
will first equal "A", then "B", etc.
Anyone have a better solution?
Here's another way to enumerate letters:
For Each letter As Char In Enumerable.Range(Convert.ToInt16("A"c), 26) _
.Select(Function(i) Convert.ToChar(i))
Console.WriteLine(letter)
Next
Maybe there is an easier way, but I was able to put this together in a minute.
Dim alpha As String
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
For x = 1 To 26
c = Mid(alpha, x, 1)
...
Next
Try this one
Dim a As String
a = 65
Do
If a > 90 Then
Exit Do
Else
List1.AddItem Chr(a)
a = a + 1
End If
Loop
Sub Sel_1_sur_2()
Dim i As Long
Dim a As ChartObject
Dim rng As Range
Set rng = Range(Chr(65) & ":" & Chr(65))
For ascii = 65 To 90 Step 2
Debug.Print (Chr(ascii))
Set rng = Union(rng, Range(Chr(ascii) & ":" & Chr(ascii)))
Next
rng.Select
End Sub
Module Abecedario
Sub main()
Dim letra As String
letra = 65
Console.WriteLine("El abecedario")
Console.WriteLine("-------------")
Do
If letra > 90 Then
Exit Do
Else
Console.Write(Chr(letra) & ", ")
letra = letra + 1
End If
Loop
Console.ReadLine()
End Sub
End Module
精彩评论