|
-
Nov 19th, 1999, 10:13 PM
#1
Thread Starter
Frenzied Member
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
-
Nov 19th, 1999, 10:32 PM
#2
Hyperactive Member
Don't use the
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
that they have posted, use:
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
The people here don't use HTML right.
------------------
Tom Young, 14 Year Old
[email protected]
ICQ: 15743470 Add Me ICQ Me
AIM: TomY10
PERL, JavaScript and VB Programmer
-
Nov 19th, 1999, 10:39 PM
#3
Thread Starter
Frenzied Member
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
-
Nov 19th, 1999, 11:17 PM
#4
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..
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
Alternativel, you can do it without APIs, eg.
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]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|