aboutsummaryrefslogtreecommitdiff
path: root/challenge-146/eric-cheung/excel-vba/ch-2.bas
blob: aa7c7d16ca3f164de08f2a44b3c23497f61dd79f (plain)
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
Attribute VB_Name = "ModTask_02"
Option Explicit

Sub FindCuriousFractionTree(ByVal nNumerator As Integer, ByVal nDenominator As Integer, ByRef nParentNumerator As Integer, ByRef nParentDenominator As Integer)

    If nNumerator > nDenominator Then
        nParentNumerator = nNumerator - nDenominator
        nParentDenominator = nDenominator
    ElseIf nNumerator = nDenominator Then
        nParentNumerator = nNumerator
        nParentDenominator = nDenominator
    Else
        nParentNumerator = nNumerator
        nParentDenominator = nDenominator - nNumerator
    End If

End Sub

Sub Task_02()

    ''Credit: https://gdaymath.com/lessons/fractions/5-3-a-curious-fraction-tree/
    
    '' Example 1
    '' Const nNumeratorInput As Integer = 3
    '' Const nDenominatorInput As Integer = 5
    
    '' Example 2
    Const nNumeratorInput As Integer = 4
    Const nDenominatorInput As Integer = 3
    
    Dim strMsg As String
    Dim nNumeratorInputParent As Integer, nDenominatorInputParent As Integer
    Dim nNumeratorInputGrandParent As Integer, nDenominatorInputGrandParent As Integer
    
    FindCuriousFractionTree nNumeratorInput, nDenominatorInput, nNumeratorInputParent, nDenominatorInputParent
    FindCuriousFractionTree nNumeratorInputParent, nDenominatorInputParent, nNumeratorInputGrandParent, nDenominatorInputGrandParent
    
    strMsg = "Parent: " & nNumeratorInputParent & " / " & nDenominatorInputParent
    strMsg = strMsg & vbNewLine
    strMsg = strMsg & "GrandParent: " & nNumeratorInputGrandParent & " / " & nDenominatorInputGrandParent

    MsgBox strMsg, vbOKOnly, strMyTitle
    
End Sub