For Anyone wondering how to Automatically Capitalize the first Letter of Each sentence as you type in a textbox.
Notes:
Chr(9) is the Tab Key
Cap is the Capital letter for the current key
SP is Starting Point or cursor Position (Textbox.SelStart)
TC is Temporary Character (The character currently being tested)
Basically what this does is:
When you press a key, before it processes the key into the textbox, the following checks are made...
1) Check to see if the cursor is at the front of the line. If so... Capitallize it.
2) Check to see if the Letter before the cursor is a space. If so... Scan backwards to the first of the string to see if a period occurs before any other letter with the ONLY exceptions being a TAB character and Space Character.
3) If a period is found, the current letter is capitalized and terminates the for loop.
4) If a character is found other than a period, space or tab, the loop is terminated, and the character remains at it's current Cap State.
5) If the begining of the string is reached before a period or other character, then the current character is the first non-space/tab character in the string, AKA the begining of a sentence. So... the current Letter is capitalized.
Sometimes... the BASIC things in life are the best...
or at least the most fun ;-)
-Josh Stribling
Notes:
Chr(9) is the Tab Key
Cap is the Capital letter for the current key
SP is Starting Point or cursor Position (Textbox.SelStart)
TC is Temporary Character (The character currently being tested)
Basically what this does is:
When you press a key, before it processes the key into the textbox, the following checks are made...
1) Check to see if the cursor is at the front of the line. If so... Capitallize it.
2) Check to see if the Letter before the cursor is a space. If so... Scan backwards to the first of the string to see if a period occurs before any other letter with the ONLY exceptions being a TAB character and Space Character.
3) If a period is found, the current letter is capitalized and terminates the for loop.
4) If a character is found other than a period, space or tab, the loop is terminated, and the character remains at it's current Cap State.
5) If the begining of the string is reached before a period or other character, then the current character is the first non-space/tab character in the string, AKA the begining of a sentence. So... the current Letter is capitalized.
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Cap = Asc(UCase(Chr(KeyAscii)))
SP = Text1.SelStart
If SP = 0 Then
KeyAscii = Cap
Else
If Mid(Text1, SP, 1) = " " Or Mid(Text1, SP, 1) = Chr(9) Then
For i = SP To 1 Step -1
TC = Mid(Text1, i, 1)
If TC = "." Then
KeyAscii = cap
Else
If TC <> " " And TC <> Chr(9) Then Exit For
End If
Next
If i < 2 Then KeyAscii = cap
End If
End If
End Sub

or at least the most fun ;-)
-Josh Stribling