Unexpected Run-Time Error Type '13' mismatch Error-VBForums
Results 1 to 8 of 8

Thread: Unexpected Run-Time Error Type '13' mismatch Error

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    4

    Unexpected Run-Time Error Type '13' mismatch Error

    I've inherited an old Excel-VBA model at work. I'm running this program to calculate loss on a portfolio of loans. The program works fine for a loan portfolio up to 500 loan items, but starts throwing up "Run-Time Error Type '13' mismatch" when I load a larger portfolio with more than 500 items.

    Code:
        Public Sub generateLossDistribution()
    
        ....
    
            Dim i As Long, j As Long
            Dim p As portfolio
            ' Creates a new portfolio object and reads it
            **Set p = New portfolio**
    The error message crops up in the "**" code line. FYI, "portfolio" is a user defined object/class module. Since the code works for fewer loan items, could this error be due to increased array size (when bigger portfolio gets loaded)? The portfolio has about 30 fields for each loan items. Is there a limit on the array size, which I can expand?

    Apologies of being very vague since I'm just a beginner and the model code is too huge to be uploaded to make any sense.

    Thanks

  2. #2
    Fanatic Member
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    985

    Re: Unexpected Run-Time Error Type '13' mismatch Error

    If it were an array issue you would get an Error 9 - Out of bounds/Out of Range
    Error 13 is usually something like assigning a bike-object to a car-object, a string to a long a.s.o.
    For health reasons i try to avoid reading unformatted Code

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    4

    Re: Unexpected Run-Time Error Type '13' mismatch Error

    Quote Originally Posted by Zvoni View Post
    If it were an array issue you would get an Error 9 - Out of bounds/Out of Range
    Error 13 is usually something like assigning a bike-object to a car-object, a string to a long a.s.o.
    Which is what I don't understand. If the issue was merely type mismatch, why does the code work for fewer loan items in the portfolio (i.e. fewer rows of data) but fails for larger data set?

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    4

    Re: Unexpected Run-Time Error Type '13' mismatch Error

    If I (hypothetically speaking) declared all variables as Variant, would that solve the problem?

  5. #5
    Fanatic Member
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    985

    Re: Unexpected Run-Time Error Type '13' mismatch Error

    Maybe, but it wouldn't solve the initial problem. It would be a case that your code works in a certain situation, but you can't be sure that it's going to work always. So it's better to find the root of the error
    For health reasons i try to avoid reading unformatted Code

  6. #6
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    2,449

    Re: Unexpected Run-Time Error Type '13' mismatch Error

    Can you show us the "portfolio" module?

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    4

    Re: Unexpected Run-Time Error Type '13' mismatch Error

    Here is the VBA code for "portfolio" module (I have redacted lot of stuff for ease):

    Code:
    Option Explicit
    
    Private emflag As Boolean
    
    'Private numberOfCDOs As Integer
    Private numberOfAssets As Integer
    Private numberOfObligors As Integer
    Private numberOfIndustries As Integer
    Private numberOfPools As Integer
    Private numberOfRegions As Integer
    Private totalDealDays As Double
    Private deltaT As Double
    
    Private assetArray() As asset
    Private obligorArray() As obligor
    Private pools() As pool
    
    'Private assetsInObligor() As Integer
    
    ' Weighted average default probability
    Private wadp As Double
    Private totalNotional As Double
    
    Public reinvmultiplier As Double
    
    
    '_________________Generic Functions_______________________
    
    Private Sub Class_Initialize()
        Dim state As Integer
        state = Application.Calculation
        Application.Calculation = xlCalculationManual
        Mode = Range("mode").Value
        
        numberOfPeriods = Range("portfolio.num_periods").Value
        numberOfYears = Range("portfolio.num_years").Value
        paymentFrequency = Range("Frequency").Value
        numberOfAssets = Range("portfolio.num_assets").Value
        numberOfObligors = Range("portfolio.num_obligors").Value
        numberOfCurrencies = Range("portfolio.num_currencies")
        numberOfAssetClasses = Range("portfolio.number_asset_classes").Value
        totalDealDays = Range("portfolio.total_deal_days").Value
        If (Range("useDays360").Value = "y") Then
            deltaT = 1 / 360
        Else
            deltaT = 1 / 365.25
        End If
        recoveryLag = Range("portfolio.recovery_delay").Value * paymentFrequency
        emflag = Range("portfolio.emflag").Value
        totalNotional = Range("portfolio.total_collateral_balance").Value
        
        maturityAdjustment = Range("portfolio.maturityAdjustment").Value
        Call getPeriodSizes
        
        ' Read the pool information
        dealType = string2dealType(Range("portfolio.deal_type").Value)
        If (dealType = CDO_1) Then
            maxRevolvPd = Range("Revolv_PD").Value
            numberOfPools = numberOfCurrencies * numberOfAssetClasses
            Call readPoolInformation
            numberOfCDOs = 0
        Else
        ' In case of CDO^2 pool information is specific to CDOs
            numberOfCDOs = Range("cdo_2.number_cdos").Value
        End If
        
        ' Read default prob matrices
        Call updateDefProb(Mode)
        
        ' Read the asset information
        If (Mode = 2) Then
            Call readAssetInformationMoodys
        ElseIf (Mode = 3) Then
            Call readAssetInformationSP
        End If
        
        'Setup the FX and Interest Curves
        Call initalizeFXInterest
        
        Application.Calculation = state
    End Sub
    
    
    Public Sub readPoolInformation()
        Dim i As Integer, j As Integer
        
        
        ReDim pools(0 To numberOfPools - 1) As pool
        
        ' Read the pool information
        For i = 0 To numberOfCurrencies - 1
            For j = 0 To numberOfAssetClasses - 1
                Set pools(i * numberOfAssetClasses + j) = New pool
                Call pools(i * numberOfAssetClasses + j).readPool(i, j)
            Next j
        Next i
        
    End Sub

    If this doesn't help spot the obvious cause, I can post the full code.

  8. #8
    Fanatic Member
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    985

    Re: Unexpected Run-Time Error Type '13' mismatch Error

    After thinking about it, your issue could be some summary, which is saved inside an integer value, but with the "larger" portfolio the sum exceeds the range of an integer so you would need a long *shrugs*

    Btw: when posting your code it would be helpful in which line the error occurs
    For health reasons i try to avoid reading unformatted Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.