Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
every time when I pick a letter, the label keeps getting shorter

What I have tried:

VB
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnStart.Click
        'Enable buttons when clicking start
        EnableButtons()
        btnStart.Enabled = False        'Start buttons turn false so that user can stay on the game
        btnReset.Enabled = True         'Reopen the reset button once the game starts
        'Load up the secret word
        Secret_Word = "CHRISTMAS"
        LoadLabelDisplay()

        If Secret_Word = lblChar1.Text Then
            MessageBox.Show("Congratulations!!You won!!")

        End If
    End Sub
   'Base on the secret word, display how many dashed lines
    Sub LoadLabelDisplay()
        lblChar1.Text = ""
        Dim LengthOfSecretWord As Integer
        LengthOfSecretWord = Secret_Word.Length - 1
        Dim LetterPosition As Integer
        For LetterPosition = 0 To LengthOfSecretWord
            lblChar1.Text = lblChar1.Text & "-"
        Next
    End Sub
    Sub GuessLetter(LetterGuess As String)
        'dashes filled with dashes
        Dim LengthOfSecretWord As Integer
        LengthOfSecretWord = Secret_Word.Length - 1
        tempWord = ""
        Dim letterPosition As Integer
        For letterPosition = 0 To LengthOfSecretWord
            If Secret_Word.Substring(letterPosition, 1) = LetterGuess Then
                tempWord = tempWord & LetterGuess
            Else
                tempWord = tempWord & lblChar1.Text.Substring(letterPosition, 1)

            End If
        Next
        lblChar1.Text = tempWord
    End Sub
Posted
Updated 24-Nov-16 11:44am
v2
Comments
[no name] 24-Nov-16 16:15pm    
Okay.... learn how to use the debugger to debug your code. Then you might be able to give a better description of a problem than "the label keeps getting shorter".

1 solution

Quote:
the label keeps getting shorter
On first look, there is nothing obvious to explain why the label gets shorter.
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900