Feb 13, 2002 #1 knovak Programmer Dec 18, 2001 17 US I need to generate a random 6 character string? Any suggestions on how to do this? Thanks, Kyle
Feb 13, 2002 #2 jhall156 Programmer Aug 27, 2001 711 US Do you want all characters, only printables, only alphas? JHall Upvote 0 Downvote
Feb 13, 2002 1 #3 Jon4747 Programmer Aug 22, 2001 234 CA Hi Kyle, This will give you a string of all ascii values from 33 to 126 inclusive: Randomize For intR = 0 To 5 intA = Int(Rnd * 93) + 33 str = str & Chr(intA) Next This will give you alphanumeric only(upper and lower case) Randomize intR = 0 While (intR <= 5) intA = Int(Rnd * 93) + 33 Select Case intA Case 48 To 57 str = str & Chr(intA) intR = intR + 1 Case 65 To 90 str = str & Chr(intA) intR = intR + 1 Case 97 To 122 str = str & Chr(intA) intR = intR + 1 End Select Wend Jon Upvote 0 Downvote
Hi Kyle, This will give you a string of all ascii values from 33 to 126 inclusive: Randomize For intR = 0 To 5 intA = Int(Rnd * 93) + 33 str = str & Chr(intA) Next This will give you alphanumeric only(upper and lower case) Randomize intR = 0 While (intR <= 5) intA = Int(Rnd * 93) + 33 Select Case intA Case 48 To 57 str = str & Chr(intA) intR = intR + 1 Case 65 To 90 str = str & Chr(intA) intR = intR + 1 Case 97 To 122 str = str & Chr(intA) intR = intR + 1 End Select Wend Jon
Feb 14, 2002 Thread starter #4 knovak Programmer Dec 18, 2001 17 US Thanks everyone! Upvote 0 Downvote
Feb 14, 2002 #5 Custom24 Programmer Nov 27, 2001 591 GB If you want a string which is not likely to be repeated in the future then try this one MySixString = Hex$(CLng(Mid(Replace((CStr(CDbl(Now))), ".", "", 1, , vbTextCompare), 3, 9))) It converts the current time into a hexadecimal value - I use it sometimes for primary keys and the like, but it is a bit messy Mark Upvote 0 Downvote
If you want a string which is not likely to be repeated in the future then try this one MySixString = Hex$(CLng(Mid(Replace((CStr(CDbl(Now))), ".", "", 1, , vbTextCompare), 3, 9))) It converts the current time into a hexadecimal value - I use it sometimes for primary keys and the like, but it is a bit messy Mark