Results 1 to 4 of 4

Thread: Why Won't This Tip Work!?!?!?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    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

  2. #2
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    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

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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
  •  



Click Here to Expand Forum to Full Width