I am finding it hard to do this the in OOP/event driven environment.

I am trying to make a typing tutor in Visual C#.

So I've already made an array where each elemnt is a single word.

Now my next steps are, parse the first word, seperating each letter.

Then have textbox, each time the textbox contentChange (or which ever it is called) event happens, I'll compare it to the first letter in the word, if it is the same, go ahead to the next letter, and the cycle continues.

But I'm stuck on how to implement this?

I've tried making a public array in my form class but it gives a bunch of errors:

public string[] wordArray;
wordArray = new string[50];

Errors include: 'Array size cannot be specified in variable declaration (try initializng with a 'new' expression), Invalid token ';', etc etc

Should I create a seperate 'word' class and initial a object within my form?
I'm just stuck on how I should go about doing this as.

Any suggestions/comments?

Thank you!

Sorry if I never made it clear enough, I'm having trouble on how the data should flow around this? Where should my wordArray be? In a method, public variable, seperate class?

I still dont get it what you want to do.
Please explain in some words what is your intention.
Why is an array there, what do you put into it? Is it filled in the runtime (in the code), or does it fill from textBox (or some other control)?
Why is textBox there?
And explain that it will make sence. Ok?
Mitja

I just added an array for now. Further on I would like to have a bunch of paragraphs/sentences that will be randomly selected and parsed into an arary. Why an array? As it seems the most sutible to store all the seperate words.

But in order to avoid all this hassle for now, I just created an array from scratch.

My aim is for the user to type out the whole sentence into the textbox, but in order to make it easier to catch a user's typo I will do it word by word.

So for example I will ask the user to type 'fox', as soon as one letter will be inputted, the textChanged event will fire right?

In this event I plan to check if the user input a 'f' which if he did will 'return/continue' so he can type the next letter. If he typed ' 'g' by mistake then I will notify the user in which ever way (a block changing to red or such).

So I my question is 'how am I meant to structure this', should I create a bunch of functions? Should I create a seperate class that will be called each time the textChanged event fires?

Do I create a public array?

Thank you, hope I made myself more clear :).
- I'm use to PHP so the whole event driven environment is doing my head in lol

Hi, I did an example code, which colors the textBox background, based on the correction of the letters inserted.
To test the code, you only put the textBox on the form, ther code takes care for the rese (even event creation).

PS: the word "tag" is the look which you are looking for!
Take a look:

public partial class Form1 : Form
    {
        bool bChecking;
        public Form1()
        {
            InitializeComponent();
            this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
        }

        private void textBox1_TextChanged(object obj, EventArgs e)
        {
            string tab = "fox";
            if (!bChecking)
            {
                bChecking = true;
                string written = textBox1.Text;
                if (written != String.Empty)
                {
                    if (written == tab)
                    {
                        textBox1.BackColor = Color.YellowGreen;
                        return;
                    }

                    int writtenLenght = written.Length;
                    try
                    {
                        string tabSelection = tab.Substring(0, writtenLenght);
                        if (written == tabSelection)
                            textBox1.BackColor = Color.Yellow;
                        else
                            textBox1.BackColor = Color.Red;
                    }
                    catch
                    {
                        textBox1.BackColor = Color.Red;
                    }
                }
                else
                    textBox1.BackColor = Color.White;
            }
            else
                bChecking = false;
        }
    }

Hope it helps a bit,
Mitja

It sounds like this really should be wriiten in JavaScript.

I would use .net to setup the page i.e. get your words or sentences from pre-defined dictionary. But the inline spell checking is definately a javascript thing. .Net does allow async-post back, but thats over kill for what you're trying to do. You don't want to post back the page everytime a user hits a character.

Client side script would work much faster and would be easier to write.

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