468,146 Members | 1,512 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,146 developers. It's quick & easy.

Auto generate numbers in vb.net form

I have created a vb.net form and wish to auto generate number within a textbox each time i click a button. Can you be of any to me?
Nov 23 '20 #1
1 1533
SioSio
238 128KB
Is the number a sequence or is it random?
If you want to set the sequence number in the text box, use the Button2Click code, and if you want to set the random number in the text box, use the Button1Click code.
Expand|Select|Wrap|Line Numbers
  1. Dim seq_num As Integer = 0
  2.     Sub Button1Click(sender As Object, e As EventArgs)
  3.         Dim rnd = New System.Random        ' Create an instance
  4.         Dim intResult = rnd.Next(1, 1000)  ' Get random numbers from 1 to 1000
  5.         textBox1.Text = intResult.ToString
  6.     End Sub
  7.  
  8.     Sub Button2Click(sender As Object, e As EventArgs)
  9.         seq_num = seq_num + 1
  10.         textBox1.Text = seq_num.ToString
  11.     End Sub
  12.  
Nov 24 '20 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Sebastien | last post: by
2 posts views Thread by SalimShahzad | last post: by
1 post views Thread by popsovy | last post: by
mmarif4u
reply views Thread by mmarif4u | last post: by
1 post views Thread by ganesh22 | last post: by
30 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.