Random numbers and letters
-
Hey people, what's up? Well, I am quite new to this whole VB/VBNET thing and I love it already. I am also stuck with a little problem. I am trying to design a program that creates a ten digit alphanumeric code. I have no idea how to approach that goal. Can anyone help me? I appreciate any help!!!
-
Hey people, what's up? Well, I am quite new to this whole VB/VBNET thing and I love it already. I am also stuck with a little problem. I am trying to design a program that creates a ten digit alphanumeric code. I have no idea how to approach that goal. Can anyone help me? I appreciate any help!!!
i will give you an example of how to generate a random number. then, an example of how to return a character, using its Ascii value (ex, A = 65). then finally a way to return a random character. ** NOTE: for these examples, i am using a VB.net Console Application. ** GENERATE RANDOM NUMBER: Module Module1 Sub Main() 'declare variable to store your random number Dim myNumber As Integer 'initialize a method to generate random numbers Randomize() 'create a random number and store it in our variable myNumber = (50 * Rnd()) + 1 'the statement (50 * Rnd()) + 1) will generate a random number from 1-50. 'If you excluded the " + 1" part, it would generate a number from 0-49. 'write our variable to the screen Console.WriteLine(myNumber) 'pause for display, by waiting untill the user presses -ENTER- Console.ReadLine() End Sub End Module RETURN A CHARACTER USING ASCII VALUES: console.writeline(Chr(65)) 'displays "A" on the screen. if you dont want to print it and only return its value, just use Chr(65). GENERATE RANDOM CHARACTERS: after reviewing the top 2 methods, you should be able to know how to do this. here is an example though: Console.WriteLine(Chr((127 * Rnd()) + 1)) 'this will display a random Ascii character. again, if you just want to return it and not print it, just use the Chr(...). ASCII: for more info about Ascii and a chart of characters and their corresponding ASCII values, visit asciitable.com[^]. The "Dec" column is the "Chr"'s ASCII value. ------------------------ Jordan. III
-
i will give you an example of how to generate a random number. then, an example of how to return a character, using its Ascii value (ex, A = 65). then finally a way to return a random character. ** NOTE: for these examples, i am using a VB.net Console Application. ** GENERATE RANDOM NUMBER: Module Module1 Sub Main() 'declare variable to store your random number Dim myNumber As Integer 'initialize a method to generate random numbers Randomize() 'create a random number and store it in our variable myNumber = (50 * Rnd()) + 1 'the statement (50 * Rnd()) + 1) will generate a random number from 1-50. 'If you excluded the " + 1" part, it would generate a number from 0-49. 'write our variable to the screen Console.WriteLine(myNumber) 'pause for display, by waiting untill the user presses -ENTER- Console.ReadLine() End Sub End Module RETURN A CHARACTER USING ASCII VALUES: console.writeline(Chr(65)) 'displays "A" on the screen. if you dont want to print it and only return its value, just use Chr(65). GENERATE RANDOM CHARACTERS: after reviewing the top 2 methods, you should be able to know how to do this. here is an example though: Console.WriteLine(Chr((127 * Rnd()) + 1)) 'this will display a random Ascii character. again, if you just want to return it and not print it, just use the Chr(...). ASCII: for more info about Ascii and a chart of characters and their corresponding ASCII values, visit asciitable.com[^]. The "Dec" column is the "Chr"'s ASCII value. ------------------------ Jordan. III
-
Hey Jordan, Thank you very much for the information. Although I have not tried it yet, it looks very helpfull. Again, thank you!!! Al Ahmad :)