[RESOLVED] How to increment letters like a to b then to c ...
Hi all .could any one show me how i can increment letters for example if i have letter text5=a next time i call the function the value be text5=b and so on untill i reach z and it jumps back to a ! I have done similer think for integers as shown below but want to do it for letters .Hope some one show me how i can
increment letters.Thanks
Text5.Text = CStr(CLng(Text5.Text) + 1)
Re: How to increment letters like a to b then to c ...
This is an example in which, for demonstration purposes, I am using two textboxes.
It will take the number in text1 and find its equivalent in the alphabet, and display the letter in text2.
You can take my example, and modify it for your use
vb Code:
Private Sub Command1_Click()
Const ALPHA_BET As String = "abcdefghijklmnopqrstuvwxyz"
Dim intLetter As Integer
Dim intNum As Integer
intNum = CInt(Text1.Text)
For intLetter = 1 To Len(ALPHA_BET)
If intLetter = intNum Then
Text2.Text = UCase(Mid(ALPHA_BET, intLetter, 1))
Exit For
End If
Next
End Sub
Re: How to increment letters like a to b then to c ...
thanks hack . i go this solution but it goes beyond letter z . Is there away to stop it at Z and start from a all over again ?
Code:
Private Sub Command1_Click()
If Option7.Value = True Then
Text14.Text = Chr(Asc(Text14.Text) + 1)
End If
End sub
By looking at you solution how i can restart from a to z all over again when i reach letter z. i see that integer keeps incrementing ?is there a
Code:
Private Sub Command1_Click()
Const ALPHA_BET As String = "abcdefghijklmnopqrstuvwxyz"
Dim intLetter As Integer
Dim intNum As Integer
Text1.Text = CStr(CLng(Text1.Text) + 1)
intNum = CInt(Text1.Text)
For intLetter = 1 To Len(ALPHA_BET)
If intLetter = intNum Then
Text2.Text = LCase(Mid(ALPHA_BET, intLetter, 1))
Exit For
End If
Next
End Sub
My goal is to change value of textbox14 which initially start with letter "a" and keep incrementing it till "z" and the all over again ...until user stop clicking the function!
Re: How to increment letters like a to b then to c ...
Quote:
Originally Posted by
tony007
Hi all .could any one show me how i can increment letters for example if i have letter text5=a next time i call the function the value be text5=b and so on untill i reach z and it jumps back to a ! I have done similer think for integers as shown below but want to do it for letters .Hope some one show me how i can
increment letters.Thanks
Text5.Text = CStr(CLng(Text5.Text) + 1)
If Text5.Text = "z" Then Text5.Text = Chr(Asc("a") - 1)
Text5.Text = Chr(Asc(Text5.Text) + 1)
Re: How to increment letters like a to b then to c ...
Quote:
Originally Posted by
tony007
thanks hack . i go this solution but it goes beyond letter z . Is there away to stop it at Z and start from a all over again ?
Code:
Private Sub Command1_Click()
If Option7.Value = True Then
Text14.Text = Chr(Asc(Text14.Text) + 1)
End If
End sub
Tony
That is the approach that came to mind as I started reading
thru the thread.
To deal with your "stopping at z" issue, it might be helpful
to keep this in mind:
- Asc("a") = 97
- Asc("z") = 122
You could add a "test" .... if you are at 122, reset to 97.
I bet that you can take it from here.
BTW, it is case-sensitive. To wit,
- Asc("A") = 65
- Asc("Z") = 90
EDIT: jmsrickland snuck his reply in while I was typing -- he stole my idea
Spoo
Re: How to increment letters like a to b then to c ...
My version :)
vb Code:
Dim iChar As Integer
For iChar = Asc("a") To Asc("z")
MsgBox Chr(iChar)
If iChar = Asc("z") Then iChar = Asc("a") - 1
Next iChar
Re: How to increment letters like a to b then to c ...
Yes, as you were typing I looked behind the window and saw what you were typing:D:D
Re: How to increment letters like a to b then to c ...
Many Many thanks for all of you . jmsrickland i think your solution was shortest one !
Code:
Private Sub Command1_Click()
If Option7.Value = True Then
'for incrementing letters till z
If Text5.Text = "z" Then Text5.Text = Chr(Asc("a") - 1)
Text5.Text = Chr(Asc(Text5.Text) + 1)
End If
End sub
Hack i manged to stop your first solution like this:
Code:
Private Sub Command1_Click()
Const ALPHA_BET As String = "abcdefghijklmnopqrstuvwxyz"
Dim intLetter As Integer
Dim intNum As Integer
For i = 0 To Text1.Text = 27
Text1.Text = CStr(CLng(Text1.Text) + 1)
If Text1.Text = 27 Then
Text1.Text = 1
End If
Next
intNum = CInt(Text1.Text)
For intLetter = 1 To Len(ALPHA_BET)
If intLetter = intNum Then
Text2.Text = LCase(Mid(ALPHA_BET, intLetter, 1))
Exit For
End If
Next
End sub