Vb6 How do I make a Random String of 0-9 and a-z of x characters

后端 未结 8 1896
無奈伤痛
無奈伤痛 2021-02-14 03:29

Trying to create a random string, x characters in length using 0-9 and a-z/A-Z and can\'t seem to find a good example, any ideas?

8条回答
  •  太阳男子
    2021-02-14 04:00

    I forgot all my VB6 (thank God) but in pseudocode it's pretty easy:

        all_chars = an array of all the valid chars
        seed random number generator
        for i = 1 to x do
            random_index = get a random number between 1 and length of all_chars
            'I remember how to concat and comment in VB6 :-)
            string = string & all_chars[random_index] 
        end for
    
        done!
    

    So it's just a matter of finding out how to create an array and fill it with characters, how to get the length of the array and how to get a random number between the first and last indexes of said array.

    Well, all that and looping of course.

提交回复
热议问题