PDA

Click to See Complete Forum and Search --> : Why Won't This Tip Work!?!?!?


SteveCRM
Nov 19th, 1999, 09:13 PM
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

Compwiz
Nov 19th, 1999, 09:32 PM
Don't use the
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:

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
tyoung@stny.rr.com
ICQ: 15743470 (http://wwp.icq.com/15743470) Add Me (http://wwp.icq.com/scripts/search.dll?to=15743470) ICQ Me (http://wwp.icq.com/scripts/contact.dll?msgto=15743470)
AIM: TomY10 (http://www.aol.com/aim/aim30.html)
PERL, JavaScript and VB Programmer

SteveCRM
Nov 19th, 1999, 09:39 PM
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

Aaron Young
Nov 19th, 1999, 10:17 PM
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..

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.

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
aarony@redwingsoftware.com
adyoung@win.bright.net