diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-24 00:25:02 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-24 00:25:02 +0000 |
| commit | 40638ae4192845aa5e1fc43e402f49aeb1e6074a (patch) | |
| tree | 6a121d550064b315b9caf1f8d13938af9050544b | |
| parent | e57e8ba97ca974deeadbd7137390e99a38d8304d (diff) | |
| download | perlweeklychallenge-club-40638ae4192845aa5e1fc43e402f49aeb1e6074a.tar.gz perlweeklychallenge-club-40638ae4192845aa5e1fc43e402f49aeb1e6074a.tar.bz2 perlweeklychallenge-club-40638ae4192845aa5e1fc43e402f49aeb1e6074a.zip | |
- Added guest contributions by Eric Cheung.
| -rwxr-xr-x | challenge-140/eric-cheung/excel-vba/Challenge_140.xlsm | bin | 0 -> 35022 bytes | |||
| -rwxr-xr-x | challenge-140/eric-cheung/excel-vba/ch-1.bas | 28 | ||||
| -rwxr-xr-x | challenge-140/eric-cheung/excel-vba/ch-2.bas | 57 |
3 files changed, 85 insertions, 0 deletions
diff --git a/challenge-140/eric-cheung/excel-vba/Challenge_140.xlsm b/challenge-140/eric-cheung/excel-vba/Challenge_140.xlsm Binary files differnew file mode 100755 index 0000000000..6d255dd99b --- /dev/null +++ b/challenge-140/eric-cheung/excel-vba/Challenge_140.xlsm diff --git a/challenge-140/eric-cheung/excel-vba/ch-1.bas b/challenge-140/eric-cheung/excel-vba/ch-1.bas new file mode 100755 index 0000000000..b73559dd3f --- /dev/null +++ b/challenge-140/eric-cheung/excel-vba/ch-1.bas @@ -0,0 +1,28 @@ +Attribute VB_Name = "ModTask_01"
+Option Explicit
+
+Public Const strMyTitle As String = "Eric Cheung"
+
+Function BinaryNumAdd(ByVal strBinNum_01 As String, ByVal strBinNum_02 As String) As String
+
+ Dim wsFunc As Object
+
+ Set wsFunc = Application.WorksheetFunction
+
+ BinaryNumAdd = wsFunc.Dec2Bin(wsFunc.Bin2Dec(strBinNum_01) + wsFunc.Bin2Dec(strBinNum_02))
+
+ Set wsFunc = Nothing
+
+End Function
+
+Sub Task_01()
+
+ Dim strMsg As String
+
+ '' strMsg = BinaryNumAdd("11", "1") '' Example 1
+ '' strMsg = BinaryNumAdd("101", "1") '' Example 2
+ strMsg = BinaryNumAdd("100", "11") '' Example 3
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
diff --git a/challenge-140/eric-cheung/excel-vba/ch-2.bas b/challenge-140/eric-cheung/excel-vba/ch-2.bas new file mode 100755 index 0000000000..4530e5ce1f --- /dev/null +++ b/challenge-140/eric-cheung/excel-vba/ch-2.bas @@ -0,0 +1,57 @@ +Attribute VB_Name = "ModTask_02"
+Option Explicit
+
+Sub Task_02()
+
+ '' Example 1
+'' Const nNumRow As Integer = 2
+'' Const nNumCol As Integer = 3
+'' Const nElemNum As Integer = 4
+
+ '' Example 2
+ Const nNumRow As Integer = 3
+ Const nNumCol As Integer = 3
+ Const nElemNum As Integer = 6
+
+ Dim strMsg As String
+ Dim nRowLoop As Integer, nColLoop As Integer, nLoop As Integer
+ Dim nArr(1 To nNumRow * nNumCol) As Integer
+
+ '' Initialize
+ nLoop = 1
+ For nRowLoop = 1 To nNumRow
+ For nColLoop = 1 To nNumCol
+ nArr(nLoop) = nRowLoop * nColLoop
+ nLoop = nLoop + 1
+ Next nColLoop
+ Next nRowLoop
+
+ '' Sort
+ For nRowLoop = 1 To nNumRow * nNumCol - 1
+ For nColLoop = nRowLoop + 1 To nNumRow * nNumCol
+ If nArr(nRowLoop) > nArr(nColLoop) Then
+ nLoop = nArr(nRowLoop)
+ nArr(nRowLoop) = nArr(nColLoop)
+ nArr(nColLoop) = nLoop
+ End If
+ Next nColLoop
+ Next nRowLoop
+
+ '' Display
+ strMsg = "Now the " & nElemNum
+
+ If nElemNum = 1 Then
+ strMsg = strMsg & "st"
+ ElseIf nElemNum = 2 Then
+ strMsg = strMsg & "nd"
+ ElseIf nElemNum = 3 Then
+ strMsg = strMsg & "rd"
+ Else
+ strMsg = strMsg & "th"
+ End If
+
+ strMsg = strMsg & " element in the table is " & nArr(nElemNum)
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
|
