aboutsummaryrefslogtreecommitdiff
path: root/challenge-131/eric-cheung
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-09-21 07:41:09 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-09-21 07:41:09 +0100
commit2576f41493de9d47a1c5bbc2acfe7e05a9efa2be (patch)
treedabadb8de272d88837f70f4d4956e9e8eb738f60 /challenge-131/eric-cheung
parent9c92a0acec4abdc9ac1fd36ba78de2df04521aad (diff)
downloadperlweeklychallenge-club-2576f41493de9d47a1c5bbc2acfe7e05a9efa2be.tar.gz
perlweeklychallenge-club-2576f41493de9d47a1c5bbc2acfe7e05a9efa2be.tar.bz2
perlweeklychallenge-club-2576f41493de9d47a1c5bbc2acfe7e05a9efa2be.zip
- Added guest contributions by Eric Cheung.
Diffstat (limited to 'challenge-131/eric-cheung')
-rwxr-xr-xchallenge-131/eric-cheung/excel-vba/Challenge_131.xlsmbin0 -> 33475 bytes
-rwxr-xr-xchallenge-131/eric-cheung/excel-vba/ch-1.bas56
-rwxr-xr-xchallenge-131/eric-cheung/excel-vba/ch-2.bas67
3 files changed, 123 insertions, 0 deletions
diff --git a/challenge-131/eric-cheung/excel-vba/Challenge_131.xlsm b/challenge-131/eric-cheung/excel-vba/Challenge_131.xlsm
new file mode 100755
index 0000000000..350aa51edf
--- /dev/null
+++ b/challenge-131/eric-cheung/excel-vba/Challenge_131.xlsm
Binary files differ
diff --git a/challenge-131/eric-cheung/excel-vba/ch-1.bas b/challenge-131/eric-cheung/excel-vba/ch-1.bas
new file mode 100755
index 0000000000..79c312b233
--- /dev/null
+++ b/challenge-131/eric-cheung/excel-vba/ch-1.bas
@@ -0,0 +1,56 @@
+Attribute VB_Name = "ModTask_01"
+Option Explicit
+Option Base 1
+Public Const strMyTitle As String = "Eric Cheung"
+
+Sub Task_01()
+
+ ''Const nMaxSize As Integer = 7 ''Example 1
+ ''Const nMaxSize As Integer = 6 ''Example 2
+ ''Const nMaxSize As Integer = 4 ''Example 3
+ Const nMaxSize As Integer = 5 ''Example 4
+
+ Dim strMsg As String
+ Dim nArr(1 To nMaxSize) As Integer
+ Dim nMatrix(1 To nMaxSize, 1 To nMaxSize) As Integer
+ Dim nRowLoop As Integer, nColLoop As Integer, nLoop As Integer
+
+ ''nArr(1) = 1: nArr(2) = 2: nArr(3) = 3: nArr(4) = 6: nArr(5) = 7: nArr(6) = 8: nArr(7) = 9 ''Example 1
+ ''nArr(1) = 11: nArr(2) = 12: nArr(3) = 14: nArr(4) = 17: nArr(5) = 18: nArr(6) = 19 ''Example 2
+ ''nArr(1) = 2: nArr(2) = 4: nArr(3) = 6: nArr(4) = 8 ''Example 3
+ nArr(1) = 1: nArr(2) = 2: nArr(3) = 3: nArr(4) = 4: nArr(5) = 5 ''Example 4
+
+ nRowLoop = 1
+ nColLoop = 1
+
+ For nLoop = 1 To nMaxSize
+ If nLoop > 1 Then
+ If nArr(nLoop) - nArr(nLoop - 1) = 1 Then
+ nColLoop = nColLoop + 1
+ Else
+ nRowLoop = nRowLoop + 1
+ nColLoop = 1
+ End If
+ End If
+ nMatrix(nRowLoop, nColLoop) = nArr(nLoop)
+ Next nLoop
+
+ For nRowLoop = 1 To nMaxSize
+ If nMatrix(nRowLoop, 1) > 0 Then
+ If strMsg <> "" Then
+ strMsg = strMsg & vbNewLine
+ End If
+ For nColLoop = 1 To nMaxSize
+ If nMatrix(nRowLoop, nColLoop) > 0 Then
+ If nColLoop > 1 Then
+ strMsg = strMsg & ", "
+ End If
+ strMsg = strMsg & nMatrix(nRowLoop, nColLoop)
+ End If
+ Next nColLoop
+ End If
+ Next nRowLoop
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
diff --git a/challenge-131/eric-cheung/excel-vba/ch-2.bas b/challenge-131/eric-cheung/excel-vba/ch-2.bas
new file mode 100755
index 0000000000..c5c09fa5cd
--- /dev/null
+++ b/challenge-131/eric-cheung/excel-vba/ch-2.bas
@@ -0,0 +1,67 @@
+Attribute VB_Name = "ModTask_02"
+Option Explicit
+Option Base 1
+
+Sub Task_02()
+
+ ''Credits
+ ''https://github.com/manwar/perlweeklychallenge-club/blob/master/challenge-131/ulrich-rieke/cpp/ch-2.cpp
+ ''https://github.com/manwar/perlweeklychallenge-club/blob/master/challenge-131/ulrich-rieke/perl/ch-2.pl
+ ''https://github.com/manwar/perlweeklychallenge-club/blob/master/challenge-131/ziameraj16/java/FindPairs.java
+
+ Dim strMsg As String
+ Dim strDelim As String, strToFind As String
+ Dim strOpenDelim As String, strCloseDelim As String
+ Dim strOpenSet As String, strCloseSet As String
+ Dim nLoop As Integer, nIndxFind As Integer
+ Dim wsFunc As Object
+
+ Set wsFunc = Application.WorksheetFunction
+
+ ''Example 1:
+ ''strDelim = """" & """" & "[]()"
+ ''strToFind = """" & "I like (parens) and the Apple ][+" & """" & " they said."
+
+ ''Example 2:
+ strDelim = "**//<>"
+ strToFind = "/* This is a comment (in some languages) */ <could be a tag>"
+
+ For nLoop = 1 To Len(strDelim)
+ If nLoop Mod 2 = 0 Then
+ strOpenDelim = strOpenDelim & Mid(strDelim, nLoop, 1)
+ Else
+ strCloseDelim = strCloseDelim & Mid(strDelim, nLoop, 1)
+ End If
+ Next nLoop
+
+ For nLoop = 1 To Len(strToFind)
+
+ ''Open Set
+ nIndxFind = 0
+ On Error Resume Next
+ nIndxFind = wsFunc.Find(Mid(strToFind, nLoop, 1), strOpenDelim)
+ On Error GoTo 0
+ If nIndxFind > 0 Then
+ strOpenSet = strOpenSet & Mid(strToFind, nLoop, 1)
+ End If
+ ''Open Set
+
+ ''Close Set
+ nIndxFind = 0
+ On Error Resume Next
+ nIndxFind = wsFunc.Find(Mid(strToFind, nLoop, 1), strCloseDelim)
+ On Error GoTo 0
+ If nIndxFind > 0 Then
+ strCloseSet = strCloseSet & Mid(strToFind, nLoop, 1)
+ End If
+ ''Close Set
+
+ Next nLoop
+
+ strMsg = strOpenSet & vbNewLine & strCloseSet
+ Set wsFunc = Nothing
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
+