Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-09-2009
Member
 
Join Date: Jun 2009
Posts: 56
Generate random number using VB

I want to a small help with VB coding. My task is to generate a random number and display it on label when a user hits a button. I know i have to code for this in Button1_Click() method but really confused about the coding part. How can I generate the random number using VB?
Reply With Quote
  #2  
Old 02-09-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Generate random number using VB

Code:
Private Sub Random(num As Integer, randlist() As Integer)

Randomize()

Dim i As Integer, j As Integer, k As Integer

For i = 1 To num 
  randlist(i) = i
Next i

For j = num To 2 Step -1
  i = Int(Rnd * j) + 1
  k = randlist(j)
  randlist(j) = randlist(i)
  randlist(i) = k
Next j
End Sub
Reply With Quote
  #3  
Old 02-09-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Generate random number using VB

Use the below random function to generate the random number:

Code:
Public Function rand(ByVal Low As Long, ByVal High As Long) As Long
  rand = Int((High - Low + 1) * Rnd) + Low
End Function
Now call this function every time you want to calculate the random number.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Generate random number using VB"
Thread Thread Starter Forum Replies Last Post
Generate some quality of random number via Random Number Generation function aMADeO! Windows Software 4 13-01-2012 05:07 PM
Generate Random Text In Ms Word Captain Carrot Windows Software 6 04-09-2010 05:58 AM
How to use "Math.random()" to generate a random number in JavaScript? Silent~Kid Software Development 5 03-02-2010 05:06 AM
Generate Random Password In PHP Aaquib Software Development 2 23-01-2009 10:33 PM
How to Generate Random Password in vb.net Aaprichit Software Development 1 24-12-2008 07:05 PM


All times are GMT +5.5. The time now is 10:41 PM.