d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Word Search Generator > Needing Some Guidance
123Next
Add Reply New Topic New Poll
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Mar 22 2013 07:01am
I'm stuck on doing a check to see if the word is already there, I would like the program to go on through with generating whatever, if the letters match

H
I
P
P O N I E S
O

^Example

Code

Public Class Form1

   Dim Square(0 To 14, 0 To 14) As String
   Dim Word1 As String
   Dim randomnc As Integer
   Dim randomc As Integer
   Dim t_ As Integer
   Dim Word1cut As String

   Private Sub generate_Click(sender As Object, e As EventArgs) Handles generate.Click
       Word1 = "OOOOO"

       Word1cut = Word1
       '=============Refresh======================
       Randomize()
       TextBox1.Text = ""
       For y_ = 0 To 14
           For x_ = 0 To 14
               Square(y_, x_) = ""
           Next
       Next
       '==========================================

       '============Generate Words================
           t_ = 0
       randomnc = Int(((12 - Len(Word1cut)) - 0 + 1) * Rnd()) + 0
           randomc = Int((14 - 0 + 1) * Rnd()) + 0
       If Square(randomc, randomnc + t_) = Microsoft.VisualBasic.Left(Word1cut, 1) Or Len(Square(randomc, randomnc + t_)) < 1 Then
           t_ = -1
           For z_ = 1 To Len(Word1)
               If Square(randomc, randomnc + t_) <> Microsoft.VisualBasic.Left(Word1cut, 1) Then
                   t_ = t_ + 1
                   Square(randomc, randomnc + t_) = Microsoft.VisualBasic.Left(Word1cut, 1)
                   Word1cut = Microsoft.VisualBasic.Right(Word1cut, Len(Word1cut) - 1)
               Else
                   'Erase z_ amount of steps
                   For x_ = 1 To z_
                       'flakjweklfj
                   Next
               End If
           Next
       End If
       '==========================================

       '============Fill Spaces===================
       For y_ = 0 To 14
           For x_ = 0 To 14
               If Len(Square(y_, x_)) < 1 Then Square(y_, x_) = Chr(CInt(Int((90 - 65 + 1) * Rnd() + 65)))
           Next
       Next
       '==========================================

       '============Generate Search===============
       For y_ = 0 To 14
           For x_ = 0 To 14
               TextBox1.Text = TextBox1.Text + " " + Square(y_, x_)
           Next
           TextBox1.Text = TextBox1.Text + vbNewLine
       Next
       '==========================================
   End Sub
End Class


I'm stuck at "flakjweklfj"
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Mar 27 2013 07:08pm
This is all coded now, I'll post an annotated version tomorrow.
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Apr 3 2013 03:22pm
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
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Apr 4 2013 10:23pm
did you code top to bottom in a single file or is that the contents of multiple files all pasted? ;o
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Apr 4 2013 10:42pm
Quote (Eep @ Apr 5 2013 12:23am)
did you code top to bottom in a single file or is that the contents of multiple files all pasted? ;o


if you actually knew vb you would see that is just one function denoted by the `private sub` and `end sub` phrases. was it that hard to actually try reading the code?

edit my bad. it was literally 1 function and 1 button procedure.

edit side note: vb makes my eyes bleed. i dont see why anyone still uses that syntax.

This post was edited by AbDuCt on Apr 4 2013 10:44pm
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Apr 4 2013 10:57pm
Quote (AbDuCt @ Apr 4 2013 11:42pm)
if you actually knew vb you would see that is just one function denoted by the `private sub` and `end sub` phrases. was it that hard to actually try reading the code?

edit my bad. it was literally 1 function and 1 button procedure.

edit side note: vb makes my eyes bleed. i dont see why anyone still uses that syntax.


did I read the code? no, there was too much the read ( referring to the 2nd code he posted )

Interesting to see a single function that large though, I haven't seen many like that.

Also are you tracking me or something because you come off stalkerish sometimes.

This post was edited by Eep on Apr 4 2013 10:58pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Apr 4 2013 11:58pm
Quote (Eep @ Apr 5 2013 12:57am)
did I read the code? no, there was too much the read ( referring to the 2nd code he posted )

Interesting to see a single function that large though, I haven't seen many like that.

Also are you tracking me or something because you come off stalkerish sometimes.


because you literally have done nothing besides follow the book and do your homework (basically nothing)

also why would i have to track you to make fun of your posts its not like this sub forum gets much attention aka your name is usually in the "last post" area on the main forums page.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Apr 5 2013 12:25am
Quote (AbDuCt @ Apr 5 2013 12:58am)
because you literally have done nothing besides follow the book and do your homework (basically nothing)

also why would i have to track you to make fun of your posts its not like this sub forum gets much attention aka your name is usually in the "last post" area on the main forums page.


I can't force myself to find things to do. That is not fun.

"make fun of your posts" sounds like you are using your time wisely. I really should stop treating you like a normal human being.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Apr 5 2013 01:24am
Quote (Eep @ Apr 5 2013 02:25am)
I can't force myself to find things to do. That is not fun.

"make fun of your posts" sounds like you are using your time wisely. I really should stop treating you like a normal human being.


takes literally 30 seconds to look at new posts in this sub forum and another 30 seconds to figure out why the post you made was retarded. do this once an hour and that would only be a total of 10 minutes or less that ive wasted. not much in retrospect that someone is averagely awake 600 minutes in a day. thats 1/60 of their day they spent on jsp. NOT THAT MUCH LOL

edit:: numbers are figurative and may take less than or more than the time specified which would cause the total time to vary. not by much though because its reality easy to spot why what you say is stupid inside a posts.

This post was edited by AbDuCt on Apr 5 2013 01:25am
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Apr 5 2013 01:39am
Quote (AbDuCt @ Apr 5 2013 02:24am)
takes literally 30 seconds to look at new posts in this sub forum and another 30 seconds to figure out why the post you made was retarded. do this once an hour and that would only be a total of 10 minutes or less that ive wasted. not much in retrospect that someone is averagely awake 600 minutes in a day. thats 1/60 of their day they spent on jsp. NOT THAT MUCH LOL

edit:: numbers are figurative and may take less than or more than the time specified which would cause the total time to vary. not by much though because its reality easy to spot why what you say is stupid inside a posts.


once an hour, x days since the day I apparently turned you into my own stalker.

It all adds up.

It is amusing how much you get off on this though. The more you post the more interested I become in your personal life. I don't think I have ever met someone who tried so hard to assert himself in this way.
Go Back To Programming & Development Topic List
123Next
Add Reply New Topic New Poll