1. ## Solved: Separate generated password with dashes

This code generates a random generated password. Can someone assist with editing this code to increase the characters generated from 10 characters to 16 characters. Also separate each 4th character with a dash.

ex.

INIw-yOH9-Aewy-OH93

[vba]Public Function rndStr(ByRef StrLength As Long) As String
Dim b() As Byte, keyArr() As Byte
Dim i As Long
Let keyArr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
ReDim b(1 To StrLength * 2)
For i = 1 To StrLength * 2 Step 2
Let b(i) = keyArr(Int(((UBound(keyArr) + 1) \ 2) * Rnd + 1) * 2 - 2)
Next
Let rndStr = b
End Function[/vba]

2. Originally Posted by av8tordude
to increase the characters generated from 10 characters to 16 characters
Change the 10 argument when you call it, to 16.
Originally Posted by av8tordude
separate each 4th character with a dash
[VBA]Public Function RndStr(ByRef StrLength As Long) As String
Dim b() As Byte, keyArr() As Byte, TempStr1 As String, TempStr2 As String
Dim i As Long
Let keyArr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
ReDim b(1 To StrLength * 2)
For i = 1 To StrLength * 2 Step 2
Let b(i) = keyArr(Int(((UBound(keyArr) + 1) \ 2) * Rnd + 1) * 2 - 2)
Next
Let TempStr1 = b
For i = 1 To StrLength Step 4
TempStr2 = TempStr2 & Mid(TempStr1, i, 4) & "-"
Next i
TempStr2 = Left(TempStr2, Len(TempStr2) - 1)
RndStr = TempStr2
End Function
[/VBA]

3. Thank you p45cal. Works great!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•