aboutsummaryrefslogtreecommitdiff
path: root/challenge-139/eric-cheung/excel-vba/ch-1.bas
blob: 4b118d5d91170442fa8df1e4bd77e2b6f94598f6 (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
Attribute VB_Name = "ModTask_01"
Option Explicit

Public Const strMyTitle As String = "Eric Cheung"

Sub Task_01()

    Dim strMsg As String
    Dim nArr() As Variant
    Dim nLoop As Integer
    Dim bSortFlag As Boolean, bAscOrder As Boolean
    
    bSortFlag = True
    
    '' nArr = Array(1, 2, 3, 4, 5) '' Example 1
    nArr = Array(1, 3, 2, 4, 5) '' Example 2
    
    If nArr(LBound(nArr)) < nArr(LBound(nArr) + 1) Then
        bAscOrder = True
    Else
        bAscOrder = False
    End If
    
    For nLoop = LBound(nArr) + 1 To UBound(nArr)
        If _
            bAscOrder And nArr(nLoop) < nArr(nLoop - 1) _
            Or Not bAscOrder And nArr(nLoop) > nArr(nLoop - 1) _
        Then
            bSortFlag = False
            Exit For
        End If
    Next nLoop
    
    strMsg = "0"
    If bSortFlag Then
        strMsg = "1"
    End If
    
    MsgBox strMsg, vbOKOnly, strMyTitle
    
End Sub