Di bawah ini merupakan fungsi untuk membuat sebuah kata secara acak.
Option Explicit
Public Function RandomString(Optional Max As Integer = 5) As String
Dim sAlpha As String
Dim iLoop As Integer
Dim iRandNum As Integer
Dim sMatch As String
Dim str As String
sAlpha = "abcdefghijklmnopqrstuvwxyz"
Randomize
For iLoop = 1 To Max
iRandNum = Int((26 - 1 + 1) * Rnd + 1)
sMatch = Mid(sAlpha, iRandNum, 1)
str = str & sMatch
Next iLoop
RandomString = str
End Function
Contoh penggunaan fungsi menampilkan kata secara acak
Private Sub Command1_Click()
MsgBox RandomString 10
End Sub