|
-
May 10th, 2011, 11:38 AM
#1
Thread Starter
Frenzied Member
[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)
-
May 10th, 2011, 12:00 PM
#2
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
-
May 10th, 2011, 12:19 PM
#3
Thread Starter
Frenzied Member
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!
Last edited by tony007; May 10th, 2011 at 12:52 PM.
-
May 10th, 2011, 12:50 PM
#4
Re: How to increment letters like a to b then to c ...
 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)
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 10th, 2011, 12:59 PM
#5
Re: How to increment letters like a to b then to c ...
 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
Last edited by Spoo; May 10th, 2011 at 01:04 PM.
-
May 10th, 2011, 01:13 PM
#6
Lively Member
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
If my post was helpful to you, then express your gratitude using Rate this Post.
To understand recursion, you must first understand recursion.
-
May 10th, 2011, 01:13 PM
#7
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
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 10th, 2011, 01:21 PM
#8
Thread Starter
Frenzied Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|