Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating Random Alphanumber Number 1

Status
Not open for further replies.

PRUSA

Technical User
Sep 23, 2004
35
0
0
US
Hello Everyone.

I am trying to develop an application in either vb.net, vba, vbscript that will basically generate a random alphanumber in the following format xxx-xxxx

Letters could be: A-Z (in caps)
Numbers coulb be: 0-9

If anyone could please provide some insight, I would really appreciate. I haven't used vb.net in at least 3years, so please be gentle on me.

Thanks In Advance,

Sergio
 
The Chr(i as integer) return chars. I must be from 0 to 255.

Use the random function also. It returns a number between 0 and 1.


That's all you need. Can you now figure out what the code should be?
 
VBakias,

Thanks for the hints. I'll give it a try. I hope you don't mind If I have additional questions.

Thanks you for the advice.

Regards,
Serge
 
Take a look at this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(Random)
End Sub

Function Random() As String
Dim x As String = ""
For i As Integer = 0 To 6
If i = 3 Then x &= "-"
x &= Chr(CInt(Rnd() * 80) + 20)
Next
Return x
End Function


This does not contain A to B and 0 to 9, but all characters of Chr() function. I'll post again
 
This below function returns caps only in this format: xxx-xxxx

Function Random() As String
Dim x As String = ""
For i As Integer = 0 To 6
If i = 3 Then x &= "-"
x &= Chr(CInt(Rnd() * 25) + 65)
Next
Return x
End Function


Chr():
If it is from 48 to 57 gives 0 ... 9
If it is from 65 to 90 gives A ... Z
If it is from 97 to 122 gives a ... z


The: CInt(Rnd() * 25) gives a number from 0 ("A") to 25 (25 number is counted: 90-65 = 25)
I need the Chr to start from 65, so i add 65 and will reach maximum the 65+25 = 90 ("Z")
 
VBakias,

I really appreicate all your help. I did not get a chance to test this last night, but I'll definitely be testing this tonight.

Thanks Again..
Serge
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top