Help with VB code

How can I easily do the following:  for any string of 2 letters, for example, ag, dm,  ou, etc., I want to generate a string that contains all letters of the alphabet between the 2 letters, inclusive.  And also verify that the first letter precedes the second letter, alphabetically.
LVL 1
HLRosenbergerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
This should get you started
    Sub Main()
        Dim inp As String
        inp = "ag"
        If inp.Chars(0) < inp.Chars(1) Then
            Dim i As Integer
            For i = Asc(inp.Chars(0)) To Asc(inp.Chars(1))
                Console.WriteLine(Chr(i))
            Next
        End If
        Console.WriteLine("done")
    End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ron MalmsteadInformation Services ManagerCommented:
..something like this...
    Sub Main()


        Dim alphabet As String = "abcdefghijklmnopqrstuvwxyz"


        Dim teststring As String = "dm"
        Dim newstring As String = ""
        If teststring.Length = 2 Then
            If alphabet.IndexOf(Left(teststring, 1)) < alphabet.IndexOf(Right(teststring, 1)) Then

                For i = alphabet.IndexOf(Left(teststring, 1)) + 1 To alphabet.IndexOf(Right(teststring, 1)) - 1

                    newstring = newstring & alphabet(i)

                Next

            End If
        End If
      
        MsgBox(newstring)
    End Sub

Open in new window

0
Julian HansenCommented:
Version to create an output string
Question: does case matter in other words can you have a string "Ag"
If so do you need to preserve the case?

If not you can do this
Sub Main()
        Dim inp As String = "Ag"
        Dim otp As String

        inp = inp.ToLower()
        If inp.Length = 2 And inp.Chars(0) < inp.Chars(1) Then
            Dim i As Integer
            For i = Asc(inp.Chars(0)) To Asc(inp.Chars(1))
                otp = otp & Chr(i)
            Next
        End If
        Console.WriteLine(otp)
    End Sub

Open in new window

0
HLRosenbergerAuthor Commented:
thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.