Hello everybody,
I have to generate a string of letters of this kind:
M + 7 letters
for example :
MAZERTYU
MPOISURE
etc
What kind of code could I use ?
Thanks
Hello everybody,
I have to generate a string of letters of this kind:
M + 7 letters
for example :
MAZERTYU
MPOISURE
etc
What kind of code could I use ?
Thanks
[vba]
Dim num As Long
Dim tmp As String
Dim i As Long
tmp = "M"
For i = 1 To 7
tmp = tmp & Chr(64 + Int((Rnd() * 26) + 1))
Next i
Debug.Print tmp
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Great, it works perfectly, my boss will be happy!
Thank you so much XLD
That's okay. But can I ask what possible use you have for this code, I am intrigued?Originally Posted by Dabo
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Sure,
I have a list of Ids for customers
"M0000001" = customer 1
"M0000002" = customer 2
etc
I need to let the user add new customers.
When he doesn't know the Id of the customer, I need to generate a new one with letters instead of figures, to be able to recognize them.
What happens if it generates a string you have already used?
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
I put a test to avoid that and generate a new string until it's ok
(even if it is highly unlikely)