ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

How to Create a Simple Autonumber in the TextBox

Today, I’m going to teach you how to create an autonumber in the TextBox. It auto generates the number in the TextBox every time you click the Button. This is very important, why? Because this number serves as your primary key. For instance, when saving the data or record in the database you have to put a specific I’d number so that, the data or records will not be redundant when retrieving it from the database.

 

Let’s begin:
Open the visual basic. After that, add a button and a textbox in the form.
autonumform
After arranging the Button and TextBox, double click the button to fire the click event handler. Then, put the code into it.

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. 'DECLARE A VARIABLE FOR STORING NUMBER
  3. Dim inc As Integer
  4. 'STORE A NUMBER WHICH IS 1 TO A VARIABLE THAT YOU HAVE DECLARED
  5. inc = 1
  6. 'THIS FORMULA WORKS FOR INCREMENTING A VALUE THAT'S IN THE TEXTBOX.
  7. inc = inc + Val(TextBox1.Text)
  8. 'PUTING THE VALUE OF A VARIABLE IN THE TEXTBOX
  9. TextBox1.Text = inc
  10. End Sub

Every time you click the button, the number in the TextBox will be incremented by 1.

Press F5 on the keyboard to run your project.

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!