Boggle is a type of words puzzle game where the players can form as many words as possible from the characters displayed on a nxn square. Words can be formed in many ways, from left to right, from right to left, top to bottom, bottom to top, diagonal, zigzag manner and more.
In this example, we have designed a 5x5 boggle. This is only a boogle board generator so the players have to write the words on a piece of paper.Each time we press the shuffle button, a different set of characters will appear. In order to achieve this, we use the chr() function and the Rnd function to randomly generate the characters.
Alphabet A to Z correpond to Chr(65) to chr(90), therefore we need to generate random numbers between 65 to 90. The formula to generate random numbers between two numbers is:
m = Int((MaxValue - MinValue + 1) * Rnd) + MinValue
Therefore, the formula to generate random numbers between 65 and 90 is RndNum=Int(26)+65, which means we can generate random alphabet using chr(m) in a For Next Loop.
To display the alphabets in 25 cells on the worksheet, we use a nexted For Next loop.
Private Sub cmd_Shuffle_Click() Dim m As Integer For i = 2 To 6 For j = 2 To 6 m = Int(26 * Rnd) + 65 Sheet1.Cells(i, j) = Chr(m) Next Next End Sub