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
-
David,I found a possible problem in your macro:You assign NumSlices after allocating of arrays :ReDim TheMaxValue(NumSlices) As SingleReDim TheMeanValue(NumSlices) As Single...NumSlices = DuplicateImage.FrameCountIt should be other way around.Yuri0
Answers
-
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
0 -
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?Yuri0
-
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
0 -
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 Measure10NumSlices = 50 1 2 3 4 5 max = 0 1 4 9 16 25NumSlices = 100 1 2 3 4 5 6 7 8 9 10 max = 0 1 4 9 16 25 36 49 64 81 100NumSlices = 50 1 2 3 4 5 max = 0 1 4 9 16 25NumSlices = 100 1 2 3 4 5 6 7 8 9 10 max = 0 1 4 9 16 25 36 49 64 81 100Please test it.Yuri0 -
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
0 -
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.Yuri0 -
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,Yuri0 -
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
0
Categories
- All Categories
- 961 Image-Pro v9 and higher
- 9 Image-Pro FAQs
- 18 Image-Pro Download & Install
- 448 Image-Pro General Discussions
- 486 Image-Pro Automation (Macros, Apps, Reports)
- 20 AutoQuant Deconvolution
- 2 AutoQuant Download & Install
- 18 AutoQuant General Discussions
- 195 Image-Pro Plus v7 and lower
- 3 Image-Pro Plus Download & Install
- 106 Image-Pro Plus General Discussions
- 86 Image-Pro Plus Automation with Macros
- 19 Legacy Products
- 16 Image-Pro Premier 3D General Discussions
- 26 Image-Pro Insight General Discussions