P
Paul Johnson
I have written the following sub for a textbox control on a form, which
emulates the Shift-F3 key combination in MS Word, cycling through lower,
proper, and upper case for selected text. I may want to use this in several
textboxes, and I know I could put the code in a module and call it from the
textbox controls, but what I would like to do is to create a new textbox
class that inherits from the stock object and adds my method. Is there a
good article for me to learn how to code this?
TIA,
Paul Johnson
------------------------------------------------------
Private Sub Comments_KeyDown(KeyCode As Integer, Shift As Integer)
Dim intCase As Integer, intSelStart As Integer, intSelLength As Integer,
vbCase As VbStrConv
If KeyCode = 114 And Shift = 1 Then ' Shift - F3 pressed
With Comments
vbCase = IIf(Asc(Right(Trim(.SelText), 1)) =
Asc(UCase(Right(Trim(.SelText), 1))), vbLowerCase, _
IIf(Asc(Trim(.SelText)) = Asc(UCase(Trim(.SelText))),
vbUpperCase, vbProperCase))
' "...A" sets it to vbLowerCase, or
' "A..." sets it to vbUpperCase, or
' "a..." (assumed by not "A..") sets vbCase to
vbProperCase
intSelStart = .SelStart
intSelLength = .SelLength ' Need to save selection data
.SelText = StrConv(.SelText, vbCase) ' Convert selection
.SelStart = intSelStart
.SelLength = intSelLength ' Restore selection
End With
End If
End Sub
emulates the Shift-F3 key combination in MS Word, cycling through lower,
proper, and upper case for selected text. I may want to use this in several
textboxes, and I know I could put the code in a module and call it from the
textbox controls, but what I would like to do is to create a new textbox
class that inherits from the stock object and adds my method. Is there a
good article for me to learn how to code this?
TIA,
Paul Johnson
------------------------------------------------------
Private Sub Comments_KeyDown(KeyCode As Integer, Shift As Integer)
Dim intCase As Integer, intSelStart As Integer, intSelLength As Integer,
vbCase As VbStrConv
If KeyCode = 114 And Shift = 1 Then ' Shift - F3 pressed
With Comments
vbCase = IIf(Asc(Right(Trim(.SelText), 1)) =
Asc(UCase(Right(Trim(.SelText), 1))), vbLowerCase, _
IIf(Asc(Trim(.SelText)) = Asc(UCase(Trim(.SelText))),
vbUpperCase, vbProperCase))
' "...A" sets it to vbLowerCase, or
' "A..." sets it to vbUpperCase, or
' "a..." (assumed by not "A..") sets vbCase to
vbProperCase
intSelStart = .SelStart
intSelLength = .SelLength ' Need to save selection data
.SelText = StrConv(.SelText, vbCase) ' Convert selection
.SelStart = intSelStart
.SelLength = intSelLength ' Restore selection
End With
End If
End Sub