AutoNumber in a TextBox

An AutoNumber is very useful in Programming Languages. Why? It’s because, their's no need for you to set the unique Id and the program will automatically set it for you. When you are saving records in the database, the records will be organized and it won’t be redundant because they have their own unique Id by using this AutoNumber. So , in this tutorial I will create an AutoNumber in a TextBox. I will show you how easy it is to use and you don't have to use complicated codes. It’s simple and it’s in the techniques. So let’s begin: 1. Open Visual Basic 2008. 2. Create a Project. 3. Create a Form and set it just like this. First Form 4. Double click the Form and set a value in the TextBox which is 0 for the first load.
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         TextBox1.Text = 0
  3.  End Sub
5. Go back to the Design Views, double click the Go Button and do the following codes for AutoNumber.
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim txt As Integer = 1 'declare a variable as integer
  3.                                'and store value which is 1.
  4.  
  5.         txt = txt + Val(TextBox1.Text) 'Set a Formula for adding the
  6.                                        'variable(txt)and a TextBox to
  7.                                        'store it in the variable(txt) again.
  8.  
  9.         '(Syntax of the Formula)
  10.         'The variable(txt) which is the value of 1,
  11.         'plus the value of a TextBox which is 0,
  12.         'is equal to the variable(txt).
  13.         'The value of variable(txt) now is 1.
  14.  
  15.        
  16.         TextBox1.Text = Val(txt)'place the value of a variable(txt)
  17.                                 'which is 1 to a textbox.
  18.     End Sub
Descriptions:Dim is a statement used to declare variables in Visual Basic. An Integer is a data type and it read numbers only. And the used of Val is to return the numbers contain in a string as a numeric value of the appropriate type. 6. Now, run your Project. If you click the Go Button continuously the TextBox will be incremented by 1. You can download the complete Source Code.

Add new comment