|
-
Feb 21st, 2018, 08:00 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Not Defined..? VS 2017
Im getting the same message on each of the red areas of my code saying their not defined..Am I missing something? Also there is another message im getting bout the area I marked in blue saying expression expected?
Code:
Public Class GameForm
' Define variables
Dim dsQuestions As String 'Object variable
Dim numWord As Integer ' To hold index of word
Dim word As String ' Hold actual word
Dim numWrongGuesses As Integer ' Hold number of wrong guesses
Dim numRightGuesses As Integer ' Hold number of right guesses
Dim gameStarted As Boolean = False ' Indicate if game has started or not
Private Sub GameForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Disable txtGuess textbox.
txtGuess.Enabled =
' Set numWord variable.
Dim numWord As Integer = 0
' Call the Load Data method.
LoadData()
End Sub
Private Sub QuitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles QuitToolStripMenuItem.Click
' Close the form
Me.Close()
End Sub
Private Sub NewToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewToolStripMenuItem.Click
Dim dsQuestions As New QuestionDataSet
Dim numWord As Integer = 1
numWord += 1
Dim word As String
Dim numWrongGuesses As Integer = 10
Dim numRightGuesses As Integer = 5
Dim gameStarted As Boolean = True
' Initialize controls
lblUnitDescription.Text = "Choose a game"
txtGuess.Text = lblGuessALetter.Text
' Clear text of all labels.
lblUnitDescription.Text = String.Empty
txtGuess.Clear()
lblLetter0.Text = String.Empty
lblLetter1.Text = String.Empty
lblLetter2.Text = String.Empty
lblLetter3.Text = String.Empty
lblLetter4.Text = String.Empty
lblLetter5.Text = String.Empty
lblLetter6.Text = String.Empty
lblLetter7.Text = String.Empty
lblLetter8.Text = String.Empty
lblLetter9.Text = String.Empty
lblLetter10.Text = String.Empty
lblLetter11.Text = String.Empty
' Enable txtGuess.
txtGuess.Enabled = True
' Set the focus to txtGuess.
txtGuess.Focus()
' Gets word column row
Try
word = CStr(dsQuestions.Words(numWord)(1))
' Gets unit description
lblUnitDescription.Text = CStr(dsQuestions.Words(numWord).UnitsRow(1))
Catch
' Set label control for character.
lblLetter0.Text = "_"
lblLetter1.Text = "_"
lblLetter2.Text = "_"
lblLetter3.Text = "_"
lblLetter4.Text = "_"
lblLetter5.Text = "_"
lblLetter6.Text = "_"
lblLetter7.Text = "_"
lblLetter8.Text = "_"
lblLetter9.Text = "_"
lblLetter10.Text = "_"
lblLetter11.Text = "_"
Dim ch As Char = CChar(CStr(0))
Dim ch1 As Char = "_"
Dim ch2 As Char = "_"
Dim ch3 As Char = "_"
Dim ch4 As Char = "_"
Dim ch5 As Char = "_"
Dim ch6 As Char = "_"
Dim ch7 As Char = "_"
Dim ch8 As Char = "_"
Dim ch9 As Char = "_"
Dim ch10 As Char = "_"
Dim ch11 As Char = "_"
End Try
End Sub
Private Sub txtGuess_TextChanged(sender As Object, e As EventArgs) Handles txtGuess.TextChanged
Dim gameStarted As Boolean = True
Dim word As String = ""
Dim numRightGuesses As Integer = 5
Dim ch As Char
If gameStarted = True Then
If word.Contains(txtGuess.Text) Then
SetRightLetterLabels(word, ch)
numRightGuesses += 1
End If
ElseIf word.Contains(txtGuess.Text) = False Then
pboxHangman.ImageLocation = “images\Hangman-” & numWrongGuesses & “.png”
numWrongGuesses += 1
End If
CheckProgress()
End Sub
Private Sub CheckProgress()
' Calculates the total number of tries.
Dim numTries As Integer
numTries = numRightGuesses + numWrongGuesses
' Displays messages
If numRightGuesses = 5 Then
MessageBox.Show("You in 5 tries!" & ControlChars.CrLf &
"Do you want to play another game?", "You won!",
MessageBoxButtons.YesNo, MessageBoxIcon.Information)
ElseIf numWrongGuesses = 10 Then
MessageBox.Show("You in 10 tries. The word was ''." & ControlChars.CrLf &
"Do you want to play another game?", "You lost",
MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
End If
End Sub
Private Sub WonGame()
End Sub
Private Sub LostGame()
Dim numWrongGuesses As Integer
If numWrongGuesses > 6 Then
numWrongGuesses = True
End If
End
lblLetter0.Text = "_"
lblLetter1.Text = "_"
lblLetter2.Text = "_"
lblLetter3.Text = "_"
lblLetter4.Text = "_"
lblLetter5.Text = "_"
lblLetter6.Text = "_"
lblLetter7.Text = "_"
lblLetter8.Text = "_"
lblLetter9.Text = "_"
lblLetter10.Text = "_"
lblLetter11.Text = "_"
End Sub
Private Sub LoadData()
Dim dsQuestions As New QuestionDataSet
Dim taUnits As New QuestionDataSetTableAdapters.UnitsTableAdapter
Dim taWords As New QuestionDataSetTableAdapters.WordsTableAdapter
taUnits.Fill(dsQuestions.Units)
taWords.Fill(dsQuestions.Words)
End Sub
Private Function FindLabel(ByVal i As Integer) As Control
' Finds the right label in the word panel
Dim label = panelWord.Controls.Find("lblLetter", False)(0)
Return label
End Function
Private Sub SetRightLetterLabels(ByVal word As String, ByVal ch As Char)
For i As Integer = 0 To word.Length - 1
' Check for each letter and set the appropriate letter
If word.Chars(i) = ch Then
FindLabel(i).Text = ch
End If
Next
End Sub
End Class
Last edited by EmilyM1105; Feb 21st, 2018 at 08:16 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|