469,271 Members | 1,790 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Incrementing a string variable?? (A,B,C,D....)

Does anyone know of an easy way to increment a string by one letter at
a time?

What I want to be able to do is set a variable with the value "A" and
then be able to use a For loop to make it change to B,C,D,E...

Any ideas? If so, then thankyou very very much!
Jul 17 '05 #1
4 13475
SFB
Use chr function as upper A to Z code points are 65 to 90.

"trickydicky" <tr***********@hotmail.com> wrote in message
news:9a********************************@4ax.com...
Does anyone know of an easy way to increment a string by one letter at
a time?

What I want to be able to do is set a variable with the value "A" and
then be able to use a For loop to make it change to B,C,D,E...

Any ideas? If so, then thankyou very very much!

Jul 17 '05 #2
> Does anyone know of an easy way to increment a string by one letter at
a time?

First, you need to convert it to a number. A good way of doing this is by
ASC( ).
Second, you need to add 1 to it. Try +.
Third, you need to convert it back again. Maybe CHR$( ).

Put it together, and you should get something like
A$ = Chr$(Asc(A$) + 1)

I know this sounds as if I'm taking the mick, but it does look like a school
question as it's out of context.

--
QuickHare
Remove the NOT HERE to email direct.
Jul 17 '05 #3
trickydicky <tr***********@hotmail.com> wrote:
Does anyone know of an easy way to increment a string by one letter at
a time?

What I want to be able to do is set a variable with the value "A" and
then be able to use a For loop to make it change to B,C,D,E...

Any ideas? If so, then thankyou very very much!


Try this:

Dim iCount as integer, strChar as string

for iCount=1 to 26
strChar=str(asc("@" + iCount)
print strChar
next

Or this:

Dim iCount as integer, strChar as string

strChar="A"
for iCount = 1 to 25
strChar=str(asc(strChar) +1)
print strChar
next

More about me: http://www.jecarter.com/
VB3/VB6/NSBasic Palm/C/PowerBasic source code: http://www.jecarter.com/programs.html
Drivers for Pablo graphics tablet and JamCam cameras: http://home.earthlink.net/~mwbt/
johnecarter at@at mindspring dot.dot com. Fix the obvious to reply by email.
Jul 17 '05 #4
Thanks for the help guys. In case you were interested what I'm doing
is making a basic charting program and needed a way to label the X
axis with letters and use a key.

Thanks again.

On Thu, 13 Nov 2003 00:46:43 GMT, the Wiz <lo**@message.body> wrote:
trickydicky <tr***********@hotmail.com> wrote:
Does anyone know of an easy way to increment a string by one letter at
a time?

What I want to be able to do is set a variable with the value "A" and
then be able to use a For loop to make it change to B,C,D,E...

Any ideas? If so, then thankyou very very much!


Try this:

Dim iCount as integer, strChar as string

for iCount=1 to 26
strChar=str(asc("@" + iCount)
print strChar
next

Or this:

Dim iCount as integer, strChar as string

strChar="A"
for iCount = 1 to 25
strChar=str(asc(strChar) +1)
print strChar
next

More about me: http://www.jecarter.com/
VB3/VB6/NSBasic Palm/C/PowerBasic source code: http://www.jecarter.com/programs.html
Drivers for Pablo graphics tablet and JamCam cameras: http://home.earthlink.net/~mwbt/
johnecarter at@at mindspring dot.dot com. Fix the obvious to reply by email.


Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mothra | last post: by
27 posts views Thread by Erik de Castro Lopo | last post: by
5 posts views Thread by Daz | last post: by
8 posts views Thread by mantrid | last post: by
53 posts views Thread by subramanian100in | last post: by
code green
6 posts views Thread by code green | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.