클래스에 추가하는 경우 느려집니다 : 100
번 100 000
Clients
와 배열을 생성하고 배열을 통해 루프마다 설정 서로 다른 난수를 각 Client
에 입력하십시오.엑셀 VBA : 같은 코드를 얻을 속성이 나는 <code>Client</code> 클래스를 사용합니다 메인 서브를
Sub start()
Application.ScreenUpdating = False
Dim i As Long
Dim j As Long
Dim clientsColl() As Client
ReDim clientsColl(1 To 100000) As Client
For j = 1 To 100000
Set clientsColl(j) = New Client
clientsColl(j).setClientName = "Client_" & j
Application.StatusBar = "Getting client " & j
DoEvents
Next
Dim clientCopy As Variant
For i = 1 To 100
For Each clientCopy In clientsColl
clientCopy.generateRandom
Next
Application.StatusBar = "Calculating " & i
DoEvents
Next
MsgBox ("done")
Application.StatusBar = False
Application.ScreenUpdating = True
End Sub
클라이언트 클래스 :
Option Explicit
Private clientname As String
Private identityNumber As String
Private creditRating As String
Private contractTenor As Long
Private contractNumber As String
Private contractRate As Double
Private totalReserves As Double
Private totalReservesRate As Double
Private debtType As String
Private totalDebt As Double
Private lossRatio As Double
Private totalLoss As Variant
Private totalProfit As Double
Private totalPd As Double
Private totalLgd As Double
Private simulationCount As Long
Private randomNumber As Double
Private outcome As Integer
Private loss As Double
Private profit As Double
Private sumLosses() As Double
Private sumProfits() As Double
Private sumResults() As Double
Private averageDebtInfo As Double
Public Sub generateRandom()
randomNumber = Rnd()
End Sub
Public Property Get getClientName()
getClientName = clientName
End Property
Public Property Let setClientName(value As String)
clientName = value
End Property
그러나,이 코드는 Client
클래스는 Get
및 Let
특성을 가지고 여부에 따라 실행하는 다른 시간이 걸립니다. 위에 게시 된 클래스의 현재 버전은 약 25
초에 실행됩니다. identityNumber
또는 contractRate
과 같은 것을 얻으려면 몇 가지 Get
속성을 추가하면 약 1 minute 25 seconds
이 걸립니다.
왜 간단한 코드를 추가하면 코드에 많은 영향을 줍니까? 그것에 대해 아무 것도 할 수 있습니까? 이 코드는 30 초 이상 실행될 수 없습니다.
이 확실히 도움이되는 정보이지만 명시된 변경이 전체 실행 시간에 영향을 미치지 않는 이유의 질문에 대답 도움이되지 않습니다. –