Results 1 to 4 of 4

Thread: How to put numbers/float only on textboxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    Philippines
    Posts
    2

    Question How to put numbers/float only on textboxes

    Hello Im new to these forums. Im using VB for our thesis and Im just wondering how to be able to put numbers only on text boxes without causing an error.

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    We can only put text into textboxes.

    Where we need numbers the entry needs to be converted in some way. The easiest way is to get Excel to do the conversion by declaring a variable. eg.

    Code:
    Dim MyNumber As Double
    MyNumber = TextBox1.Value
    Regards
    BrianB
    -------------------------------

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    Philippines
    Posts
    2
    That's what I do:
    nSNR = CInt(txtNoise.Text)

    And as soon as I type a non-number character...

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Text1_KeyPress(KeyAscii As Integer)
    4.     If KeyAscii <> 46 And KeyAscii <> 48 And KeyAscii <> 49 And KeyAscii <> 50 Then 'Etc.
    5.         KeyAscii = vbNull
    6.     End If
    7. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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