Okay, I'm writing a word processing program aimed at writers, with all the stuff that my writer-type friends want in it. Problem is, I can't get it to use multiple documents. I have it creating them, and I can make it save whatever document you're on and all that, but there is one thing I can't do.

Word count on the currently selected document every time you hit space.

I'm using KeyPreview = True to watch for any space press, and I have that working. The only thing is getting it to word count on whatever document is currently active. Here is my current code, please tell me if I'm at least on the right track or not:

VB Code:
  1. Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean
  2.         'If space key is pressed
  3.         If m.WParam.ToInt32 = 32 Then
  4.             'Dim Number as whatever tab number we're on.
  5.             Dim Number As Integer = TabControl1.SelectedIndex + 1
  6.             'Dim WhatOne as whatever RichTextBoxEx we want to count, if we're on the first tab then this will make WhatOne = RichTextBoxEx1
  7.             Dim WhatOne As String = "RichTextBoxEx" + Number.ToString
  8.             'Dim WhatToCount as a new control so that we can count its text.
  9.             Dim WhatToCount As New RichTextBoxEx
  10.             'Change WhatToCounts name to whatever RichTextBox we're on, so if we're on the first tab then its new name will be RichTextBoxEx1
  11.             WhatToCount.Name = WhatOne
  12.             'Count WhatToCounts text
  13.             Word_Counter(WhatToCount.Text)
  14.         End If
  15.     End Function

Word_Counter is a self-made function that will count the words in whatever string you specify. It doesn't work. Any idea as to how I can fix this?