0

Whenever I enter a word into the textbox and press confirm, an error comes up on the line

correctlettersneeded = currentword.Length

but I don't know why. Please help

Private Sub confirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles confirm.Click

    twoplayertxt.Text = currentword
    correctlettersneeded = currentword.Length
    lblletters.Text = Val(correctlettersneeded)
    checkword()
    confirm.Visible = False
    twoplayertxt.Visible = False
    play.Visible = True
End Sub

here is the code for when I confirm the word.

Private Sub checkword()

    If currentword.Length < 1.1 Then
        line2.Visible = False
    End If
    If currentword.Length < 2.1 Then
        line3.Visible = False
    End If
    If currentword.Length < 3.1 Then
        line4.Visible = False
    End If
    If currentword.Length < 4.1 Then
        line5.Visible = False
    End If
    If currentword.Length < 5.1 Then
        line6.Visible = False
    End If
    If currentword.Length < 6.1 Then
        line7.Visible = False
    End If
    If currentword.Length < 7.1 Then
        line8.Visible = False
    End If
    If currentword.Length < 8.1 Then
        line9.Visible = False
    End If
    If currentword.Length < 9.1 Then
        line10.Visible = False
    End If
    If currentword.Length < 10.1 Then
        line11.Visible = False
    End If
    If currentword.Length < 11.1 Then
        line12.Visible = False
    End If
    If currentword.Length < 12.1 Then
        line13.Visible = False
    End If
    If currentword.Length < 13.1 Then
        line14.Visible = False
    End If
    If currentword.Length < 14.1 Then
        line15.Visible = False
    End If
    correctletters = correctlettersneeded
End Sub

code for checkword() This error comes: NullReferenceException was unhandled

and a sub heading of: object reference not set to an instance of an object

Mark
  • 8,140
  • 1
  • 14
  • 29
hasra
  • 1
  • 2
  • 1
    Welcome to Stack Overflow! Please take a moment to review this *carefully*: [Ask] We are not mind readers! – Ňɏssa Pøngjǣrdenlarp Jan 04 '15 at 21:51
  • NullReferenceException was unhandled and also "object reference not set to an instance of an object" – hasra Jan 04 '15 at 21:52
  • 2
    possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Ňɏssa Pøngjǣrdenlarp Jan 04 '15 at 22:06
  • 1
    Is the line 'twoplayertxt.Text = currentword' not supposed to be the other way around? – Rich Andrews Jan 04 '15 at 22:13
  • What is the value of currentword when the app crashes? It seems like it hasn't been set properly and the value of currentword is Nothing instead of a string value which would give you this error. – Joe Uhren Jan 05 '15 at 04:04
  • no the code for currentword is this dim currentword as string so currentword is a string. – hasra Jan 05 '15 at 15:25
  • OMG,RICH ANDREWS you are a genius. IT worked. thanks so much.and thanks for the support guys. You all helped me out with my hangman. – hasra Jan 05 '15 at 17:05

0 Answers0