Why can't I get the tip that only allows numbers into a textbox to work? I keep getting "Expected End Of Statement" in the declarations section.
Steve
Printable View
Why can't I get the tip that only allows numbers into a textbox to work? I keep getting "Expected End Of Statement" in the declarations section.
Steve
Don't use the
that they have posted, use:Code:Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As LongDeclare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
The people here don't use HTML right.Code:Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
------------------
Tom Young, 14 Year Old
[email protected]
ICQ: 15743470 Add Me ICQ Me
AIM: TomY10
PERL, JavaScript and VB Programmer
Now I'm getting a syntax error on:
Public Const GWL_STYLE = (-16)Public Const ES_NUMBER = &H2000&
Public Sub SetNumber(NumberText As TextBox, Flag As Boolean)Dim curstyle As Long
Dim newstyle As Longcurstyle = GetWindowLong(NumberText.hwnd, GWL_STYLE)
If Flag Then curstyle = curstyle Or ES_NUMBERElse
curstyle = curstyle And (Not ES_NUMBER)End If
newstyle = SetWindowLong(NumberText.hwnd, GWL_STYLE, curstyle)NumberText.Refresh
Steve
If you look at what you've posted you'll see all the Code has been added together in one long line, you need to split it up.
Here's a better example of using the ES_NUMBER Message..
If you're using IE5, it makes all the lines in the Formatted block add together..
Alternativel, you can do it without APIs, eg.Code:Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const ES_NUMBER = &H2000
Private Sub Command1_Click()
'Toggle Numbers Only On/Off
Call SetWindowLong(Text1.hwnd, GWL_STYLE, GetWindowLong(Text1.hwnd, GWL_STYLE) Xor ES_NUMBER)
End Sub
Code:Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> vbKeyDelete And KeyAscii <> vbKeyBack Then KeyAscii = 0
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]