diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-02-22 09:24:54 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-02-22 09:24:54 +0000 |
| commit | 724312be84f5467b6107b7a3ec1c4588ac8b68e9 (patch) | |
| tree | 06b87c61124209cc380bda3232b21f90c624d20b /challenge-153/eric-cheung | |
| parent | 0c43bedd1756a6ca1052fb4ee172d5384441b0da (diff) | |
| download | perlweeklychallenge-club-724312be84f5467b6107b7a3ec1c4588ac8b68e9.tar.gz perlweeklychallenge-club-724312be84f5467b6107b7a3ec1c4588ac8b68e9.tar.bz2 perlweeklychallenge-club-724312be84f5467b6107b7a3ec1c4588ac8b68e9.zip | |
- Added guest contributions by Eric Cheung.
Diffstat (limited to 'challenge-153/eric-cheung')
| -rwxr-xr-x | challenge-153/eric-cheung/excel-vba/Challenge_153.xlsm | bin | 0 -> 26649 bytes | |||
| -rwxr-xr-x | challenge-153/eric-cheung/excel-vba/ch-1.bas | 37 | ||||
| -rwxr-xr-x | challenge-153/eric-cheung/excel-vba/ch-2.bas | 35 |
3 files changed, 72 insertions, 0 deletions
diff --git a/challenge-153/eric-cheung/excel-vba/Challenge_153.xlsm b/challenge-153/eric-cheung/excel-vba/Challenge_153.xlsm Binary files differnew file mode 100755 index 0000000000..f25c18566f --- /dev/null +++ b/challenge-153/eric-cheung/excel-vba/Challenge_153.xlsm diff --git a/challenge-153/eric-cheung/excel-vba/ch-1.bas b/challenge-153/eric-cheung/excel-vba/ch-1.bas new file mode 100755 index 0000000000..151e6437a7 --- /dev/null +++ b/challenge-153/eric-cheung/excel-vba/ch-1.bas @@ -0,0 +1,37 @@ +Attribute VB_Name = "ModTask_01"
+Option Explicit
+
+Public Const strMyTitle As String = "Eric Cheung"
+
+Function GetLeftFact(ByVal nNum As Integer) As Long
+
+ Dim nProd As Long, nSubLoop As Integer
+
+ If nNum <= 0 Then
+ GetLeftFact = 0
+ Exit Function
+ End If
+
+ nProd = 1
+ For nSubLoop = 1 To nNum
+ GetLeftFact = GetLeftFact + nProd
+ nProd = nProd * nSubLoop
+ Next nSubLoop
+
+End Function
+
+Sub Task_01()
+
+ Dim strMsg As String
+ Dim nLoop As Integer
+
+ For nLoop = 1 To 10
+ If strMsg <> "" Then
+ strMsg = strMsg & ", "
+ End If
+ strMsg = strMsg & GetLeftFact(nLoop)
+ Next nLoop
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
diff --git a/challenge-153/eric-cheung/excel-vba/ch-2.bas b/challenge-153/eric-cheung/excel-vba/ch-2.bas new file mode 100755 index 0000000000..eb48fdd949 --- /dev/null +++ b/challenge-153/eric-cheung/excel-vba/ch-2.bas @@ -0,0 +1,35 @@ +Attribute VB_Name = "ModTask_02"
+Option Explicit
+
+Function IsFactorion(ByVal nNum As Integer) As Boolean
+
+ Dim nSum As Integer, nLoop As Integer
+
+ For nLoop = 1 To Len(CStr(nNum))
+ nSum = nSum + Application.WorksheetFunction.Fact(Val(Mid(CStr(nNum), nLoop, 1)))
+ Next nLoop
+
+ If nSum = nNum Then
+ IsFactorion = True
+ Else
+ IsFactorion = False
+ End If
+
+End Function
+
+Sub Task_02()
+
+ '' Const nNumInput As Integer = 145 '' Example 1:
+ Const nNumInput As Integer = 123 '' Example 2:
+
+ Dim strMsg As String
+
+ If IsFactorion(nNumInput) Then
+ strMsg = "1"
+ Else
+ strMsg = "0"
+ End If
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
|
