468,107 Members | 1,485 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

VB.NET: Do clause

4
How do I write Do...Loop clause until strLetter is "Y" or "y"? I know how to do it with numbers but not alphabet.
Oct 9 '08 #1
5 1145
It should be like

int x

x = "A"

while chr(x) <= "Y"
do whatever you like here
x = x + 1
loop
Oct 9 '08 #2
desi2p
4
Sorry, I should have said in VB.net.

thanks
Oct 10 '08 #3
debasisdas
8,127 Expert 4TB
try to use ASCII value of the character for the looping.
Oct 10 '08 #4
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]
Oct 10 '08 #5
jg007
283 100+
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Class Form1
  3.  
  4.     Dim letr As Char
  5.  
  6.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  7.  
  8.         letr = "A"
  9.         Label1.Text = letr
  10.  
  11.     End Sub
  12.  
  13.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  14.  
  15.         letr = Chr((Asc(letr)) + 1)     ' this is increasing the character by 1
  16.         If letr = "Z" Then
  17.             Label1.Text = "Finished"
  18.         Else : Label1.Text = letr
  19.  
  20.         End If
  21.  
  22.     End Sub
  23. End Class
  24.  
  25.  
** sorry just realised that this is pretty much the same as the code above but couldn't work out how to delete! <:) **
Oct 11 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by aj70000 | last post: by
1 post views Thread by Blake | last post: by
1 post views Thread by Larry Dooley | last post: by
2 posts views Thread by Jim.Mueksch | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.