-
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.
-
Feb 21st, 2018, 08:16 PM
#2
Re: Not Defined..? VS 2017
Did you generate a typed DataSet in your project or did you just copy and paste someone else's code? You can use the Data Sources window to generate a typed DataSet from an existing database. You would need a database named Question containing tables named Units and Words to get those types by default. It should work regardless of the type of database (Access, SQL Server, etc) but I'm guessing that this is part of an assignment and the instructor has either provided the database or told you how to create it.
-
Feb 21st, 2018, 08:22 PM
#3
Thread Starter
Addicted Member
Re: Not Defined..? VS 2017
Originally Posted by jmcilhinney
Did you generate a typed DataSet in your project or did you just copy and paste someone else's code? You can use the Data Sources window to generate a typed DataSet from an existing database. You would need a database named Question containing tables named Units and Words to get those types by default. It should work regardless of the type of database (Access, SQL Server, etc) but I'm guessing that this is part of an assignment and the instructor has either provided the database or told you how to create it.
The school did provide a database for me and no I did not copy and paste any of it. Alot of the code was given to me by the school also and they used a older version of Visual Studio so I had to download SQL server management also to upgrade it. I have found many mistakes in the instructions given to me so this must be one of them.
Thank you for pointing that out for me I fixed that part.. but this one is still showing for me..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 HangmanDBDataSet
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 HangmanDBDataSet
Dim taUnits As New HangmanDBDataSetTableAdapters.UnitsTableAdapter
Dim taWords As New HangmanDBDataSetTableAdapters.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:29 PM.
-
Feb 21st, 2018, 08:45 PM
#4
Re: Not Defined..? VS 2017
You can think through something like this yourself. Did you read the comment above that line?
Disable txtGuess textbox.
What do you think you need to assign to the Enabled property of txtGuess to disable it? If it's not clear to you then read the documentation for that Enabled property. You can open that documentation simply by clicking the property and pressing the F1 key, or you can use the Help menu to open the documentation and go from there. Don't put your brain in neutral. Some things are difficult. I wouldn't expect you to know how to create a typed DataSet if noone had ever explained it. Some things are not difficult. This is one of the latter.
-
Feb 22nd, 2018, 02:55 PM
#5
Thread Starter
Addicted Member
Re: Not Defined..? VS 2017
Originally Posted by jmcilhinney
You can think through something like this yourself. Did you read the comment above that line?
What do you think you need to assign to the Enabled property of txtGuess to disable it? If it's not clear to you then read the documentation for that Enabled property. You can open that documentation simply by clicking the property and pressing the F1 key, or you can use the Help menu to open the documentation and go from there. Don't put your brain in neutral. Some things are difficult. I wouldn't expect you to know how to create a typed DataSet if noone had ever explained it. Some things are not difficult. This is one of the latter.
Im getting a new message now on another part..it says
System.Data.SqlClient.SqlException
HResult=0x80131904
Message=An attempt to attach an auto-named database for file C:\Users\ENJ1105\source\repos\HangmanApp\HangmanApp\bin\Debug\HangmanDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
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 = False
' 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 HangmanDBDataSet
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 HangmanDBDataSet
Dim taUnits As New HangmanDBDataSetTableAdapters.UnitsTableAdapter
Dim taWords As New HangmanDBDataSetTableAdapters.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
These are the properties for the database file..
(Name) C:\USERS\ENJ1105\SOURCE\REPOS\HANGMANAPP\HANGMANAPP\HANGMANDB.MDF
The connection String for the database is showing
Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\ENJ1105\source\repos\HangmanApp\HangmanApp\H angmanDB.mdf;Integrated Security=True;Connect Timeout=30
(Primary Path) C:\Users\ENJ1105\source\repos\HangmanApp\HangmanApp\HangmanDB.mdf
The user interface is set to false but if I go to set it to be True it says...
The login Instance flag is not allowed when connecting to a user instance of SQL server. The connection will be closed.
Do I need to detach the database on sql server or take offline to make it work in Visual Studio? I have already upgraded it and put it in my project
Last edited by EmilyM1105; Feb 22nd, 2018 at 03:46 PM.
-
Feb 22nd, 2018, 03:52 PM
#6
Thread Starter
Addicted Member
Re: Not Defined..? VS 2017
ok taking it offline didnt help..and the file is not located in UNC share
-
Feb 22nd, 2018, 05:37 PM
#7
Re: Not Defined..? VS 2017
You've now asked three unrelated questions in this one thread. Please keep each thread to a single topic and each topic to a single thread. If the issue described by the title of this thread has been resolved then please use the Thread Tools menu to mark this thread Resolved. If you have a new question then please create a new thread with a title that describes that issue.
-
Feb 23rd, 2018, 02:08 PM
#8
Thread Starter
Addicted Member
Re: Not Defined..? VS 2017
Originally Posted by jmcilhinney
You've now asked three unrelated questions in this one thread. Please keep each thread to a single topic and each topic to a single thread. If the issue described by the title of this thread has been resolved then please use the Thread Tools menu to mark this thread Resolved. If you have a new question then please create a new thread with a title that describes that issue.
uhh ok I didnt know it was that serious
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
|