title: Hangman Game: How To Make The Program Know I Wrote The Correct Word?
body: <p>I'm making a hangman game in VB.Net and everything's going smooth except one thing.
  I have a problem. Let me first explain.</p>
  
  <p>You start the game, you press the button so it can generate a random word in form of "?" Then you press the keys built in the program. When you press a correct key, the "?" turns into the key you pressed. Yeah you know how hangman works.
  Anyway, when i've guessed all the keys correct, i want it to tell me it was correct and randomly generate next word without pressing the "generate button"</p>
  
  <p>Here's the code i wrote:</p>
  
  <pre><code>If Korrekt_Gissat = antal Then
         MsgBox("Nice, " &amp; HemligaOrdet &amp; " is correct.")
         Reset()
     End If
  </code></pre>
  
  <p>Full code:</p>
  
  <p>Public Class Form1</p>
  
  <pre><code>Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      Dim i As Integer
      i = 0
  
      'Tangentbordet
      For Each ctrl In Controls
          If ctrl.tag = "Tangentbordet" Then
              ctrl.text() = Chr(90 - i)
              i = i + 1
          End If
      Next
  
  
  
  
      'Slumporden
      Ordlistan(0) = "Zed"
      Ordlistan(1) = "Ahri"
      Ordlistan(2) = "Udyr"
      Ordlistan(3) = "Ekko"
      Ordlistan(4) = "Shen"
      Ordlistan(5) = "Jinx"
      Ordlistan(6) = "Draven"
      Ordlistan(7) = "Thresh"
      Ordlistan(8) = "Yasuo"
      Ordlistan(9) = "Kassadin"
  End Sub
  
  Private Sub cmdSlumpa_Ord()
      Dim slumptal As Integer
  
      'Slumpa orden till textrutan
      slumptal = Int((10 * Rnd()) + 1)
      HemligaOrdet = Ordlistan(slumptal)
      '   TextBoxSlump.Text = HemligaOrdetu
  
      If HemligaOrdet = "Zed" Then
          PictureChampions.Image = My.Resources.Zed
      End If
  
      If HemligaOrdet = "Ahri" Then
          PictureChampions.Image = My.Resources.ahri
      End If
  
      If HemligaOrdet = "Udyr" Then
          PictureChampions.Image = My.Resources.Udyr
      End If
  
      If HemligaOrdet = "Ekko" Then
          PictureChampions.Image = My.Resources.ekko
      End If
  
      If HemligaOrdet = "Shen" Then
          PictureChampions.Image = My.Resources.shen
      End If
  
      If HemligaOrdet = "Jinx" Then
          PictureChampions.Image = My.Resources.Jinx
      End If
  
      If HemligaOrdet = "Draven" Then
          PictureChampions.Image = My.Resources.Draven
      End If
  
      If HemligaOrdet = "Thresh" Then
          PictureChampions.Image = My.Resources.Thresh
      End If
  
      If HemligaOrdet = "Yasuo" Then
          PictureChampions.Image = My.Resources.yasuo
      End If
  
      If HemligaOrdet = "Kassadin" Then
          PictureChampions.Image = My.Resources.Kassadin
      End If
  
  
      Skapamall()
  End Sub
  
  Private Sub btnSlumpa_Click(sender As Object, e As EventArgs) Handles btnSlumpa.Click
      cmdSlumpa_Ord()
  
  End Sub
  
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click, MyBase.Click, Button9.Click, Button8.Click, Button7.Click, Button6.Click, Button5.Click, Button4.Click, Button3.Click, Button29.Click, Button28.Click, Button27.Click, Button26.Click, Button25.Click, Button24.Click, Button23.Click, Button22.Click, Button21.Click, Button20.Click, Button2.Click, Button19.Click, Button18.Click, Button17.Click, Button16.Click, Button15.Click, Button14.Click, Button13.Click, Button12.Click, Button11.Click, Button10.Click
      Dim tecken As String
      Korrekt_Gissat = False
  
      For position = 1 To HemligaOrdet.Length
          tecken = Mid(HemligaOrdet, position, 1)
          If UCase(tecken) = sender.text Then
              Korrekt_Gissat = True
              Mid(Mallen, position, 1) = tecken
              TextBox2.Text = Mallen
          End If
      Next
  
  
      If Korrekt_Gissat = True Then
          Dim btn As Button = DirectCast(sender, Button)
          btn.Enabled = False
      End If
  
      If Korrekt_Gissat = False Then
          AntalFel = AntalFel + 1
          Bestraffa()
      End If
  
      If Korrekt_Gissat = antal Then
          MsgBox("Nice, " &amp; HemligaOrdet &amp; " is correct.")
          Reset()
      End If
  
  
      If AntalFel = 8 Then
          MsgBox("You lost!")
          End
      End If
  
  
  
  End Sub
  
  Private Sub Bestraffa()
  
      If AntalFel = 1 Then
          PicturePenality.Image = My.Resources._1
      End If
  
      If AntalFel = 2 Then
          PicturePenality.Image = My.Resources._2
      End If
  
      If AntalFel = 3 Then
          PicturePenality.Image = My.Resources._3
      End If
  
      If AntalFel = 4 Then
          PicturePenality.Image = My.Resources._4
      End If
  
      If AntalFel = 5 Then
          PicturePenality.Image = My.Resources._5
      End If
  
      If AntalFel = 6 Then
          PicturePenality.Image = My.Resources._6
      End If
  
      If AntalFel = 7 Then
          PicturePenality.Image = My.Resources._7
      End If
  
      If AntalFel = 8 Then
          PicturePenality.Image = My.Resources._8
      End If
  End Sub
  
  Private Sub Skapamall()
      Mallen = ""
      antal = HemligaOrdet.Length
      For i = 1 To antal
          Mallen = Mallen + "?"
      Next i
      TextBox2.Text = Mallen
  End Sub
  End Class
  </code></pre>
  
  <p>Module:</p>
  
  <p>Module Module1</p>
  
  <pre><code>Public Ordlistan(0 To 9) As String
  Public HemligaOrdet As String
  Public Mallen As String
  Public antal As Integer
  Public Korrekt_Gissat As Boolean
  Public AntalFel As Integer
  
  End Module
  </code></pre>