Do you see anything concerning? Would you do something differently? Any comments?

public partial class mainForm : Form
    {
        public mainForm()
        {
            InitializeComponent();
        }

        // String array
        private string[] myWords = new string[4];
        private string currentWord;
        private int wordIndex;

        private void parseWords()
        {
            myWords[0] = "The ";
            myWords[1] = "fox ";
            myWords[2] = "jumps ";
            myWords[3] = "slowly.";

            currentWord = myWords[0];
            txtWordDisplay.Text = currentWord;
            wordIndex = 1;
        }

        private bool nextWord(int wordIndexSet)
        {
            // Make sure it's not the last element
            if (wordIndexSet != myWords.Length)
            {
                int arrayIndex;
                wordIndex++;
                arrayIndex = wordIndex - 1;

                currentWord = myWords[arrayIndex];
                txtWordDisplay.Text = currentWord;
                return true;
                
            }
            else
            {
                return false;
            }   
        }

        private void button1_Click(object sender, EventArgs e)
        {
            parseWords();
            txtWordDisplay.Enabled = true;
            lblToType.Enabled = true;
            txtInput.Enabled = true;
            
        }

        private void txtInput_TextChanged(object sender, EventArgs e)
        {
            if (txtInput.Text == currentWord)
            {
                txtInput.Text = "";

                if (nextWord(wordIndex))
                {
                    // Carry on typing...
                }
                else
                {
                    txtInput.Enabled = false;
                    MessageBox.Show("Finished!");
                    
                }
            }

        }
    }

Basically, the program loads, you click the start button, it enables the textbox for you to type in, it shows you a word to type and you type it, if it matches it empties the text box and you start with the next word until it reaches the last word.

I do have one question, how do I rename button1_Click, I've renamed it directly in visual studio (via the properties window) but it hasn't updated in the codeview?

Thank you :)

Hi,
it hard to tell what could be done better. There is to much to learn. This code looks ok, and it works, but I dont know exaclty what do you want to do with it.

Change private string[] myWords = new string[4]; on line 9 into private List<string> myWords = new List<string>();

commented: good suggestion :) +14

To rename the event, just rename it in the code.

You will probably get an error saying something like 'button1_click() not defined'
That is because there is another file that visual studio made for you that sets all the properties for all of your controls/components.

Just double click the error and make sure you change the name of the event += line to reflect the new name of the event.

Hi,
it hard to tell what could be done better. There is to much to learn. This code looks ok, and it works, but I dont know exaclty what do you want to do with it.

It's a really really basic 'typing tutor'. Well in the making anyway. :)

Thank you everyone really appreciated.

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.