Visual Basic Helper Routines
Pure VB: Handy Functions for Working with Numbers
     
Posted:   Sunday November 28, 1999
Updated:   Monday December 26, 2011
     
Applies to:   VB4-32, VB5, VB6
Developed with:   VB6, Windows XP
OS restrictions:   None
Author:   Newsgroups
     
 Prerequisites
32-bit VB.

 Code
Add the following functions to a form or BAS module, and declare as appropriate:

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function GetPI() As Double
  
  'returns the value of PI to 14 decimal places
   GetPI = (4 * Atn(1)) 
 
End Function


Public Function RoundDblToSng(ByVal nValue As Double, _
                              nDigits As Long) As Single

  'returns the passed value rounded to n decimal
  'places. From a msnews post by Steve Anderson.  
  'Useful for versions of VB without the Round 
  'function, or when customized return is required.
   RoundDblToSng = Int(nValue * (10 ^ nDigits) + 0.5) / (10 ^ nDigits)    

End Function


Public Function ShiftBitsLeft(ByVal dwValue As Long, _
                              ByVal dwBitsLeft As Long) As Long

  'bitwise left-shift equivalent to
  'C++ << operator
   ShiftBitsLeft = CLng(dwValue * (2 ^ dwBitsLeft))
   
End Function


Public Function ShiftBitsRight(ByVal dwValue As Long, _
                               ByVal dwBitsRight As Long) As Long

  'bitwise right-shift equivalent to
  'C++ >> operator
   ShiftBitsRight = CLng(dwValue / (2 ^ dwBitsRight))
   
End Function
 Comments

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter