끝나지 않는 프로그래밍 일기


소스가 많이 더럽습니다.

POSTDCompare.zip

Option Explicit
Dim MinControl As Integer
Dim i As Integer

Private Sub BCompare_Click()
    Dim VCompareA() As String: VCompareA = Split(TCompareA, "&")
    Dim VCompareB() As String: VCompareB = Split(TCompareB, "&")
    Dim MaxControl As Integer
    
    TCompareA.BackColor = &HFFFFFF: TCompareB.BackColor = &HFFFFFF
    If TCompareA.Text = vbNullString Or TCompareB.Text = vbNullString Then MsgBox "CompareA 또는 CompareB가 비어 있습니다. 모두 입력해주세요.", vbCritical, "에러 발생": Exit Sub
    If TCompareA.Text <> TCompareB.Text Then
        TCompareA.BackColor = &H8080FF: TCompareB.BackColor = &H8080FF
    Else
        TCompareA.BackColor = &H80FF80: TCompareB.BackColor = &H80FF80
    End If
    
    CompareBoxClear
    CompareA(0) = VCompareA(0)
    For i = 1 To UBound(VCompareA)
        Load CompareA(i)
        CompareA(i).Visible = True
        CompareA(i).Top = CompareA(i - 1).Top + CompareA(i).Height + 50
        CompareA(i).Text = VCompareA(i)
    Next i
    
    CompareB(0) = VCompareB(0)
    For i = 1 To UBound(VCompareB)
        Load CompareB(i)
        CompareB(i).Visible = True
        CompareB(i).Top = CompareB(i - 1).Top + CompareB(i).Height + 50
        CompareB(i).Text = VCompareB(i)
    Next i
    
    MaxControl = IIf(CompareA.Count > CompareB.Count, CompareA.Count, CompareB.Count)
    MinControl = IIf(CompareA.Count > CompareB.Count, CompareB.Count, CompareA.Count)
    PCompareCurrent.Height = MaxControl * CompareA(0).Height + MaxControl * 50
    PScroll.Max = IIf(MaxControl <= 8, 0, MaxControl)
    
    If TCompareA.Text <> TCompareB.Text Then CompareSort
    CompareStart
End Sub

Private Sub CompareBoxClear()
    CompareA(0).Text = vbNullString: CompareB(0).Text = vbNullString
    CompareA(0).BackColor = &HFFFFFF: CompareB(0).BackColor = &HFFFFFF
    For i = 1 To CompareA.UBound
        Unload CompareA(i)
    Next i
    For i = 1 To CompareB.UBound
        Unload CompareB(i)
    Next i
End Sub

Private Sub CompareSort()
    Dim j As Integer
    Dim searchCount As Integer
    Dim temp As String
    Dim maxObject As Object, minObject As Object
    
    If CompareA.Count > CompareB.Count Then
        Set maxObject = CompareA
        Set minObject = CompareB
    Else
        Set maxObject = CompareB
        Set minObject = CompareA
    End If

    For i = 0 To minObject.UBound
        If minObject(i).Text <> maxObject(i).Text Then
            For j = 0 To maxObject.UBound
                If Split(maxObject(j).Text, "=")(0) = Split(minObject(i).Text, "=")(0) Then
                    temp = maxObject(j).Text
                    maxObject(j).Text = maxObject(searchCount).Text
                    maxObject(searchCount).Text = temp
                        
                    searchCount = searchCount + 1
                    GoTo Movable
                End If
            Next j
        End If
Movable:
    Next i
End Sub

Private Sub PScroll_Change()
    PCompareCurrent.Top = -(300 * PScroll.Value)
End Sub

Private Sub CompareStart()
    For i = 0 To MinControl - 1
        If CompareA(i).Text <> CompareB(i).Text Then
            CompareA(i).BackColor = &H8080FF: CompareB(i).BackColor = &H8080FF
        Else
            CompareA(i).BackColor = &H80FF80: CompareB(i).BackColor = &H80FF80
        End If
    Next i
End Sub