Home Image-Pro Automation (Macros, Apps, Reports)
Options

Passing variables between functions

Hello

I've written an automation for analysing FRAP data which requires array variables to be passed ByRef between functions. The automation works then the next time its run I get an Array Index out of range error. If I run it again it works fine and the next time the array error reappears. When I run in debug mode it seems to holding on to the values in the arrays after the automation has finished running. Is there a way of making VB or Premier forget the array variables after running.

Any help appreciated

Regards

David

Best Answer

  • Options
    Answer ✓
    David,

    I found a possible problem in your macro:
    You assign NumSlices after allocating of arrays :

            ReDim TheMaxValue(NumSlices) As Single
            ReDim TheMeanValue(NumSlices) As Single
    ...
            NumSlices = DuplicateImage.FrameCount

    It should be other way around.

    Yuri

Answers

  • Options

    Hello

    There might be a bit more to this than I thought as its now crashed a couple of times and when  Premier re-starts it reopens all the files that I used previously even though they were closed when it crashed. I think Premier might be hanging on to more than just the array variables. I'm using Premier 3D 64-bit Version 9.1.2 Build 5429

    Regards

    David

  • Options
    Hi David,

    VB.NET uses different mechanism passing arrays, so it may not work the same way as it was in IPP6.
    Can you give an example what you are trying to achieve?

    Yuri
  • Options

    Hello Yuri

    I've attached the ipx file for my project and an example image is on my usual server. Its called 140824NET23NE_1-FRAP.seq

    I can resend you the server location off list if you don't still have it.

    Regards

    David

  • Options
    Hi David,

    I checked your project and created a sample macro (I changed the way Redim is defined).

    My test macro works correctly:

    Public Module Module1
        Dim NumSlices As Long
    
        Public Sub Measure5
            NumSlices=5
            Measure
        End Sub
    
        Public Sub Measure10
            NumSlices=10
            Measure
        End Sub
    
        Public Sub Measure
            Dim TheMeanValue() As Single, TheMaxValue() As Single
            ReDim TheMaxValue(NumSlices)
            ReDim TheMeanValue(NumSlices)
            For x As Integer=0 To NumSlices
                GetMeasure(x,TheMeanValue,TheMaxValue)
            Next
            Debug.Print "NumSlices = " & NumSlices
            Debug.Print ThisApplication.GlobalTools.McToText(TheMeanValue).Value & " max = " & ThisApplication.GlobalTools.McToText(TheMaxValue).Value
        End Sub
    
        Public Function GetMeasure(ByVal x As Integer, ByRef TheMeanValue() As Single, ByRef TheMaxValue() As Single)
            TheMeanValue(x)=x
            TheMaxValue(x)=x^2
        End Function
    End Module
    

    It produces these outputs running Measure5 and Measure10

    NumSlices = 5
    0 1 2 3 4 5 max = 0 1 4 9 16 25
    NumSlices = 10
    0 1 2 3 4 5 6 7 8 9 10 max = 0 1 4 9 16 25 36 49 64 81 100
    NumSlices = 5
    0 1 2 3 4 5 max = 0 1 4 9 16 25
    NumSlices = 10
    0 1 2 3 4 5 6 7 8 9 10 max = 0 1 4 9 16 25 36 49 64 81 100


    Please test it.

    Yuri
  • Options

    Hello Yuri

    Yours works, mine doesn't. I changed the ReDim statement from

    ReDim TheMaxValue(NumSlices) As Single
    to ReDim TheMaxValue(NumSlices)
    and changed the function calss from
    GetMeasure(x,TheMeanValue(),TheMaxValue())
    to GetMeasure(x,TheMeanValue,TheMaxValue)
    which appear to be the only differences between your version, but its crashing at line 185 and
    the variables appear to already have a value as soon as the macro starts.
    Regards
    David
  • Options
    David,

    Line 185 is:
                TheMeanValue(x) = MaxMeanValue
    

    which means that x is larger than the array size. You can debug printing x and the array size:

            Debug.Print x & "  " & TheMeanValue.GetUpperBound(0)
    
    Other possibility is that the error somewhere else, in that case you can try disabling some parts of the macro until it starts working.

    Yuri
  • Options
    One more point. I noticed that you are finding max using a loop.
    Premier has easier ways of getting stats values using Statistics function, you can use this:

        Public Sub GetMeasStats
            Dim md As MediaCy.Addins.Measurements.McMMData=ThisApplication.ActiveImage.MeasurementsData
            Debug.Print "MaxMeanIntensity = " & md.Statistics(MediaCy.Addins.Measurements.eMeasures.RgnDensity).Maximum
            Debug.Print "MaxMaxIntensity = " & md.Statistics(MediaCy.Addins.Measurements.eMeasures.RgnMaxIntensity).Maximum
        End Sub
    

    Regards,

    Yuri
  • Options

    Hello Yuri,

    Allocating NumSlices first was the problem. No idea why it failed every other run rather than straight away but it works now.

    Thanks

    David

Sign In or Register to comment.