444,239 Members | 1,505 Online Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

# VB code to convert positive integer N into an alphanumeric string

 P: 6 Convert a positive integer with N digits into an alphanumeric string where A = 0, B = 1, …, J = 9. Let N be less than or equal to 1000000. N=776655 So far I have: Expand|Select|Wrap|Line Numbers Sub code_num() Dim N As integer Dim Alpha As String N=776655 I am new to VBA and i'm not really sure on where to even start with this problem.... Feb 28 '13 #1
3 Replies

 Expert Mod 10K+ P: 12,383 Please use code tags when posting code. There are a few options, one way is to use the replace function to replace each number from 0 to 9 with its letter equivalent. Feb 28 '13 #2

 P: 6 ok so i would set A=0, B=1 etc. which means for N=776655, my end result should be HHGGFF right? Which command assigns each number a letter? Feb 28 '13 #3

 P: 94 I haven't coded in VBA in a while so I'm not 100% on the syntax but I believe this will work for you. What I did to get the correct alpha value was add 65 (ASCII decimal code for A) to your number which will get me the correct decimal value and brought that back to a character. Expand|Select|Wrap|Line Numbers    Dim N As Integer    Dim Alpha As String    N = 776655    Alpha = CStr(N)    For i As Integer = 1 To Len(Alpha)        Mid(Alpha, i, 1) = Chr(CInt(Mid(Alpha, i, 1)) + 65)    Next    ' Alpha variable will now be HHGGFF   Ascii Table: http://www.asciitable.com/ Feb 28 '13 #4 