Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 11-05-2019, 09:10 AM   #1
murray83
sega collector
 
Join Date: Mar 2017
Location: Daventry, UK
Posts: 454
Thanks: 110
Thanked 1 Time in 1 Post
murray83 is on a distinguished road
Hangman Style Search

Howdy access gods

Question is can you or is there a function with vba or sql to check whether a string in a text box contains certain characters

so if the word was "Microsoft and the user asked does it have any O it would then put two O's and if it was word without any O it would then add a bit of the gallows


cheers

murray83 is offline   Reply With Quote
Old 11-05-2019, 09:21 AM   #2
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,653
Thanks: 58
Thanked 1,459 Times in 1,440 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Hangman Style Search

Hi. Don't think there's anything pre-built. You can certainly create one.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
The Following User Says Thank You to theDBguy For This Useful Post:
murray83 (11-05-2019)
Old 11-05-2019, 09:25 AM   #3
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,370
Thanks: 556
Thanked 948 Times in 897 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Hangman Style Search

Well, it depends on whether you are actually making a hangman game or not. If you're going to make a hangman game then you will want to divide your word out, with each letter in a single text box..

More information is required before the the correct answer can be given.

However to give you a start, have a look at this vb6 code, it should give you some ideas on how to go about it, in fact that's where I got the idea of putting each letter in a separate text box!

http://www.vbforums.com/showthread.p...n-quot-program


Code:
Option Explicit
Dim myWord As String
Dim myLetters() As String
Dim numWrongGuesses As Integer
Dim bCorrect As Boolean
Private Sub Command1_Click()
Dim myGuess As String, numBlacks As Integer, X As Integer, y As Integer
numBlacks = 0
myGuess = UCase(InputBox("Guess a Letter"))
If Len(myGuess) = 1 Then
    bCorrect = False
    For X = 0 To Len(myWord) - 1  'number of visible text boxes
        If myGuess = Text1(X).Text Then
            Text1(X).ForeColor = vbBlack
            bCorrect = True
            For y = 0 To Len(myWord) - 1
                If Text1(y).ForeColor = vbBlack Then
                   numBlacks = numBlacks + 1
                   If numBlacks = Len(myWord) Then
                      MsgBox ("Congratulations!  You WIN!")
                   End If
                End If
            Next y
         End If
     Next X
     If bCorrect = False Then
        numWrongGuesses = numWrongGuesses + 1
        Label1.Visible = True
        Timer1.Enabled = True
        drawman
     End If
End If
End Sub
Private Sub drawman()
    Select Case numWrongGuesses
    Case 1
       Shape1.Visible = True
    Case 2
       Shape1.Visible = True
       Line1.Visible = True
    Case 3
       Shape1.Visible = True
       Line1.Visible = True
       Line2.Visible = True
    Case 4
       Shape1.Visible = True
       Line1.Visible = True
       Line2.Visible = True
       Line3.Visible = True
    Case 5
       Shape1.Visible = True
       Line1.Visible = True
       Line2.Visible = True
       Line3.Visible = True
       Line4.Visible = True
    Case 6
       Shape1.Visible = True
       Line1.Visible = True
       Line2.Visible = True
       Line3.Visible = True
       Line4.Visible = True
       Line5.Visible = True
       MsgBox "You Lose!"
       Dim X As Integer
       For X = 0 To Len(myWord) - 1
           Text1(X).ForeColor = vbBlack
       Next X
    End Select
End Sub
Private Sub Command2_Click()
Dim X As Integer
For X = 0 To 9
   Text1(X).Visible = False
Next X
List1.ListIndex = Val(Combo1.Text) - 1
myWord = List1.Text
ReDim myLetters(Len(myWord)) As String
For X = 0 To Len(myWord) - 1
   Text1(X).Visible = True  'temp for testing
   Text1(X).Text = Mid(myWord, X + 1, 1)
   Text1(X).ForeColor = vbWhite
Next X
Shape1.Visible = False
Line1.Visible = False
Line2.Visible = False
Line3.Visible = False
Line4.Visible = False
Line5.Visible = False
End Sub
Private Sub Form_Load()
List1.AddItem ("COMPUTER")
List1.AddItem ("HOUSE")
List1.AddItem ("VISUAL")
List1.AddItem ("BASIC")
List1.AddItem ("STUDIO")
List1.AddItem ("LESSONS")
Dim X As Integer
For X = 0 To List1.ListCount - 1
    Combo1.AddItem Str(X + 1)
Next X
Combo1.Text = "1"
End Sub
Private Sub Timer1_Timer()
Label1.Visible = False
Timer1.Enabled = False
End Sub

__________________
Code:
                 |||||
               @(~‘^‘~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
The Following User Says Thank You to Uncle Gizmo For This Useful Post:
murray83 (11-05-2019)
Old 11-05-2019, 10:23 AM   #4
murray83
sega collector
 
Join Date: Mar 2017
Location: Daventry, UK
Posts: 454
Thanks: 110
Thanked 1 Time in 1 Post
murray83 is on a distinguished road
Talking Re: Hangman Style Search

Quote:
Originally Posted by Uncle Gizmo View Post
Well, it depends on whether you are actually making a hangman game or not. If you're going to make a hangman game then you will want to divide your word out, with each letter in a single text box..

More information is required before the the correct answer can be given.

However to give you a start, have a look at this vb6 code, it should give you some ideas on how to go about it, in fact that's where I got the idea of putting each letter in a separate text box!

http://www.vbforums.com/showthread.p...n-quot-program


Code:
Option Explicit
Dim myWord As String
Dim myLetters() As String
Dim numWrongGuesses As Integer
Dim bCorrect As Boolean
Private Sub Command1_Click()
Dim myGuess As String, numBlacks As Integer, X As Integer, y As Integer
numBlacks = 0
myGuess = UCase(InputBox("Guess a Letter"))
If Len(myGuess) = 1 Then
    bCorrect = False
    For X = 0 To Len(myWord) - 1  'number of visible text boxes
        If myGuess = Text1(X).Text Then
            Text1(X).ForeColor = vbBlack
            bCorrect = True
            For y = 0 To Len(myWord) - 1
                If Text1(y).ForeColor = vbBlack Then
                   numBlacks = numBlacks + 1
                   If numBlacks = Len(myWord) Then
                      MsgBox ("Congratulations!  You WIN!")
                   End If
                End If
            Next y
         End If
     Next X
     If bCorrect = False Then
        numWrongGuesses = numWrongGuesses + 1
        Label1.Visible = True
        Timer1.Enabled = True
        drawman
     End If
End If
End Sub
Private Sub drawman()
    Select Case numWrongGuesses
    Case 1
       Shape1.Visible = True
    Case 2
       Shape1.Visible = True
       Line1.Visible = True
    Case 3
       Shape1.Visible = True
       Line1.Visible = True
       Line2.Visible = True
    Case 4
       Shape1.Visible = True
       Line1.Visible = True
       Line2.Visible = True
       Line3.Visible = True
    Case 5
       Shape1.Visible = True
       Line1.Visible = True
       Line2.Visible = True
       Line3.Visible = True
       Line4.Visible = True
    Case 6
       Shape1.Visible = True
       Line1.Visible = True
       Line2.Visible = True
       Line3.Visible = True
       Line4.Visible = True
       Line5.Visible = True
       MsgBox "You Lose!"
       Dim X As Integer
       For X = 0 To Len(myWord) - 1
           Text1(X).ForeColor = vbBlack
       Next X
    End Select
End Sub
Private Sub Command2_Click()
Dim X As Integer
For X = 0 To 9
   Text1(X).Visible = False
Next X
List1.ListIndex = Val(Combo1.Text) - 1
myWord = List1.Text
ReDim myLetters(Len(myWord)) As String
For X = 0 To Len(myWord) - 1
   Text1(X).Visible = True  'temp for testing
   Text1(X).Text = Mid(myWord, X + 1, 1)
   Text1(X).ForeColor = vbWhite
Next X
Shape1.Visible = False
Line1.Visible = False
Line2.Visible = False
Line3.Visible = False
Line4.Visible = False
Line5.Visible = False
End Sub
Private Sub Form_Load()
List1.AddItem ("COMPUTER")
List1.AddItem ("HOUSE")
List1.AddItem ("VISUAL")
List1.AddItem ("BASIC")
List1.AddItem ("STUDIO")
List1.AddItem ("LESSONS")
Dim X As Integer
For X = 0 To List1.ListCount - 1
    Combo1.AddItem Str(X + 1)
Next X
Combo1.Text = "1"
End Sub
Private Sub Timer1_Timer()
Label1.Visible = False
Timer1.Enabled = False
End Sub
cheers for that i thought some where along id have to split the word down this is what i have v basically put together, no laughing
Attached Files
File Type: accdb Hangman.accdb (408.0 KB, 4 views)
murray83 is offline   Reply With Quote
Old 11-05-2019, 10:41 AM   #5
murray83
sega collector
 
Join Date: Mar 2017
Location: Daventry, UK
Posts: 454
Thanks: 110
Thanked 1 Time in 1 Post
murray83 is on a distinguished road
Re: Hangman Style Search

Sorry for DP but have done a bit of more work and not sure but im thinking i need to count cycles when the player puts in a letter

see updated db attached
Attached Files
File Type: accdb Hangman.accdb (420.0 KB, 4 views)
murray83 is offline   Reply With Quote
Old 11-05-2019, 11:12 AM   #6
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,370
Thanks: 556
Thanked 948 Times in 897 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Hangman Style Search

I'm not sure if you want this, I get the impression you want to build it yourself! However, if you want a pre-made one, then have a look at this....

By the way it's not mine and I have no idea where I got it from, I've had it for years!

Attached Images
File Type: jpg Hangman.JPG (43.3 KB, 94 views)
Attached Files
File Type: zip Hangman.zip (131.7 KB, 8 views)
__________________
Code:
                 |||||
               @(~‘^‘~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
The Following User Says Thank You to Uncle Gizmo For This Useful Post:
murray83 (11-05-2019)
Old 11-05-2019, 11:37 AM   #7
murray83
sega collector
 
Join Date: Mar 2017
Location: Daventry, UK
Posts: 454
Thanks: 110
Thanked 1 Time in 1 Post
murray83 is on a distinguished road
Re: Hangman Style Search

Quote:
Originally Posted by Uncle Gizmo View Post
I'm not sure if you want this, I get the impression you want to build it yourself! However, if you want a pre-made one, then have a look at this....

By the way it's not mine and I have no idea where I got it from, I've had it for years!

i shall look at the code and thanks yeah want to try and build it my self, but thanks again for pointers so far I may end up coming back for more hehe

murray83 is offline   Reply With Quote
Old 11-15-2019, 04:57 AM   #8
murray83
sega collector
 
Join Date: Mar 2017
Location: Daventry, UK
Posts: 454
Thanks: 110
Thanked 1 Time in 1 Post
murray83 is on a distinguished road
Re: Hangman Style Search

hi you lovely people

so trying to search on that website which starts with a G, and all i can find on 'Next Item' is not of any help to me in access vba

as im trying to get the guessing part run through each square and then if it has the guessed letter put it

for now i haven't got an else i will have a counter and tries which link to a noose

but my code is wrong some slight help would be appreciated cheers

see attached for code and example
Attached Images
File Type: png ok.png (23.6 KB, 4 views)
Attached Files
File Type: accdb Hang wiv two forms.accdb (548.0 KB, 4 views)
murray83 is offline   Reply With Quote
Old 11-15-2019, 05:20 AM   #9
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,285
Thanks: 97
Thanked 2,032 Times in 1,979 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Hangman Style Search

murray83,

Here is another hangman game for Access from the forum. It's from an older post, but may contain some code or approach of interest to you. Sometimes good/helpful to see different approaches to similar problem.
Good luck.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
The Following User Says Thank You to jdraw For This Useful Post:
murray83 (11-15-2019)
Old 11-15-2019, 06:00 AM   #10
murray83
sega collector
 
Join Date: Mar 2017
Location: Daventry, UK
Posts: 454
Thanks: 110
Thanked 1 Time in 1 Post
murray83 is on a distinguished road
Re: Hangman Style Search

Quote:
Originally Posted by jdraw View Post
murray83,

Here is another hangman game for Access from the forum. It's from an older post, but may contain some code or approach of interest to you. Sometimes good/helpful to see different approaches to similar problem.
Good luck.
that is what i mean boy


shame as its locked down though so cant peak at the code
murray83 is offline   Reply With Quote
Old 11-15-2019, 06:49 AM   #11
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,285
Thanks: 97
Thanked 2,032 Times in 1,979 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Hangman Style Search

Sorry about that. I didn't realize it was password protected. Should have checked- sorry.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
Old 11-15-2019, 08:17 AM   #12
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,892
Thanks: 38
Thanked 574 Times in 539 Posts
MajP has a spectacular aura about MajP has a spectacular aura about
Re: Hangman Style Search

The code is not locked, just select show all access objects in the navigation pane.

Import your form into the database
Change code to
To modify the hangman to use a selected word instead of random word

Code:
Private Sub cmdChoose_Click()
  Dim wrd As String
  Me.Visible = False
  If Trim(Me.WordList & " ") <> "" Then
    wrd = Me.WordList
    DoCmd.OpenForm "frmHangMan", , , , , , wrd
  End If
End Sub
update the frmHangMan code to

I greatly reduced the code using some tags and commond functions.

[code]
Private Sub cmdReset_Click()
'Start new game
NewGame
intPoints = 0
lblPoints.Caption = "Points : " & intPoints
HideBody
End Sub

Private Sub Form_Load()
If Not Trim(Me.OpenArgs & " ") = "" Then
NewGame
End If
End Sub

Private Sub SelectWord()
strWord = Me.OpenArgs
ResetLetters
End Sub

Private Sub CheckLetter()
On Error GoTo ErrorHandler
'Checks the letter entered against the random word
Dim i As Integer
Dim booGotLetter As Boolean
dim ID as string
booGotLetter = False
Dim strSingleLetter As String

'Go through the selected word
For i = 1 To intWordLength
'Get letter from word
strSingleLetter = Right(Left(strWord, i), 1)

'Check if selected letter is same as letter in word
If strLetter = strSingleLetter Then

'Increment got letters count
intLettersGot = intLettersGot + 1
booGotLetter = True

'Place the letter on the board
If I < 10 then
ID = "0" & I
else
id = cstr(i)
end if
me.controls("lblLetter" & ID).Caption = strLetter
End If
Next i

'Check if the user got the whole word finished
If intLettersGot = intWordLength Then
'They have completed the word
intPoints = intPoints + intHangman
lblPoints.Caption = "Points : " & intPoints
If MsgBox("Well done, you have beaten the hangman!" & vbCrLf & vbCrLf & _
"Would you like another go?", vbYesNo, "Congratulations") = vbYes Then
'User wants another go
NewGame
Else
'Close form
DoCmd.Close acForm, "frmHangman"
End If
End If

'Check if the user got a letter
If booGotLetter = False Then
'Didn't get a letter
intHangman = intHangman - 1
End If

'Update screen details
lblTries.Caption = "Tries Remaining : " & intHangman
hidebody
head.Visible = (intHangman = 9)
body.Visible = (intHangman = 8)
right_arm.Visible = (intHangman = 7)
left_arm.Visible = (intHangman = 6)
right_leg.Visible = (intHangman = 5)
left_leg.Visible = (intHangman = 4)
right_hand.Visible = (intHangman = 3)
left_hand.Visible = (intHangman = 2)
right_foot.Visible = (intHangman = 1)
'Check if the game is over!
If intHangman = 0 Then
'Game over
intPoints = intPoints - 10
If intPoints < 1 Then intPoints = 0
lblPoints.Caption = "Points : " & intPoints
hung.Visible = True
If MsgBox("Sorry, you did not get the word!" & vbCrLf & vbCrLf & _
"Would you like to try again?", vbYesNo, "Unlucky!") = vbYes Then
'New game
NewGame
Exit Sub
Else
'Quit
DoCmd.Close acForm, "frmHangman"
Exit Sub
End If
End If
Exit Sub

ErrorHandler:
'Close the form
DoCmd.Close acForm, "frmHangman"
End Sub

Private Sub NewGame()
'Set variables and screen for a new game
SelectWord

'Reset all the command buttons
enableCommands
'Hide body
resetBody

'Reset letters got
intLettersGot = 0
intHangman = 10
lblTries.Caption = "Tries Remaining : " & intHangman
End Sub

Public Sub EnableCommands
dim ctrl as access.control
for each ctrl in me.controls
if ctrl.tag = "Command" then
ctrl.enabled = true
end if
next ctrl
MajP is online now   Reply With Quote
Old 11-15-2019, 08:47 AM   #13
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,285
Thanks: 97
Thanked 2,032 Times in 1,979 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Hangman Style Search

Interesting -- still asking me for a password???


__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
Old 11-15-2019, 09:22 AM   #14
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,892
Thanks: 38
Thanked 574 Times in 539 Posts
MajP has a spectacular aura about MajP has a spectacular aura about
Re: Hangman Style Search

My fault, I thought you were talking about the first db. The first DB is nicer in my opinion, but should be easy to modify the code. If you do not want the command buttons
MajP is online now   Reply With Quote
Old 11-15-2019, 09:32 AM   #15
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,285
Thanks: 97
Thanked 2,032 Times in 1,979 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Hangman Style Search

Yes, I thought there may be some miscommunication. I was just offering that link as another approach to code underlying "Hangman" for reference.
Glad the issue has been cleared.

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
Reply

Tags
characters , string

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Style and Window's Style form Border Jho_1994 Forms 4 11-15-2014 04:04 PM
"Google" style search function QueenKirsty Modules & VBA 12 07-14-2009 03:14 PM
Access 07 Search Style Lord Justin Forms 1 06-22-2008 06:19 PM
Print Style different from preview style lxh Reports 2 04-11-2004 08:38 AM
Problem with UK style Short date style (dd/mm/yyyy) - it's REALLY wierd! Sharky II General 3 09-14-2003 02:01 PM




All times are GMT -8. The time now is 02:22 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World