How do I write Do...Loop clause until strLetter is "Y" or "y"? I know how to do it with numbers but not alphabet.
VB.NET: Do clause
Collapse
X
-
-
-
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
-
Originally posted by mbshinde78It should be like
int x
x = "A"
while chr(x) <= "Y"
do whatever you like here
x = x + 1
loop
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
Comment
Comment