CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 1999
    Location
    Germany
    Posts
    15

    Textbox only with Numbers

    i make a makro for Word 2000. I have an Dialog with TextBoxes. In these Textboxes i will only have an Integer value. How can i check that the value in the Textbox is a Number or a text ?

    ICQ : 41418974

  2. #2
    Guest

    Re: Textbox only with Numbers

    just check the contents' ASCII value(s)


  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Textbox only with Numbers

    In Visual Basic, you'd use the following code to set a textbox to be numeric input only (and only for integer values) :


    option Explicit

    '
    ' WinAPI Declarations
    '
    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 as Long = &H2000
    '
    '
    private Sub Form_Load()
    '
    Dim lStyle as Long
    Dim lRet as Long
    '
    lStyle = GetWindowLong(Text1.hwnd, GWL_STYLE)
    lStyle = lStyle Or ES_NUMBER
    lRet = SetWindowLong(Text1.hwnd, GWL_STYLE, lStyle)
    '
    End Sub




    Not too sure about from a macro though ...


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  4. #4
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Textbox only with Numbers

    here is the simplest code:

    If Not IsNumeric(Text1.Text) then
    MsgBox "Numbers Only!!!"
    End If






  5. #5
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Textbox only with Numbers

    Forgot to add something....code goes into textbox_change and change Text1.text in the code to whatever your textboxes name is.


  6. #6
    Guest

    Re: Textbox only with Numbers

    There is a function ISNumeric in VB which returns to to true or flase. the syntax is

    Dim strtmp as String
    strtmp = 'ss3'
    strtmp = '123'

    IsNumeric(strtmp)

    The first string will return you false
    and the second one will return you true


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

Featured