0

I have next 'while' statement which I should re-write on VB:

    while (--number >= 0)
    {
        result = (char)('A' + number % lettersNumbers) + result;
        number /= lettersNumbers;
    }

I've tried something like this:

While number >= 0
    number = number - 1
    result = Chr(Chr("A") + number Mod lettersNumbers) & result
    number = number / lettersNumbers
WEnd

But unfortunately it doesn't works. I am getting next error:

Type mismatch: '[string: "A"]' So how to correct this code to make it work on VBscript?

2 Answers 2

5

You need to get the character code of "A":

While number >= 0
    number = number - 1
    result = Chr(Asc("A") + number Mod lettersNumbers) & result
    number = number / lettersNumbers
WEnd

The function Asc returns the Ascii code for a given letter. in your original you use a charcater (char) in a calculation. C# implicitly converts char to int.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, Asc returns the ANSI character code value. The ANSI character set is the one of many possible character sets that is configured for the thread at the time the code runs. (The thread initially inherits from the process, which initially inherits from the user, which initially inherits from the operating system installation.)
2
While number >= 0
    number = number - 1
    result = Chr(Asc("A") + number Mod lettersNumbers) & result
    number = number / lettersNumbers
WEnd

You need to get the character code of "A":

4 Comments

Answered the same answer later and still gets the upvotes. I don't understand the mechanics of this site :-D
Code dumps just do better. No need for any effort to read what you have explained... @RomanoZumbé
@PatrickHofman Oh, thats kind of sad. Just solve the problem and don't understand the cause of it ... I'll stay with explaining what causes the problem :-)
And now the answering user (which was registered today) is deleted. Seems odd to me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.