Discussion Locked

Generating random letters in vb 6.0

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi all

Sorry should have explained this in more detail, here's what I want to do.
I have one form with 5 text boxes on it and need to generate random letters between A-F and random Numbers between 0-9

For Example: Text box 1 A0, Text 2 B7 Text 3 F9 Text 4 C6 Text 5 E8

So when the user clicks the command button, the program will generate random letters and numbers in each of the text boxes.

Could anyone maybe just point me in the direction with a couple of lines of code to perform this task.

Thanks for any help in advance

Cheers,
Mark

4 replies

by tom

Mark, Hi

Using the same concept as before, here's a method to get waht you need. The Randomize(Time) "seeds" the randomizer and ensures that you don't get the same sequence of numbers generating every time you start the program.

Good Luck!

Private Sub Form_Load()
Randomize (Time)
End Sub

Private Function AtoF() As String
' Upper Case
AtoF = Chr(65 + Rnd() * 862150000 Mod 6)

End Function

Private Function ZerotoNine() As String
' Numbers
ZerotoNine = Chr(48 + Rnd() * 862150000 Mod 10)

End Function

Private Sub Command1_Click()
Dim count As Integer

' Text1 is a control array of 5 text box's

For count = 0 To 4
Text1(count) = AtoF & ZerotoNine
Next count

End Sub

by manrick_021

I NEED SPECIFIC CODE FOR A RANDOM QUESTION, I HAVE A !) TEXTBOX AND WHEN I'LL RUN A PROG. IT WILL BE RANDOMIZE...!?

This discussion is closed to new replies.