Search code examples
for-loopasp-classic

For next to add with classic asp


for the next "A to Z" getting results. for into; 5 and the number 6, I want to add. How do I make.

for k = asc("A") to asc("Z")
response.write chr(k)
next

Result :

A B C .. Z

I want A B C .. Z 5 6

Such as ( k = asc("A") to asc("Z") add "5" and add"6" )


Solution

  • You can't really have a loop for this, just add separate commands:

    for k = asc("A") to asc("Z")
        response.write chr(k)
    next
    response.write "5"
    response.write "6"
    

    Another option is storing all the ASCII numbers in array then looping that array:

    Dim arrLetters(), x
    ReDim arrLetters(-1)
    For k=Asc("A") To Asc("Z")
        ReDim Preserve arrLetters(UBound(arrLetters) + 1)
        arrLetters(UBound(arrLetters)) = k
    Next
    ReDim Preserve arrLetters(UBound(arrLetters) + 1)
    arrLetters(UBound(arrLetters)) = Asc("5")
    ReDim Preserve arrLetters(UBound(arrLetters) + 1)
    arrLetters(UBound(arrLetters)) = Asc("6")
    For x=0 To UBound(arrLetters)
        k = arrLetters(x)
        response.write chr(k)
    Next
    Erase arrLetters