vb6parse 1.0.1

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
<!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 - log - Math">
    <title>log - 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> / log</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="log-function">Log Function</h1>
<p>Returns a Double specifying the natural logarithm of a number.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">Log(number)</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><code>number</code> (Required): Double or any valid numeric expression greater than zero</li>
<li>Must be positive (&gt; 0)</li>
<li>Cannot be zero or negative</li>
<li>Error 5 "Invalid procedure call or argument" if number &lt;= 0</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>Returns a Double:
- Natural logarithm (base e) of the number
- Also known as ln(x) in mathematics
- Result can be positive, negative, or zero
- Log(1) = 0
- Log(e) = 1 where e ≈ 2.71828182845905
- For values 0 &lt; x &lt; 1, result is negative
- For values x &gt; 1, result is positive</p>
<h2 id="remarks">Remarks</h2>
<p>The Log function returns the natural logarithm:
- Natural logarithm uses base e (Euler's number)
- e ≈ 2.71828182845905
- Also written as ln(x) in mathematical notation
- Inverse operation of Exp function
- Log(Exp(x)) = x
- Exp(Log(x)) = x (for x &gt; 0)
- To calculate logarithms with other bases, use change of base formula
- Log base 10: Log(x) / Log(10)
- Log base 2: Log(x) / Log(2)
- Log base n: Log(x) / Log(n)
- Error 5 if argument is zero or negative
- Used in scientific and engineering calculations
- Common in exponential growth/decay problems
- Essential for statistical calculations
- Used in information theory (entropy, information content)
- Financial calculations (continuous compounding)
- Physics (radioactive decay, sound levels)
- Can be used to solve exponential equations
- Part of VB6's math function library
- Available in all VB versions</p>
<h2 id="typical-uses">Typical Uses</h2>
<ol>
<li><strong>Natural Logarithm</strong></li>
</ol>
<pre><code class="language-vbnet">   result = Log(10)
   ```
2. **Base 10 Logarithm**
   ```vb
   log10 = Log(x) / Log(10)
   ```
3. **Base 2 Logarithm**
   ```vb
   log2 = Log(x) / Log(2)
   ```
4. **Exponential Decay**
   ```vb
   timeConstant = -1 / Log(decayRate)
   ```
5. **Solve for Exponent**
   ```vb
   exponent = Log(result / initial) / Log(base)
   ```
6. **Information Content**
   ```vb
   bits = -Log(probability) / Log(2)
   ```
7. **pH Calculation**
   ```vb
   pH = -Log(hydrogenIonConcentration) / Log(10)
   ```
8. **Continuous Compounding**
   ```vb
   rate = Log(finalValue / initialValue) / time
   ```
## Basic Examples
### Example 1: Natural Logarithm</code></pre>
<p>vb
Dim result As Double
result = Log(1)        ' Returns 0
result = Log(2.71828)  ' Returns ~1 (ln(e) = 1)
result = Log(10)       ' Returns ~2.302585
result = Log(100)      ' Returns ~4.605170</p>
<pre><code>### Example 2: Base 10 Logarithm</code></pre>
<p>vb
Function Log10(ByVal x As Double) As Double
    Log10 = Log(x) / Log(10)
End Function
' Usage
Dim result As Double
result = Log10(100)    ' Returns 2
result = Log10(1000)   ' Returns 3
result = Log10(10)     ' Returns 1</p>
<pre><code>### Example 3: Exponential Growth</code></pre>
<p>vb
' Calculate doubling time
Function DoublingTime(ByVal growthRate As Double) As Double
    ' growthRate is the rate per time period (e.g., 0.05 = 5%)
    DoublingTime = Log(2) / Log(1 + growthRate)
End Function
' Usage
Dim years As Double
years = DoublingTime(0.07)  ' 7% annual growth
MsgBox "Doubling time: " &amp; Format(years, "0.0") &amp; " years"</p>
<pre><code>### Example 4: Solve Exponential Equation</code></pre>
<p>vb
' Solve: base^exponent = result for exponent
Function SolveExponent(ByVal base As Double, _
                       ByVal result As Double) As Double
    If base &gt; 0 And base &lt;&gt; 1 And result &gt; 0 Then
        SolveExponent = Log(result) / Log(base)
    Else
        SolveExponent = 0
    End If
End Function
' Usage: Solve 2^x = 32
Dim x As Double
x = SolveExponent(2, 32)  ' Returns 5
MsgBox "2^" &amp; x &amp; " = 32"</p>
<pre><code>## Common Patterns
### Pattern 1: Log10 (Base 10 Logarithm)</code></pre>
<p>vb
Function Log10(ByVal x As Double) As Double
    If x &gt; 0 Then
        Log10 = Log(x) / Log(10)
    Else
        Err.Raise 5, , "Invalid argument"
    End If
End Function</p>
<pre><code>### Pattern 2: Log2 (Base 2 Logarithm)</code></pre>
<p>vb
Function Log2(ByVal x As Double) As Double
    If x &gt; 0 Then
        Log2 = Log(x) / Log(2)
    Else
        Err.Raise 5, , "Invalid argument"
    End If
End Function</p>
<pre><code>### Pattern 3: `LogN` (Logarithm with Any Base)</code></pre>
<p>vb
Function LogN(ByVal x As Double, ByVal base As Double) As Double
    If x &gt; 0 And base &gt; 0 And base &lt;&gt; 1 Then
        LogN = Log(x) / Log(base)
    Else
        Err.Raise 5, , "Invalid arguments"
    End If
End Function</p>
<pre><code>### Pattern 4: `SafeLog`</code></pre>
<p>vb
Function SafeLog(ByVal x As Double, _
                 Optional ByVal defaultValue As Double = 0) As Double
    On Error Resume Next
    SafeLog = Log(x)
    If Err.Number &lt;&gt; 0 Then
        SafeLog = defaultValue
        Err.Clear
    End If
End Function</p>
<pre><code>### Pattern 5: `CalculateEntropy`</code></pre>
<p>vb
Function CalculateEntropy(probabilities() As Double) As Double
    Dim i As Integer
    Dim entropy As Double
    Dim p As Double
    entropy = 0
    For i = LBound(probabilities) To UBound(probabilities)
        p = probabilities(i)
        If p &gt; 0 Then
            entropy = entropy - p * (Log(p) / Log(2))
        End If
    Next i
    CalculateEntropy = entropy
End Function</p>
<pre><code>### Pattern 6: `CalculateHalfLife`</code></pre>
<p>vb
Function CalculateHalfLife(ByVal decayConstant As Double) As Double
    If decayConstant &gt; 0 Then
        CalculateHalfLife = Log(2) / decayConstant
    Else
        CalculateHalfLife = 0
    End If
End Function</p>
<pre><code>### Pattern 7: `CalculateDoublingTime`</code></pre>
<p>vb
Function CalculateDoublingTime(ByVal growthRate As Double) As Double
    If growthRate &gt; 0 Then
        CalculateDoublingTime = Log(2) / Log(1 + growthRate)
    Else
        CalculateDoublingTime = 0
    End If
End Function</p>
<pre><code>### Pattern 8: `SolveForTime` (Exponential Growth)</code></pre>
<p>vb
Function SolveForTime(ByVal initialValue As Double, _
                      ByVal finalValue As Double, _
                      ByVal rate As Double) As Double
    If initialValue &gt; 0 And finalValue &gt; 0 And rate &lt;&gt; 0 Then
        SolveForTime = Log(finalValue / initialValue) / rate
    Else
        SolveForTime = 0
    End If
End Function</p>
<pre><code>### Pattern 9: `CalculateDecibels`</code></pre>
<p>vb
Function CalculateDecibels(ByVal power As Double, _
                           ByVal referencePower As Double) As Double
    If power &gt; 0 And referencePower &gt; 0 Then
        CalculateDecibels = 10 * (Log(power / referencePower) / Log(10))
    Else
        CalculateDecibels = 0
    End If
End Function</p>
<pre><code>### Pattern 10: `CalculatePH`</code></pre>
<p>vb
Function CalculatePH(ByVal hydrogenIonConcentration As Double) As Double
    If hydrogenIonConcentration &gt; 0 Then
        CalculatePH = -(Log(hydrogenIonConcentration) / Log(10))
    Else
        CalculatePH = 7  ' Neutral pH
    End If
End Function</p>
<pre><code>## Advanced Examples
### Example 1: Logarithm Calculator</code></pre>
<p>vb
' Module: LogarithmCalculator
Public Function NaturalLog(ByVal x As Double) As Double
    If x &lt;= 0 Then
        Err.Raise 5, "LogarithmCalculator", _
                  "Argument must be positive"
    End If
    NaturalLog = Log(x)
End Function
Public Function Log10(ByVal x As Double) As Double
    If x &lt;= 0 Then
        Err.Raise 5, "LogarithmCalculator", _
                  "Argument must be positive"
    End If
    Log10 = Log(x) / Log(10)
End Function
Public Function Log2(ByVal x As Double) As Double
    If x &lt;= 0 Then
        Err.Raise 5, "LogarithmCalculator", _
                  "Argument must be positive"
    End If
    Log2 = Log(x) / Log(2)
End Function
Public Function LogBase(ByVal x As Double, _
                        ByVal base As Double) As Double
    If x &lt;= 0 Or base &lt;= 0 Or base = 1 Then
        Err.Raise 5, "LogarithmCalculator", _
                  "Invalid arguments"
    End If
    LogBase = Log(x) / Log(base)
End Function
Public Function Antilog(ByVal x As Double) As Double
    ' Returns e^x (inverse of Log)
    Antilog = Exp(x)
End Function
Public Function Antilog10(ByVal x As Double) As Double
    ' Returns 10^x (inverse of Log10)
    Antilog10 = 10 ^ x
End Function</p>
<pre><code>### Example 2: Exponential Growth Analyzer</code></pre>
<p>vb
' Class: GrowthAnalyzer
Private m_initialValue As Double
Private m_currentValue As Double
Private m_timeElapsed As Double
Public Sub Initialize(ByVal initialValue As Double)
    m_initialValue = initialValue
    m_currentValue = initialValue
    m_timeElapsed = 0
End Sub
Public Property Let CurrentValue(ByVal value As Double)
    m_currentValue = value
End Property
Public Property Let TimeElapsed(ByVal time As Double)
    m_timeElapsed = time
End Property
Public Property Get GrowthRate() As Double
    If m_timeElapsed &gt; 0 And m_initialValue &gt; 0 And m_currentValue &gt; 0 Then
        GrowthRate = Log(m_currentValue / m_initialValue) / m_timeElapsed
    Else
        GrowthRate = 0
    End If
End Property
Public Property Get DoublingTime() As Double
    Dim rate As Double
    rate = GrowthRate
    If rate &gt; 0 Then
        DoublingTime = Log(2) / rate
    Else
        DoublingTime = 0
    End If
End Property
Public Function ProjectValue(ByVal futureTime As Double) As Double
    Dim rate As Double
    rate = GrowthRate
    If rate &lt;&gt; 0 Then
        ProjectValue = m_initialValue * Exp(rate * futureTime)
    Else
        ProjectValue = m_initialValue
    End If
End Function
Public Function TimeToReach(ByVal targetValue As Double) As Double
    Dim rate As Double
    rate = GrowthRate
    If rate &gt; 0 And m_initialValue &gt; 0 And targetValue &gt; 0 Then
        TimeToReach = Log(targetValue / m_initialValue) / rate
    Else
        TimeToReach = 0
    End If
End Function</p>
<pre><code>### Example 3: Sound Level Calculator</code></pre>
<p>vb
' Module: SoundLevelCalculator
Private Const REFERENCE_PRESSURE As Double = 0.00002  ' 20 micropascals
Public Function CalculateDecibels(ByVal pressure As Double) As Double
    If pressure &gt; 0 Then
        CalculateDecibels = 20 * (Log(pressure / REFERENCE_PRESSURE) / Log(10))
    Else
        CalculateDecibels = 0
    End If
End Function
Public Function CombineSoundLevels(levels() As Double) As Double
    Dim i As Integer
    Dim sumPressures As Double
    Dim pressure As Double
    sumPressures = 0
    For i = LBound(levels) To UBound(levels)
        ' Convert dB to pressure, sum, then convert back
        pressure = REFERENCE_PRESSURE * Exp(levels(i) * Log(10) / 20)
        sumPressures = sumPressures + pressure * pressure
    Next i
    If sumPressures &gt; 0 Then
        CombineSoundLevels = 10 * (Log(sumPressures) / Log(10)) + _
                            20 * (Log(REFERENCE_PRESSURE) / Log(10))
    Else
        CombineSoundLevels = 0
    End If
End Function
Public Function CalculateDistance(ByVal soundLevelAtSource As Double, _
                                  ByVal soundLevelAtDistance As Double, _
                                  ByVal knownDistance As Double) As Double
    Dim ratio As Double
    ' Sound decreases by 6 dB when distance doubles
    ratio = (soundLevelAtSource - soundLevelAtDistance) / 6
    CalculateDistance = knownDistance * (2 ^ ratio)
End Function</p>
<pre><code>### Example 4: Financial Calculator</code></pre>
<p>vb
' Module: FinancialCalculator
Public Function CalculateContinuousGrowthRate(ByVal initialValue As Double, _
                                               ByVal finalValue As Double, _
                                               ByVal years As Double) As Double
    If initialValue &gt; 0 And finalValue &gt; 0 And years &gt; 0 Then
        CalculateContinuousGrowthRate = Log(finalValue / initialValue) / years
    Else
        CalculateContinuousGrowthRate = 0
    End If
End Function
Public Function YearsToDouble(ByVal annualRate As Double) As Double
    If annualRate &gt; 0 Then
        YearsToDouble = Log(2) / Log(1 + annualRate)
    Else
        YearsToDouble = 0
    End If
End Function
Public Function EffectiveRate(ByVal nominalRate As Double, _
                              ByVal compoundingPeriods As Integer) As Double
    If compoundingPeriods &gt; 0 Then
        EffectiveRate = Exp(compoundingPeriods * _
                       Log(1 + nominalRate / compoundingPeriods)) - 1
    Else
        EffectiveRate = 0
    End If
End Function
Public Function CalculateAPY(ByVal principal As Double, _
                             ByVal finalAmount As Double, _
                             ByVal years As Double) As Double
    If principal &gt; 0 And finalAmount &gt; 0 And years &gt; 0 Then
        CalculateAPY = Exp(Log(finalAmount / principal) / years) - 1
    Else
        CalculateAPY = 0
    End If
End Function</p>
<pre><code>## Error Handling</code></pre>
<p>vb
' Error 5: Invalid procedure call or argument
On Error Resume Next
result = Log(0)
If Err.Number = 5 Then
    MsgBox "Cannot take log of zero!"
End If
result = Log(-10)
If Err.Number = 5 Then
    MsgBox "Cannot take log of negative number!"
End If
' Safe log function
Function SafeLog(ByVal x As Double) As Variant
    On Error Resume Next
    SafeLog = Log(x)
    If Err.Number &lt;&gt; 0 Then
        SafeLog = Null
        Err.Clear
    End If
End Function</p>
<pre><code>## Performance Considerations
- **Fast Operation**: Log is a built-in processor instruction
- **Cache Constants**: Store Log(10), Log(2) if used repeatedly
- **Avoid Division by Zero**: Always validate arguments
- **Use Exp for Inverse**: Exp(Log(x)) = x is optimized
## Best Practices
1. **Always validate** that argument is positive
2. **Use error handling** for user input
3. **Cache frequently used** logarithms (Log(10), Log(2))
4. **Document the base** when using change of base formula
5. **Use descriptive names** for logarithm wrapper functions
6. **Consider precision** for very large or small numbers
7. **Check for overflow** in calculations
8. **Use constants** for common values (e, pi, etc.)
9. **Validate results** for domain-specific constraints
10. **Comment formulas** explaining mathematical relationships
## Comparison with Related Functions
| Function | Purpose | Base | Domain |
|----------|---------|------|--------|
| **Log** | Natural logarithm | e (2.718...) | x &gt; 0 |
| **Exp** | Exponential (e^x) | e | All reals |
| **Log10** | Common logarithm | 10 | x &gt; 0 |
| **Log2** | Binary logarithm | 2 | x &gt; 0 |
| **^** (power) | Exponentiation | Variable | Depends |
## Common Logarithm Identities</code></pre>
<p>vb
' Log properties
Log(x * y) = Log(x) + Log(y)
Log(x / y) = Log(x) - Log(y)
Log(x ^ y) = y * Log(x)
Log(1) = 0
Log(e) = 1
' Change of base
Log_b(x) = Log(x) / Log(b)
' Inverse relationship
Exp(Log(x)) = x  (for x &gt; 0)
Log(Exp(x)) = x
```</p>
<h2 id="platform-notes">Platform Notes</h2>
<ul>
<li>Available in all VB6 versions</li>
<li>Part of VBA core library</li>
<li>Uses IEEE 754 double-precision floating point</li>
<li>Precision: approximately 15-16 significant digits</li>
<li>Range: 4.94065645841247E-324 to 1.79769313486232E+308</li>
<li>Behavior identical across Windows versions</li>
<li>CPU-level implementation (very fast)</li>
</ul>
<h2 id="limitations">Limitations</h2>
<ul>
<li><strong>Positive Arguments Only</strong>: Cannot compute log of zero or negative numbers</li>
<li><strong>Floating Point Precision</strong>: Subject to rounding errors</li>
<li><strong>Very Small Numbers</strong>: May lose precision near zero</li>
<li><strong>Very Large Numbers</strong>: May overflow in calculations</li>
<li><strong>No Base Parameter</strong>: Must use change of base formula for other bases</li>
<li><strong>Error for Invalid Input</strong>: Raises Error 5 instead of returning special value</li>
</ul>
<h2 id="related-functions">Related Functions</h2>
<ul>
<li><code>Exp</code>: Returns e raised to a power (inverse of Log)</li>
<li><code>Sqr</code>: Returns square root</li>
<li><code>^</code>: Exponentiation operator</li>
<li><code>Abs</code>: Returns absolute value</li>
<li><code>Sgn</code>: Returns sign of number</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>