Pink Poogle Toy Forum

The official community of Pink Poogle Toy
Main Site
NeoDex
It is currently Mon Nov 25, 2024 7:23 am

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Visual Basics Hangman Program
PostPosted: Mon Oct 31, 2005 3:42 pm 
Honorary Member
Honorary Member
User avatar

Posts: 8027
Joined: Mon May 31, 2004 5:00 am
Location: Thornhill, Ontario
Gender: Male
In Computers, apparently we have to do a Hangman program. This program is very confusing to me, I don't understand what to do. This is my code so far,

Code:
Dim strGuessWord As String
Dim strHiddenWord As String
Dim strMusic(1 To 5) As String
Dim strMovies(1 To 5) As String
Dim strAnimals(1 To 5) As String
Dim strSports(1 To 5) As String
Dim strCountries(1 To 5) As String
Dim intLength As Integer


Private Sub cmdDisplay_Click()
intIndex = Int(Rnd * 5) + 1

Select Case intCategory
   Case 1
       strGuessWord = strSports(intIndex)
   Case 2
       strGuessWord = strMovies(intIndex)
   Case 3
       strGuessWord = strAnimals(intIndex)
   Case 4
       strGuessWord = strMusic(intIndex)
   Case 5
       strGuessWord = strCountries(intIndex)
End Select

intLength = Len(strGuessWord)
strHiddenWord = String(intLength, "*")
lblUserWord(1) = strHiddenWord

End Sub

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdletters_Click(Index As Integer)

strUserWord = Chr(Index)

End Sub

Private Sub cmdstart_Click()
Call SelectGuess
cmdstart.Caption = "New Word"
Call EnableLetters
End Sub

Private Sub Form_Load()
strMovies(1) = "YOU GOT SERVED"
strMovies(2) = "X-MEN 2: X-MEN UNITED"
strMovies(3) = "FRIDAY AFTER NEXT"
strMovies(4) = "FREAKY FRIDAY"
strMovies(5) = "BRINGING DOWN THE HOUSE"
strMusic(1) = "KELLY CLARKSON BECAUSE OF YOU"
strMusic(2) = "EVANESCENCE MY IMMORTAL"
strMusic(3) = "KANYE WEST GOLD DIGGER"
strMusic(4) = "MARIAH CAREY SHAKE IT OFF"
strMusic(5) = "BEYONCE NAUGHTY GIRL"
strAnimals(1) = "ELEPHANT"
strAnimals(2) = "PARROT"
strAnimals(3) = "KOALA BEARS"
strAnimals(4) = "SNAKE"
strAnimals(5) = "BUFFALO"
strSports(1) = "FOOTBALL"
strSports(2) = "HOCKEY"
strSports(3) = "BASKETBALL"
strSports(4) = "TENNIS"
strSports(5) = "SWIMMING"
strCountries(1) = "CANADA"
strCountries(2) = "PORTUGAL"
strCountries(3) = "FIJI"
strCountries(4) = "SWITZERLAND"
strCountries(5) = "DENMARK"

Image1.Visible = False
Image2.Visible = False
Image3.Visible = False
Image4.Visible = False
Image5.Visible = False
Image6.Visible = False
Image7.Visible = False
End Sub

Private Sub lblUserWord_Click(Index As Integer)
strLetter = cmdletter
End Sub



And then for my option buttons, my code is as follows,

Code:
Private Sub cmdstart_Click()
frmHangman2.Visible = True
frmCategories.Visible = False
End Sub

Private Sub optAnimals_Click()
intCategory = 3
End Sub

Private Sub optCountries_Click()
intCategory = 5
End Sub

Private Sub optmovies_Click(Index As Integer)
intCategory = 2
End Sub

Private Sub optMusic_Click()
intCategory = 4
End Sub

Private Sub optSports_Click()
intCategory = 1
End Sub


And when I press the command button Display, only the number of letters in a word shows up. If you click a letter, nothing happens. Can anyone help me get this program to work? Any help is appreciated.


Image
Set by Medli


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 01, 2005 5:00 pm 
Administrator
Administrator
User avatar

Posts: 1140
Joined: Mon May 31, 2004 1:36 pm
You're pressing cmdstart, right? Lack of capitalization in your otherwise capitalized code suggests that VB does not associate your event handler with the button -- check that the button is called cmdstart, or just put a breakpoint at the line to see if it runs.

If frmHangman2 is a frame (window), you need to use .Show and .Hide, I think. If it's a frame (container element), you can get away with .visible.

Code:
Private Sub cmdletters_Click(Index As Integer)
strUserWord = Chr(Index)
End Sub

Rather than using Chr(Index) (which you can... as long as your indexes range from 65 upwards), you should do
Code:
strUserWord = UCASE(cmdletters(Index).caption)


Image
Will you stop with the honour stuff?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 01, 2005 9:03 pm 
Honorary Member
Honorary Member
User avatar

Posts: 8027
Joined: Mon May 31, 2004 5:00 am
Location: Thornhill, Ontario
Gender: Male
Hunter Lupe wrote:
You're pressing cmdstart, right? Lack of capitalization in your otherwise capitalized code suggests that VB does not associate your event handler with the button -- check that the button is called cmdstart, or just put a breakpoint at the line to see if it runs.


First off, thank you very much for taking a look at my code.

I actually realised the cmdstart is not supposed to be in the code. I changed cmdstart to cmddisplay and you can see the code there.

Quote:
If frmHangman2 is a frame (window), you need to use .Show and .Hide, I think. If it's a frame (container element), you can get away with .visible.

Code:
Private Sub cmdletters_Click(Index As Integer)
strUserWord = Chr(Index)
End Sub

Rather than using Chr(Index) (which you can... as long as your indexes range from 65 upwards), you should do
Code:
strUserWord = UCASE(cmdletters(Index).caption)


The index does range from 65+ and I would assume it worked. But, is the code you posted the same thing? As in, does it achieve the same results?


Image
Set by Medli


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group