vb6parse 1.0.1

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="VB6Parse Library Reference - abs - Math">
    <title>abs - Math - VB6Parse Library Reference</title>
    <link rel="stylesheet" href="../../../assets/css/style.css">
    <link rel="stylesheet" href="../../../assets/css/docs-style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
    <script src="../../../assets/js/theme-switcher.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/vbnet.min.js"></script>
    <script>hljs.highlightAll();</script>
</head>
<body>
    <header class="docs-header">
        <div class="container">
            <h1><a href="../../../index.html">VB6Parse</a> / <a href="../../../library/index.html">Library</a> / <a href="../../../library/functions/math/index.html">Math</a> / abs</h1>
            <p class="tagline">VB6 Library Reference</p>
        </div>
    </header>

    <nav class="docs-nav">
        <div class="container">
            <a href="../../../index.html">Home</a>
            <a href="../../../library/index.html">Library Reference</a>
            <a href="../../../documentation.html">Documentation</a>
            <a href="https://docs.rs/vb6parse" target="_blank">API Docs</a>
            <a href="https://github.com/scriptandcompile/vb6parse" target="_blank">GitHub</a>
            <button id="theme-toggle" class="theme-toggle" aria-label="Toggle theme">
                <span class="theme-icon">🌙</span>
            </button>
        </div>
    </nav>

    <main class="container">
        
        <article class="library-item">
            <h1 id="abs-function">Abs Function</h1>
<p>Returns the absolute value of a number.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">Abs(number)</code></pre>
<h2 id="parts">Parts</h2>
<ul>
<li><strong>number</strong>: Required. Any valid numeric expression. If number contains Null, Null is returned;
  if it is an uninitialized variable, zero is returned.</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>The return type is the same as the input type, except:
- If number is a Variant containing Null, returns Null
- If number is an uninitialized Variant, returns 0
- The absolute value is always non-negative (&gt;= 0)</p>
<h2 id="remarks">Remarks</h2>
<ul>
<li><strong>Absolute Value</strong>: The absolute value of a number is its unsigned magnitude. For example,
  Abs(-1) and Abs(1) both return 1.</li>
<li><strong>Type Preservation</strong>: The return type matches the input type. If you pass an Integer, you
  get an Integer back. If you pass a Double, you get a Double back.</li>
<li><strong>Null Handling</strong>: If the argument is Null, the function returns Null.</li>
<li><strong>Overflow</strong>: For the most negative value of Integer (-32768) or Long (-2147483648), Abs
  will cause an overflow error because the positive equivalent is outside the valid range.</li>
<li><strong>Performance</strong>: Abs is highly optimized and very fast for numeric operations.</li>
</ul>
<h2 id="examples">Examples</h2>
<h3 id="basic-usage">Basic Usage</h3>
<pre><code class="language-vbnet">Dim result As Integer
result = Abs(-50)
&#x27; result = 50</code></pre>
<h3 id="with-positive-numbers">With Positive Numbers</h3>
<pre><code class="language-vbnet">Dim value As Integer
value = Abs(25)
&#x27; value = 25 (unchanged)</code></pre>
<h3 id="with-floating-point">With Floating Point</h3>
<pre><code class="language-vbnet">Dim distance As Double
distance = Abs(-12.75)
&#x27; distance = 12.75</code></pre>
<h3 id="with-zero">With Zero</h3>
<pre><code class="language-vbnet">Dim zero As Integer
zero = Abs(0)
&#x27; zero = 0</code></pre>
<h3 id="with-expressions">With Expressions</h3>
<pre><code class="language-vbnet">Dim x As Integer, y As Integer
x = 10
y = 20
Dim difference As Integer
difference = Abs(x - y)
&#x27; difference = 10</code></pre>
<h3 id="calculating-distance">Calculating Distance</h3>
<pre><code class="language-vbnet">Function Distance(x1 As Double, y1 As Double, x2 As Double, y2 As Double) As Double
    Distance = Sqr((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
End Function
&#x27; Often used with Abs for 1D distance:
Dim dist As Double
dist = Abs(x2 - x1)</code></pre>
<h3 id="with-currency">With Currency</h3>
<pre><code class="language-vbnet">Dim amount As Currency
amount = Abs(-1234.56@)
&#x27; amount = 1234.56</code></pre>
<h3 id="with-variants">With Variants</h3>
<pre><code class="language-vbnet">Dim v As Variant
v = -42
Dim result As Variant
result = Abs(v)
&#x27; result = 42</code></pre>
<h2 id="common-patterns">Common Patterns</h2>
<h3 id="ensuring-positive-values">Ensuring Positive Values</h3>
<pre><code class="language-vbnet">Sub ProcessValue(ByVal input As Integer)
    Dim positiveInput As Integer
    positiveInput = Abs(input)
    &#x27; Always work with positive values
    DoSomething positiveInput
End Sub</code></pre>
<h3 id="calculating-difference">Calculating Difference</h3>
<pre><code class="language-vbnet">Function GetDifference(a As Long, b As Long) As Long
    GetDifference = Abs(a - b)
End Function</code></pre>
<h3 id="data-validation">Data Validation</h3>
<pre><code class="language-vbnet">Function IsWithinTolerance(actual As Double, expected As Double, tolerance As Double) As Boolean
    IsWithinTolerance = (Abs(actual - expected) &lt;= tolerance)
End Function</code></pre>
<h3 id="financial-calculations">Financial Calculations</h3>
<pre><code class="language-vbnet">Function CalculateVariance(actual As Currency, budget As Currency) As Currency
    CalculateVariance = Abs(actual - budget)
End Function</code></pre>
<h3 id="array-processing">Array Processing</h3>
<pre><code class="language-vbnet">Sub MakeArrayPositive(arr() As Integer)
    Dim i As Integer
    For i = LBound(arr) To UBound(arr)
        arr(i) = Abs(arr(i))
    Next i
End Sub</code></pre>
<h3 id="comparison-logic">Comparison Logic</h3>
<pre><code class="language-vbnet">Function MaxAbsValue(a As Double, b As Double) As Double
    If Abs(a) &gt; Abs(b) Then
        MaxAbsValue = Abs(a)
    Else
        MaxAbsValue = Abs(b)
    End If
End Function</code></pre>
<h3 id="coordinate-systems">Coordinate Systems</h3>
<pre><code class="language-vbnet">Function ManhattanDistance(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer) As Integer
    ManhattanDistance = Abs(x2 - x1) + Abs(y2 - y1)
End Function</code></pre>
<h2 id="related-functions">Related Functions</h2>
<ul>
<li><code>Sgn</code>: Returns the sign of a number (-1, 0, or 1)</li>
<li><code>Fix</code>: Returns the integer portion of a number (truncates toward zero)</li>
<li><code>Int</code>: Returns the integer portion of a number (rounds down)</li>
<li><code>Round</code>: Rounds a number to a specified number of decimal places</li>
</ul>
<h2 id="type-compatibility">Type Compatibility</h2>
<table>
<thead>
<tr>
<th>Input Type</th>
<th>Return Type</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>Byte</td>
<td>Byte</td>
<td>Always positive already</td>
</tr>
<tr>
<td>Integer</td>
<td>Integer</td>
<td>Can overflow at -32768</td>
</tr>
<tr>
<td>Long</td>
<td>Long</td>
<td>Can overflow at -2147483648</td>
</tr>
<tr>
<td>Single</td>
<td>Single</td>
<td>Preserves precision</td>
</tr>
<tr>
<td>Double</td>
<td>Double</td>
<td>Preserves precision</td>
</tr>
<tr>
<td>Currency</td>
<td>Currency</td>
<td>Preserves 4 decimal places</td>
</tr>
<tr>
<td>Variant (numeric)</td>
<td>Variant</td>
<td>Type preserved</td>
</tr>
<tr>
<td>Variant (Null)</td>
<td>Null</td>
<td>Returns Null</td>
</tr>
</tbody>
</table>
<h2 id="performance-notes">Performance Notes</h2>
<ul>
<li><code>Abs</code> is a very fast intrinsic function</li>
<li>No function call overhead in compiled code</li>
<li>Optimized to CPU instructions where possible</li>
<li>Prefer <code>Abs</code> over manual <code>If</code>/<code>Then</code> checks for performance
<code>Abs</code> is parsed as a regular function call (<code>CallExpression</code>)
This module serves as documentation and reference for the Abs function</li>
</ul>
        </article>
        
        <div style="margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border-color);">
            <p>
                <a href="index.html">← Back to Math</a> |
                <a href="../index.html">View all functions</a>
            </p>
        </div>

    </main>

    <footer>
        <div class="container">
            <p>&copy; 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
        </div>
    </footer>
</body>
</html>