Brothersoft.comWindows|Mac|Mobile|Games

|Message

Solve software problem quickly Share experience to help others Improve the ability of solving problem
How to Limit a Text Box to Numbers Only in Visual Basic 6.0?

10/31/2011 07:35 by ScottHamman

First answer posted by happymom at 10/31/2011 07:35
Add Your Answer
10~1000 characters in length CAPTCHA:
2 Answers
  • happymom
    1. Load the Visual Basic 6.0 environment by clicking the program's shortcut icon from the desktop, or selecting "Microsoft Visual Basic 6.0" from the "Start" menu in your computer.

    2. Select "Standard EXE" from the "New Project" dialog box, then click "Open" button.

    3. Add a text box into the form by clicking the "TextBox" control from the "Toolbox," then drawing the desired text box size. Make sure it's wide enough to hold input characters from the user.

    4. Clear the text caption by erasing the word "Text1" next to the "Text" property at the "Properties" window on the right side of the screen.

    5. Double-click the text box control to display the "Code" window. This is where you'll write the instructions or source codes that the program will execute at run-time. The source code you are going to write will validate user input and accepts only numeric characters, else it will display an error message.

    6. Insert the following code within the "Text1_Change" event:

      If Not IsNumeric(Text1.Text) Then

      MsgBox "Numeric input only!", vbCritical, "Invalid Input"

      Text1.Text = ""

      End If

    7. Press F5 or select "Run" then "Start" from the menu to switch to runtime-mode.

    8. Test the program to check that it's running as it should. Type alphanumeric characters or combination of letters and numbers into the text box. You should see an error message letting you know the input is invalid. Now, type only numbers into the text box. If no error message pops up, the program is running correctly.

    9. Save the program by selecting "Save Project" from the "File" menu. Provide a filename into the space provided, then click "Save."

  • Was this answer helpful? 00 · 10/31/2011 07:35
  • Anonymous user
  • In code textbox_key_press

    if keyascii <48 or keyascii >57 then

    keyascii=0

    end if

  • Was this answer helpful? 00 · 11/02/2011 00:09
Add Your Answer
10~1000 characters in length CAPTCHA:
Related Questions
Q:How to Convert Visual Basic Files to C#?

A:Developer Fusion Navigate to the Developer Fusion website. Click “VB.NET” under the “From” label. Click “C#”under th...(more)

Q:How to Read & Write Text Files With Visual Basic 6.0?

A: Open Visual Basic 6.0, click File and choose New Project. Select Standard EXE from the list of templates. Double-click the TextBox control i...(more)

Q:How to Read a Comma Delimited File in Visual Basic?

A: Create a new file using a text editor such as Notepad or Wordpad. Insert the following text in the file: 1,2,3,4,5 Save the file as ...(more)

Q:How to Find Out if a Folder Exists with Visual C 98?

A: Set up your "includes." C includes are pre-existing files that contain function libraries. Add the following code to the beginning of your C...(more)

Q:How to Write Contents of Dataset to Excel File in Visual Basic 2005?

A: Create a new class file in your project called "DataTableHelper.vb". Copy the following copy into the new file: Imports System Imp...(more)

0 people are following

Ask a question now
Write a title for your question

WampServer

WampServer is a Windows web development environment.
Latest version:2.1e
License:Freeware
OS:Windows Vista/XP/2000/98/Me/NT
Total downloads:119,868
Rank:5 in Databases
Download It

Share with friends

New features is coming

  • 1. Providing high-quality answers to be a verified Q&A expert
  • 2. Ask and answer questions to get Brothersoft credits

Added Successfully!

×

Are you sure to delete your answer?

NoYes

×

Are you sure to choose it as the best answer?

NoYes

×

Voted Successfully!

×

You can't vote for yourself

×

You can't choose your own answer

×