Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Random numbers and letters

Random numbers and letters

Scheduled Pinned Locked Moved Visual Basic
helpdesigntutorialquestionlounge
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aahmad76
    wrote on last edited by
    #1

    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!!!

    N 1 Reply Last reply
    0
    • A aahmad76

      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!!!

      N Offline
      N Offline
      Nadroj
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • N Nadroj

        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

        A Offline
        A Offline
        aahmad76
        wrote on last edited by
        #3

        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 :)

        N 1 Reply Last reply
        0
        • A aahmad76

          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 :)

          N Offline
          N Offline
          Nadroj
          wrote on last edited by
          #4

          yup, no prob. ------------------------ Jordan. III

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups