XLcalc

XLCalc 1.0.1

Class provides simple mathematical operations with integers of any size.Integers are processed as strings using old-style schoolbook math.

Download class and sample project
http://www.belle-nuit.com/download/xcalc.sit.hqx
http://www.belle-nuit.com/download/xcalculator.sit.hqx

Methods

The class provides the following functions:

Function Plus(a as string, b as string) As string

Function Minus(a as string, b as string) As string

Function Mult(a as string, b as string) As string

Function Div(a as string, b as string) As string

Returns integer division. If the result is negative, the smaller absolute value will be returned.

Function Modus(a as string, b as string) As string

Returns the remainder of integer division. If the result is negative, the remainder to the smaller absolute value will be returned. Is called Modus because Mod is a reserved word in REALbasic.

Function Greater(a as string, b as string) As boolean

Function Lower(a as string, b as string) As boolean

Function Equal(a as string, b as string) As boolean

Comment on the compare-functions. If any of the strings are not valid, false will be returned.

Function Abs(a as string) As string

Function IsValid(a as string) As boolean

If you try to process strings, which contain non-numeric values, an error-string will be returned. You can prevent this by testing your string against the IsValid function before calling any other function.
New 1.0.1: Checks also for leading zeros. A number with leading zeros is not valid. If you are not sure that the number does not have leading zeros, you may use the Strip0 function to clean up your number string.

Function Strip0(a as string) as string New 1.0.1

Cuts leading zeros in a number string.

Function GetValidNumber(a as string) as string New 1.0.1

Parses the string and returns a valid number string, eliminating all offending characters.

Function IsNotNull(a as string) As boolean

If you try to divide by zero (using the Div or the Modus function), an error-string will be returned. You can prevent this by testing your string against the IsNotNull function before calling Div or Modus. IsNotNull also tests for IsValid.

Function About() As string

Returns an about-string of the class

Function Version() As string

Returns the current version of the class

Properties

This class does not have any property. Providing it as a class however frees you of problems of namespace in your application. If you need to access to it from the whole program, make it a property of your app-subclass.

About Speed

This class uses old schoolbook methods, so don't ask for speed. For the moment, I just wanted to make it possible. The sample application shows the ticks used for a calculation in a static texfield.

You may experience the following durations

where c is a constant depending of your processor speed.Divide/Modus are the longest ones and their durations is the less predictable as it depends on the evolution of the reminders.

Terms of use / Disclaimer

© Belle Nuit Montage / Matthias Bürcher November 2000. All rights reserved. Written in Switzerland.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Comments please to matti@belle-nuit.com

The latest version is available at http//www.belle-nuit.com/

History

3.11.00 Released 1.0.1: Stronger checking of number (leading zeros not allowed) both in the XLcalc class as in the Integerfield class. Prevents error when calculating with numbers which have leading zeros.

8.6.00 Released as open source

23.3.00 Release Class XLcalc 1.0.0 and application XLcalculator 1.0.0