Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

VB.NET Faces Off Against Classic VB : Page 3

VB.NET, the .NET Framework, and Visual Studio.NET together form a potent combination that can simplify your code and reduce errors; however, to truly supplant existing versions of VB as a RAD tool, Visual Studio needs Break-Edit-Continue.


advertisement

Retrieve a random number within a specified range
This is a common task, but the syntax always seemed awkward in classic VB. It's been cleaned up considerably in VB.NET. To get a random number, simply call the Next method of the System.Random object. The overloaded version shown below returns a random number between two specified Integer values. The Random object seeds itself automatically using a time-dependent value.




Classic VB:

   Private Function getRandomNumber _
      (low As Long, high As Long) As Long
      Randomize(Now())
      getRandomNumber = CInt((high - low + 1) * _
         Rnd + low)
   End Function



VB.NET

   Private Function getRandomNumber _
      (ByVal low, ByVal high) As Integer
      getRandomNumber = New System.Random(). _
         Next(low, high)
   End Function


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap