This is adapted for VB5/6, it's not hard to change it to VS12
Code
Dim Square(1 To 25, 1 To 25) As String
Dim Words(1 To 15) As String
Dim ralpha As String
Dim ran As Integer
Dim Success As Boolean
Dim First As Boolean
Dim q_ As Integer
Dim x_ As Integer
Dim y_ As Integer
Dim z_ As Integer
Dim Finished As String
Dim UnFinished As String
Private Sub roll__Click()
Randomize
If First = False Then 'Open a file for the words, once per application run
filename_string = "C:\Alex Edwards\Project 15\Words.txt"
Open filename_string For Input As #1
For x_ = 1 To 15 '15 Words, give them all values to x_
Input #1, input_string
Words(x_) = input_string
Next x_
For x_ = 1 To 15
Words(x_) = UCase(Words(x_)) 'Make sure they're all uppercase
Next x_
First = True 'ensure this won't happen again
End If
'===Refresh===
Randomize 'Fresh seed
Text1.Text = "" 'Fresh textbox
For y_ = 1 To 25 'Fresh two-dimensional array
For x_ = 1 To 25
Square(y_, x_) = ""
Next x_
Next y_
'===
For q_ = 1 To 15 'Do each word
roll = CInt(Int((4 - 1 + 1) * Rnd() + 1)) 'Find what direction (diagnol, vertical)
Flip = CInt(Int((2 - 1 + 1) * Rnd() + 1)) 'Find if backwards
selectedword = Words(q_) 'current word
newword = "" 'reset newword variable
If Flip = 1 Then 'If flip=1, reverse word
For x_ = 1 To Len(selectedword) 'For the length of word
newword = newword + Right(selectedword, 1) 'Add to new word
selectedword = Left(selectedword, Len(selectedword) - 1) 'Subtract from old
Next x_
Else
newword = selectedword 'assign default to newword
End If
'double check these
selectedword = newword
selectedwordcut = selectedword
'===Generate Words===
If roll = 1 Then
'==Horizontal==
Success = False
While Success = False 'Make sure the word will fit properly
selectedwordcut = selectedword
RYC = CInt(Int((25 - 1 + 1) * Rnd() + 1)) 'Y-axis Constant
RX = CInt(Int(((26 - Len(selectedword)) - 1 + 1) * Rnd() + 1)) 'X-axis non-constant
While Len(selectedwordcut) > 0 'Do until word is gone
'Following will make sure we can put it there
If Left(selectedwordcut, 1) = Square(RYC, RX) Or Square(RYC, RX) = "" Then
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1) 'subtract
RX = RX + 1 'Go to next box
z_ = z_ + 1 'add to counter
Else
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1) 'subtract
RX = RX + 1 'Go to next box
End If
Wend
selectedwordcut = selectedword 'reset
If z_ = Len(selectedwordcut) Then 'If counter is length of cut word
RX = RX - Len(selectedwordcut) 'reset RX to what it was before
For x_ = 1 To Len(selectedwordcut) 'For length of the word
Square(RYC, RX) = Left(selectedwordcut, 1) 'insert into array
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1) 'subtract
RX = RX + 1 'next box
Next x_
Success = True 'this worked
Else
selectedword = Words(q_) 'reset selected word to try again
End If
z_ = 0 'reset
Wend
'==
End If
If roll = 2 Then
'==Vertical==
Success = False
While Success = False
selectedwordcut = selectedword
RY = CInt(Int(((25 - Len(selectedword)) - 1 + 1) * Rnd() + 1)) 'Y axis is non-constant
RXC = CInt(Int((25 - 1 + 1) * Rnd() + 1)) 'X-axis is constant
While Len(selectedwordcut) > 0
If Left(selectedwordcut, 1) = Square(RY, RXC) Or Square(RY, RXC) = "" Then
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1)
RY = RY + 1 'Add to Y axis
z_ = z_ + 1
Else
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1)
RY = RY + 1 'Y axis
End If
Wend
selectedwordcut = selectedword
If z_ = Len(selectedwordcut) Then
RY = RY - Len(selectedwordcut) 'Reset Y axis
For x_ = 1 To Len(selectedwordcut)
Square(RY, RXC) = Left(selectedwordcut, 1)
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1)
RY = RY + 1
Next x_
Success = True
Else
selectedword = Words(q_)
End If
z_ = 0
Wend
'==
End If
If roll = 3 Then
'==DiagnolLR==
Success = False
While Success = False
selectedwordcut = selectedword
RY = CInt(Int(((25 - Len(selectedword)) - 1 + 1) * Rnd() + 1)) 'Neither are constant
RX = CInt(Int(((25 - Len(selectedword)) - 1 + 1) * Rnd() + 1))
While Len(selectedwordcut) > 0
If Left(selectedwordcut, 1) = Square(RY, RX) Or Square(RY, RX) = "" Then
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1)
RY = RY + 1 'Add to both
RX = RX + 1
z_ = z_ + 1
Else
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1)
RY = RY + 1 'Add to both
RX = RX + 1
End If
Wend
selectedwordcut = selectedword
If z_ = Len(selectedwordcut) Then
RY = RY - Len(selectedwordcut) 'Reset both
RX = RX - Len(selectedwordcut)
For x_ = 1 To Len(selectedwordcut)
Square(RY, RX) = Left(selectedwordcut, 1)
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1)
RY = RY + 1
RX = RX + 1
Next x_
Success = True
Else
selectedword = Words(q_)
End If
z_ = 0
Wend
'==
End If
If roll = 4 Then
'==DiagnolRL==
Success = False
While Success = False
selectedwordcut = selectedword
RY = CInt(Int(((21 - Len(selectedword)) - 1 + 1) * Rnd() + 1)) 'Neither constant
RX = CInt(Int((21 - Len(selectedword) + 1) * Rnd() + Len(selectedword)))
While Len(selectedwordcut) > 0
If Left(selectedwordcut, 1) = Square(RY, RX) Or Square(RY, RX) = "" Then
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1)
RY = RY + 1 'Add here
RX = RX - 1 'Subtract here, goes right to left now
z_ = z_ + 1
Else
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1)
RY = RY + 1
RX = RX - 1
End If
Wend
selectedwordcut = selectedword
If z_ = Len(selectedwordcut) Then
RY = RY - Len(selectedwordcut)
RX = RX + Len(selectedwordcut)
For x_ = 1 To Len(selectedwordcut)
Square(RY, RX) = Left(selectedwordcut, 1)
selectedwordcut = Right(selectedwordcut, Len(selectedwordcut) - 1)
RY = RY + 1
RX = RX - 1
Next x_
Success = True
Else
selectedword = Words(q_)
End If
z_ = 0
Wend
'==
End If
'===
Next q_
'===Fill Spaces===
For y_ = 1 To 25
For x_ = 1 To 25
If Len(Square(y_, x_)) = 0 Then Square(y_, x_) = " " 'Filling it with spaces
Next x_
Next y_
'===
'===Generate Search===
'This will echo it out to Text1
For y_ = 1 To 25
For x_ = 1 To 25
Text1.Text = Text1.Text + " " + Square(y_, x_)
Next x_
Text1.Text = Text1.Text + vbNewLine
Next y_
'===
UnFinished = Text1.Text
Text1.Text = ""
For y_ = 1 To 25
For x_ = 1 To 25
If Square(y_, x_) = " " Then Square(y_, x_) = Chr(Int((90 - 65 + 1) * Rnd() + 65))
Next x_
Next y_
For y_ = 1 To 25
For x_ = 1 To 25
Text1.Text = Text1.Text + " " + Square(y_, x_)
Next x_
Text1.Text = Text1.Text + vbNewLine
Next y_
Finished = Text1.Text
Text1.Text = UnFinished
End Sub
Private Sub fill_Click()
If Text1.Text = UnFinished Then Text1.Text = Finished Else Text1.Text = UnFinished
End Sub