chart not launching under vba control, how to fix please?<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />VBA automation. I notice charts do not launch until the script has finished. I need to see them as the script is running, is there a way to fix this please?
Also, I assume related. The macro creates several charts. But seemingly at random some of them fail to launch. They appear in the Window list in the home window, but do not display until manually launched. I assume i am doing something wrong, but don't know what it is.
Thank you for any assistance.
Re: chart not launching under vba control, how to fix please?I think this is preferable. Any time you create the JMP instance in a subroutine and then null out the application pointer on exit there can be issues with automation. Creating the JMP instance and passing it in, making sure its lifetime persists for the length of your full operation, is usually the best approach.
In your case, the initialization of the underlying windows is probably the issue. It seems like your new approach gives them more time to be created, so when you make them visible the initialization is complete and a quick exit won’t hurt things.
Brian
Re: chart not launching under vba control, how to fix please?I may have found the problem, perhaps you could comment.
The code was generating an array of charts, then sending the array of charts to be launched and made visible
This proved to be unstable and be timing dependent. i.e. - it would fail more often with larger data tables
Loop
Generate Charts(Index)
Next
Loop
Charts(Index).Launch
Charts(Index).Visable = True
Next
I changed it to launching the chart at generation and sending the array of charts to be made visible.
So far, I have observed no abhorrent behavior
Loop
Generate Charts(Index)
Charts(Index).Launch
Next
Loop
Charts(Index).Visable = True
Next
Re: chart not launching under vba control, how to fix please?This may be hard for me to replicate. I would suggest trying a Sleep in the actual LaunchCharts subroutine after the visible call. Setting the variables to Nothing at the end, while good practice, does mean that they can be closed down.
Brian
Re: chart not launching under vba control, how to fix please?I can make it worse by adding more Sleep()'s. This configuration typically fails to launch the first chart, but all subsequent will launch.
Sub GenChartsReview(Filter As Variant, _
Group As Variant, _
Iter1 As Variant, _
Iter2 As Variant, _
Iter3 As Variant, _
Stats As Variant, _
Iterate As Boolean)
Dim APPjmp, TBLjmp, DOCjmp
GetJMP APPjmp, TBLjmp, DOCjmp
Dim Text As String
Dim Success As Boolean
Dim Stat, A, B, C, Index, PlotIndex, RowFilter()
Dim VChart() As JMP.Variability
If Iterate Then
If IsReal(Iter1) Then ReDim VChart((UBound(Iter1, 2) + 1))
If IsReal(Iter2) Then ReDim VChart(UBound(VChart) * (UBound(Iter2, 2) + 1))
Else
ReDim VChart(1)
End If
Index = 0
For A = 0 To UBound(Iter1, 2)
For B = 0 To UBound(Iter2, 2)
Success = True
Erase RowFilter()
AddFilters RowFilter, Filter
ClearRowStates TBLjmp
If IsValid(RowFilter) Then Success = ExcludeGroup(RowFilter, TBLjmp)
DoEvents
If Iterate Then
If IsReal(Iter1) Then IncludeItem Iter1(0, A), Iter1(1, A), TBLjmp
DoEvents
If IsReal(Iter2) Then IncludeItem Iter2(0,
, Iter2(1,
, TBLjmp
DoEvents
End If
Set VChart(Index) = DOCjmp.CreateVariabilityChart
If Success Then GenerateVarCharts VChart(Index), Stats, Group
DoEvents
Index = Index + 1
Sleep 200
Next
Next
Sleep 500
If Success Then
LaunchCharts VChart
Else
DialogAndLive "No Data To Plot, Are Filter Items Selected?"
End If
DoEvents
ClearRowStates TBLjmp
Set APPjmp = Nothing
Set TBLjmp = Nothing
Set DOCjmp = Nothing
End Sub
Sub LaunchCharts(VChart() As JMP.Variability)
Dim A
For A = 0 To UBound(VChart) - 1
VChart(A).Launch
VChart(A).Visible = True
Next
End Sub
Re: chart not launching under vba control, how to fix please?If you use the "Advanced Editor", in the bottom left you will find an Attach icon. Or, you can just pasteyour VB code to give me an idea what you are doing.
Brian
Re: chart not launching under vba control, how to fix please?Hi Brian,
I definitely appreciate your help. I do not find any provision to attach anything.
Re: chart not launching under vba control, how to fix please?Hi Matt,
I apologize for somehow missing this when you posted it. Can you provide the VBA source code that you are using? Generally, if you do a call sleep() in your code when there are timing issues, it can help with things like giving the analysis time to create a window. The Analysis automation sample program that ships with JMP (c:\program files\sas\jmp\13\Samples\Automation\Visual Basic Samples\Analysis.NET) provides an example of setting up the sleep call. You must declare that you are calling an operating system function. I'm using 13 as an example for the path, but this code shipped in the last 5 versions of JMP.
I hope that helps,
Brian Corcoran
JMP Development