The code in this module also addresses rounding errors that exist in VBA/VB6 functions. VBA/VB6 has built-in functions for various mathematical operations. Search online help for "Math Functions" and "Derived Math Functions" for more information.

Procedure Name | Type | Description |

(Declarations) | Declarations | Declarations and private variables for the modMathGeneral module. |

GetGCF | Procedure | Get the greatest common factor (largest number that evenly divides into two numbers). |

GetRandomInt | Procedure | Get a random integer value between the range specified in the arguments, inclusive. The built-in Rnd function generates a value between 0 and 1. This function scales the value to return an integer between the range of numbers specified in the arguments. The range is inclusive, so the low-range and high-range values are as likely to be chosen as any of the other values between them. |

IsNumberPrime | Procedure | Determine if a number is a prime number. |

MaxOfThree | Procedure | Get the greater of three values. Null values are ignored; if all three values are Null, Null is returned. |

MaxOfTwo | Procedure | Get the greater of two values. Null values are ignored; if both values are Null, Null is returned. |

MinOfThree | Procedure | Get the smallest of three values. Null values are ignored; if all three values are Null, Null is returned. |

MinOfTwo | Procedure | Get the lesser of two values. Null values are ignored; if both values are Null, Null is returned. |

PrimeFactors | Procedure | Calculate the prime factors of a number. |

RoundDown | Procedure | Round a number to the specified number of decimal places with 0.5 rounded down. Numbers can be rounded to units on either side of the decimal point. Borderline numbers (0.5) are rounded down. Use RoundUp() to round borderline numbers up. |

RoundUp | Procedure | Round a number to the specified number of decimal places (0.5 is rounded up). The VBA/VB6 Round function performs Bankers Rounding which rounds 0.5 up or down depending on whether the previous digit is even or odd. This RoundUp function always rounds 0.5 up to the next highest value. RoundUp also allows you to round to hundreds, thousands, or decimals. |

ScalePercent | Procedure | Scale a value to a range between 0 and 100. This procedure compares one value to another, and returns the percentage that the first number is of the second number, scaled to a value between 0 and 100. This procedure is useful when you want to use a Progress Meter, ScrollBar, or another control with Min and Max properties. Instead of changing the properties of the control to match your input values, leave the Min and Max properties at 0 and 100, then scale the value to a number between the Min and Max value of the control. The number could be less than 0 or greater than 100 if the 'dblCurrent' argument is less than 0 or greater than the 'dblMax' value. |

Subtract | Procedure | Subtract two numbers with decimals correctly. In certain situations, VBA/VB6 does not subtract numbers with decimal places correctly (e.g. 100.8 - 100.7 = 0.099999999999943). This procedure corrects the problem by rounding the numbers correctly since a subtraction result cannot have more decimal places than the maximum of the inputs. |

The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

is Shipping!

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP