Results 1 to 15 of 15

Thread: Null Reference Code in My School Project

Threaded View

  1. #14
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: Null Reference Code in My School Project

    Okay, let's go back to your original sub. I'll mark in Red the condition you're interested in (whether the words match), Blue the code that should be executed if the condition is true and Green the code that should execute if the condition is false:

    Code:
    Private Sub btnGuessW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuessW.Click
        Dim strWordGuessed = "BASSETT HOUND"
        Dim strWordtoGuess = "BASSETT HOUND"
        strWordGuessed = txtWord.Text()
        txtWord.Text = strWordGuessed.ToUpper()
        intNumTries += 1
        If strWordGuessed = strWordtoGuess Then
            MessageBox.Show("BASSETT HOUND")
            MessageBox.Show("You guessed the word in " & intNumTries & " tries.")
        End If
        intNumWrongTries = intNumWrongTries + 1
        If intNumWrongTries < 6 Then
            MessageBox.Show("That is not correct. You have guessed wrong " & intNumWrongTries & " times.")
        ElseIf intNumWrongTries = 6 Then
            MessageBox.Show("You lose")
            lblWord.Text = "Bassett Hound"
    
        End If
    End Sub
    And compare that to what an If/Else block should look like:

    Code:
    If conditionExpression Then
        ' This code executed if condition true
    Else
        ' This code executed if condition false
    End If
    Last edited by Evil_Giraffe; Jan 16th, 2011 at 11:13 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width