Private Declare Function GetWindowLong Lib \"user32\" Alias \"GetWindowLongA\" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib \"user32\" Alias \"SetWindowLongA\" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Const GWL_STYLE = (-16) Private Const ES_NUMBER = &H2000&
Public Function OnlyNum(tBox As TextBox) As Long Dim DefaultStyle As Long DefaultStyle = GetWindowLong(tBox.hwnd, GWL_STYLE): tBox.Text = \"\" OnlyNum = SetWindowLong(tBox.hwnd, GWL_STYLE, DefaultStyle Or ES_NUMBER) End Function
Private Sub Form_Load() OnlyNum Text1 End Sub \'-------------------------------- Form1 --------------------------------
sjh:> Må jeg spørge om noget i forbindelse med din kode ? Jeg fik lige gravet ES_UPPERCASE og ES_LOWERCASE frem og ville lave en lille funktion med dem .. kan man på nogen måde FJERNE en \"style\" igen ? Altså f.eks. med Or ES_NUMBER, kan man så fjerne ES_NUMBER fra DefaultStyle istedet ?
det kan man vel, men det ved jeg ikke lige hvordan man gør.
funktion med dem .. (UPPER... LOWER...)
Private Declare Function GetWindowLong Lib \"user32\" Alias \"GetWindowLongA\" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib \"user32\" Alias \"SetWindowLongA\" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Function OnlyNum(tBox As TextBox) Dim DefaultStyle As Long DefaultStyle = GetWindowLong(tBox.hwnd, GWL_STYLE) OnlyNum = SetWindowLong(tBox.hwnd, GWL_STYLE, DefaultStyle Or ES_NUMBER) End Function
Public Function OnlyUpperCase(tBox As TextBox) Dim DefaultStyle As Long DefaultStyle = GetWindowLong(tBox.hwnd, GWL_STYLE) OnlyUpperCase = SetWindowLong(tBox.hwnd, GWL_STYLE, DefaultStyle Or ES_UPPERCASE) End Function
Public Function OnlyLowerCase(tBox As TextBox) Dim DefaultStyle As Long DefaultStyle = GetWindowLong(tBox.hwnd, GWL_STYLE) OnlyLowerCase = SetWindowLong(tBox.hwnd, GWL_STYLE, DefaultStyle Or ES_LOWERCASE) End Function
sjh:> Jeg havde lavet en ModifyTextBox(.., Optional AllowNumbersOnly As Boolean = False, ..) men gad ik da jeg ikke anede hvordan jeg fjernede styles igen *G*
Private Declare Function GetWindowLong Lib \"user32\" Alias \"GetWindowLongA\" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib \"user32\" Alias \"SetWindowLongA\" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Function OnlyNum(tBox As TextBox, Flag As Boolean) Dim DefaultStyle As Long DefaultStyle = GetWindowLong(tBox.hwnd, GWL_STYLE) If Flag Then DefaultStyle = DefaultStyle Or ES_NUMBER Else DefaultStyle = DefaultStyle And (Not ES_NUMBER) End If OnlyNum = SetWindowLong(tBox.hwnd, GWL_STYLE, DefaultStyle) End Function
Public Function OnlyUpperCase(tBox As TextBox, Flag As Boolean) Dim DefaultStyle As Long DefaultStyle = GetWindowLong(tBox.hwnd, GWL_STYLE) If Flag Then DefaultStyle = DefaultStyle Or ES_UPPERCASE Else DefaultStyle = DefaultStyle And (Not ES_UPPERCASE) End If OnlyUpperCase = SetWindowLong(tBox.hwnd, GWL_STYLE, DefaultStyle) End Function
Public Function OnlyLowerCase(tBox As TextBox, Flag As Boolean) Dim DefaultStyle As Long
DefaultStyle = GetWindowLong(tBox.hwnd, GWL_STYLE) If Flag Then DefaultStyle = DefaultStyle Or ES_LOWERCASE Else DefaultStyle = DefaultStyle And (Not ES_LOWERCASE) End If OnlyLowerCase = SetWindowLong(tBox.hwnd, GWL_STYLE, DefaultStyle) End Function
Private Sub Check1_Click() \'OnlyNum Text1, Check1.Value \'OnlyUpperCase Text1, Check1.Value \'OnlyLowerCase Text1, Check1.Value End Sub
en lidt letere metode. :) if not isnumeric(text1.text) then text1.text = value(text1.text) end if
' så vil teksten altid kun være tal :)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.