ForceTextBoxCase – Set a textbox’s upper/lowercase style

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _    (ByVal hWnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long' Change the style of a textbox so that it automatically converts' typed characters to uppercase or lowercaseSub ForceTextBoxCase(TextBox As TextBox, Optional ConvertCase As Integer)    Dim style As Long    Const GWL_STYLE = (-16)    Const ES_UPPERCASE = &H8&    Const ES_LOWERCASE = &H10&        ' get current style    style = GetWindowLong(TextBox.hWnd, GWL_STYLE)        Select Case ConvertCase        Case 0            ' restore default style            style = style And Not (ES_UPPERCASE Or ES_LOWERCASE)        Case 1            ' convert to uppercase            style = style Or ES_UPPERCASE        Case 2            ' convert to lowecase            style = style Or ES_LOWERCASE    End Select    ' enforce new style    SetWindowLong TextBox.hWnd, GWL_STYLE, styleEnd Sub

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: