How can I iterate through the alphabet in Visual B

2020-07-03 07:24发布

I need to generate a loop that would iterate through each capital letter of the alphabet using Visual Basic (2008). What's the cleanest way to do this?

标签: vb.net
7条回答
欢心
2楼-- · 2020-07-03 08:05

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
查看更多
淡お忘
3楼-- · 2020-07-03 08:07

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
查看更多
放荡不羁爱自由
4楼-- · 2020-07-03 08:11

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#.

查看更多
▲ chillily
5楼-- · 2020-07-03 08:11
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
查看更多
男人必须洒脱
6楼-- · 2020-07-03 08:15
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
查看更多
男人必须洒脱
7楼-- · 2020-07-03 08:21
For Each c In "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray()
...
Next
查看更多
登录 后发表回答