this is all of the code i have so far

Public Class Form1
    Dim SelectedWord As String
    Dim IntNoWords As Integer
    Dim stringarray(1000) As String
    Dim strword As String
    Dim Wordlength As Integer
    Dim UnderscoreWord As String


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EndButton.Click
        End 
    End Sub

    Private Sub ButtonA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonA.Click
        ButtonA.Enabled = False 
    End Sub

    Private Sub ButtonB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonB.Click
        ButtonB.Enabled = False
    End Sub

    Private Sub ButtonC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonC.Click
        ButtonC.Enabled = False
    End Sub

    Private Sub ButtonD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonD.Click
        ButtonD.Enabled = False
    End Sub

    Private Sub ButtonE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonE.Click
        ButtonE.Enabled = False
    End Sub

    Private Sub ButtonF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonF.Click
        ButtonF.Enabled = False
    End Sub

    Private Sub ButtonG_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonG.Click
        ButtonG.Enabled = False
    End Sub

    Private Sub ButtonH_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonH.Click
        ButtonH.Enabled = False
    End Sub

    Private Sub ButtonI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonI.Click
        ButtonI.Enabled = False
    End Sub

    Private Sub ButtonJ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonJ.Click
        ButtonJ.Enabled = False
    End Sub

    Private Sub ButtonK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonK.Click
        ButtonK.Enabled = False
    End Sub

    Private Sub ButtonL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonL.Click
        ButtonL.Enabled = False
    End Sub

    Private Sub ButtonM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonM.Click
        ButtonM.Enabled = False
    End Sub

    Private Sub ButtonN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonN.Click
        ButtonN.Enabled = False
    End Sub

    Private Sub ButtonO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonO.Click
        ButtonO.Enabled = False
    End Sub

    Private Sub ButtonP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonP.Click
        ButtonP.Enabled = False
    End Sub

    Private Sub ButtonQ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonQ.Click
        ButtonQ.Enabled = False
    End Sub

    Private Sub ButtonR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonR.Click
        ButtonR.Enabled = False
    End Sub

    Private Sub ButtonS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonS.Click
        ButtonS.Enabled = False
    End Sub

    Private Sub ButtonT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonT.Click
        ButtonT.Enabled = False
    End Sub

    Private Sub ButtonU_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonU.Click
        ButtonU.Enabled = False
    End Sub

    Private Sub ButtonV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonV.Click
        ButtonV.Enabled = False
    End Sub

    Private Sub ButtonW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonW.Click
        ButtonW.Enabled = False
    End Sub

    Private Sub ButtonX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX.Click
        ButtonX.Enabled = False
    End Sub

    Private Sub ButtonY_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonY.Click
        ButtonY.Enabled = False
    End Sub

    Private Sub ButtonZ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonZ.Click
        ButtonZ.Enabled = False
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim filenum As Integer = FreeFile()
        Dim filename As String = "../words.txt" 

        IntNoWords = 0

        FileOpen(filenum, filename, OpenMode.Input)
        Do Until EOF(filenum)
            stringarray(IntNoWords) = LineInput(filenum) '
            IntNoWords += 1
        Loop
        FileClose(filenum)
        'MsgBox("file Multi lines read " & IntNoWords)   (just was part of the testing)

        Randomize() ' chooses random word
        SelectedWord = stringarray(Int(Rnd() * IntNoWords) - 1) 
        'TextBox1.Text = SelectedWord     (part of the testing)
    End Sub

    Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
        TextBoxUnderScoreWord.Text = " "   ' this isnt working for some reason
        Wordlength = SelectedWord.Length   

        For J As Integer = 1 To Wordlength
            UnderscoreWord += "_ "
            TextBoxUnderScoreWord.Text = UnderscoreWord
        Next
    End Sub
End Class

Was wondering how to do these things

check if the letter clicked is in the word
display the letter if it is found
each miss should have a part of the man be built

The exact code would be helpful but even pointers would do

The easiest way to display the image would be to have a complete set of images that are each an increment of the previous one. e.g. head, then head and body, then head, body and one arm, etc. Then you just need to display one image or another to show the hangman.

On the button press for a letter check the char array (or string) that is the correct word and check for the letter's location (remember to code this so it finds ALL instances of the letter not just the first). Then on your result label (which probably starts off as a collection of underscores or similar) add the letter into the correct place.

try using 'if contains'

lets say VAR1 is the word and VAR2 is the character you are looking for.

IF VAR1.Contains(VAR2) = TRUE THEN
(your code if true)
ELSE
(your code if not true)
END IF

One simplification I could suggest would be to replace the 26 button handlers (for the letters) with one handler for all of them. Below is the code for doing it for three letters. Just add to the end of the function header for more letters.

Imports System.Windows.Forms

Public Class Form1
.
.
.
    Private Sub Button_Click(sender As System.Object, e As System.EventArgs) Handles ButtonA.Click, ButtonB.Click, ButtonC.Click
        Dim button As Button = sender
        button.Enabled = False
    End Sub
.
.
.
End Class

Edited 5 Years Ago by Reverend Jim: n/a

This article has been dead for over six months. Start a new discussion instead.