I need to create a program like Hangman...

I did successfully the following:
Bring a file into VB which has a list of 100 words --> ok
Then, user enters a number --> ok
VB identifies the number to a word--> ok
Convert word into *****--> ok

appear input box--> OK

USer guesses a LETTER in the SELECTED WORD--> OK

PLACE LETTER in *****.....NOT HAPPENING

For example...word is "Office"..."******" so when user enters "C" then it should look like "****C*"

This is what im trying to use:

lblHiddenWord.Text = lblHiddenWord.Text.Substring(0, intPosition) & Entry & lblHiddenWord.Text.Substring(intPosition + 1)

HELP! Why is this substring not working?

How is it not working? What results are you getting?

Also, describing the code is not the same as submitting your code. Submit what code you have, and be specific about what exactly it is doing wrong.

No idea why isnt it replacing all the stars with the CORRECT LETTERS...
it was doing it a while ago but I made some changes and now I do not remember what I had before...so it would run properly (no replacement of starts with correct word, i.e. strSelectedWord)

ALSO...How can I make it identify the same letter multiple times? Suppose, the word is OFFICE...so I want it to recognise F more than once... how can I put strSelectedWord.IndexOf(....??) in a loop??

Private Sub Play_Click(sender As Object, e As EventArgs) Handles Play.Click

    Dim strSelectedword As String = Nothing
    Dim WordArray() As String = IO.File.ReadAllLines("HangmanWords.txt")

    Dim intSelectedNum As Integer = CInt(txtGameNum.Text)

    strSelectedword = WordArray(intSelectedNum)

    lblHiddenWord.Text = ""


    For intCount As Integer = 1 To strSelectedword.Length
        lblHiddenWord.Text = lblHiddenWord.Text() & "*"
    Next

    Dim intBad As Integer = 0

    Do Until lblHiddenWord.Text = strSelectedword Or intBad = 10
        Dim intPosition As Integer
        Dim Entry As String
        Entry = InputBox("Guess a letter")

        If intPosition > -1 Then

            lblHiddenWord.Text = lblHiddenWord.Text.Substring(0, intPosition) & Entry & lblHiddenWord.Text.Substring(intPosition + 1)


        Else
            MessageBox.Show("Try Again")
            intBad = intBad + 1
            'Used.Text = Used.Text & Entry.ToString()
        End If

    Loop

    If lblHiddenWord.Text = strSelectedword Then
        MessageBox.Show("Congratulations, you won!")
    Else
        MessageBox.Show("Sorry, you lost")

    End If


End Sub

The Problem is in your intPosition.

        Dim strSelectedword As String = "office"
        lblHiddenWord.Text = ""
        For intCount = 1 To strSelectedword.Length
            lblHiddenWord.Text &= "*"
        Next

        Dim intBad As Integer = 0
        Do Until intBad = 10 Or Not lblHiddenWord.Text.Contains("*")
            Dim Entry As String
            Entry = InputBox("Guess a letter")
            If Not Entry = "" Then
                If Not Entry = "!" Then
                    If strSelectedword.Contains(Entry.ToString) Then
                        Dim Index As String = strSelectedword.IndexOf(Entry)
                        strSelectedword = strSelectedword.Remove(Index, 1).Insert(Index, "!")
                        lblHiddenWord.Text = lblHiddenWord.Text.Remove(Index, 1).Insert(Index, Entry)
                    Else
                        MessageBox.Show("Try Again")
                    End If
                    intBad += 1
                End If
            End If
        Loop

        If lblHiddenWord.Text.Contains("*") Then
            MessageBox.Show("Sorry, you lost")
        Else
            MessageBox.Show("Congratulations, you won!")
        End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.