VB.NET: Do clause

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • desi2p
    New Member
    • Oct 2008
    • 4

    VB.NET: Do clause

    How do I write Do...Loop clause until strLetter is "Y" or "y"? I know how to do it with numbers but not alphabet.
  • mbshinde78
    New Member
    • Oct 2008
    • 1

    #2
    It should be like

    int x

    x = "A"

    while chr(x) <= "Y"
    do whatever you like here
    x = x + 1
    loop

    Comment

    • desi2p
      New Member
      • Oct 2008
      • 4

      #3
      Sorry, I should have said in VB.net.

      thanks

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        try to use ASCII value of the character for the looping.

        Comment

        • rpicilli
          New Member
          • Aug 2008
          • 77

          #5
          Hi there.

          I hope the code below help you. Don't be scarred. Every line that begins with a character ' is just a coments. ;-)


          [CODE]

          Dim sLetter As String
          'put the letter A into sLetter
          sLetter = "A"
          'Until sLetter is not equal Y stay into the loop
          Do While sLetter <> "Y"
          'Show a messagebox with the currenty letter into sLetter
          MessageBox.Show (sLetter)
          'You must read this function this way.
          'First transform the contents of sLetter into a number (example A = 65)
          'Seconde add 1 to the result ( example 65 + 1 = 66 )
          'Third transform the current number (66) into a character again (66 = B )
          'Last put the new character into the variable sLetter
          sLetter = Chr(Asc(sLetter ) + 1)

          /[CODE]

          Comment

          • jg007
            Contributor
            • Mar 2008
            • 283

            #6
            Originally posted by mbshinde78
            It should be like

            int x

            x = "A"

            while chr(x) <= "Y"
            do whatever you like here
            x = x + 1
            loop
            I have stuck this onto a form with a button and label but you could implement the same in a 'do ... loop ' although it might be awkward when you change from lowercase to uppercase as you will need extra code to by pass the non alphabetic characters

            Code:
            Public Class Form1
            
                Dim letr As Char
            
                Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            
                    letr = "A"
                    Label1.Text = letr
            
                End Sub
            
                Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            
                    letr = Chr((Asc(letr)) + 1)     ' this is increasing the character by 1
                    If letr = "Z" Then
                        Label1.Text = "Finished"
                    Else : Label1.Text = letr
            
                    End If
            
                End Sub
            End Class
            ** sorry just realised that this is pretty much the same as the code above but couldn't work out how to delete! <:) **

            Comment

            Working...