1 Pages (5 items)
SMath plugins - can they do an action on SMath workbook being closed? - Messages
#1 Posted: 11/20/2015 12:22:35 PM
Hi All,
Is it possible for a SMath plugin to perform a certain action when SMath workbook is closed? If yes, how can it be implemented? I would like my EXCEL plugin to close all the workbooks it opened automatically right before I quit SMath, rather than by hand.
Thank you
Is it possible for a SMath plugin to perform a certain action when SMath workbook is closed? If yes, how can it be implemented? I would like my EXCEL plugin to close all the workbooks it opened automatically right before I quit SMath, rather than by hand.
Thank you
#2 Posted: 11/20/2015 2:37:03 PM
If you want to perform an action when you exit the SMath Executable, add your code in the Dispose() member (in ExcelIO.vb, in your case)
AFAIK to perform an action when you close a worksheet you must have a RegionBase (I may be wrong here), then you can attach an event to OnBeforeWorksheetUnoad
#region IDisposable Members
void IDisposable.Dispose()
{
MessageBox.Show("Bye!"
;
}
#endregion
AFAIK to perform an action when you close a worksheet you must have a RegionBase (I may be wrong here), then you can attach an event to OnBeforeWorksheetUnoad
this.Parent.OnBeforeWorksheetUnoad += ...
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
Alexander O. Melnik 11/20/2015 2:40:00 PM
#3 Posted: 11/20/2015 6:31:35 PM
Thank you, Davide, I take I can use the first code example if I want to carry out an action on quitting SMath .exe
Also could you give me some guidance on how I can log an open workbook name every time a plugin call is made? I am not quite sure how to "save" a variable in memory that can be used in the Dispose() member.
My idea is to create a string(), where each member is a workbook name. To do that, every time a plugin call is made i need to store the wb.name to some string in memory, which will be used in the Dispose() member and further cleared on exit.
Any help is appreciated.
Thanks
Also could you give me some guidance on how I can log an open workbook name every time a plugin call is made? I am not quite sure how to "save" a variable in memory that can be used in the Dispose() member.
My idea is to create a string(), where each member is a workbook name. To do that, every time a plugin call is made i need to store the wb.name to some string in memory, which will be used in the Dispose() member and further cleared on exit.
Any help is appreciated.
Thanks
#4 Posted: 11/20/2015 9:21:57 PM
You can get the file name from the Store.FileName property in any function you have. A way to store this variable (as well as any other parameter you need) for further usage inside Dispose() is to use a static class.
When you process the FileName remember to check if it is null or empty (in this case the worksheet where the function is running is not yet saved anywhere)
The static class:
Inside your function:
Inside Dispose:
When you process the FileName remember to check if it is null or empty (in this case the worksheet where the function is running is not yet saved anywhere)
The static class:
Namespace ExcelIO
''' <summary>
''' Global Stuff.
''' </summary>
Public NotInheritable Class GlobalEnvironment
Private Sub New()
End Sub
Public Shared FileName As String
Public Shared AnInterestingNumber As Double
''' And so on...
End Class
End Namespace
Inside your function:
Public Function ExpressionEvaluation(ByVal root As SMath.Manager.Term, ByVal args()() As SMath.Manager.Term, ByRef store As SMath.Manager.Store, ByRef result() As SMath.Manager.Term) As Boolean Implements SMath.Manager.IPluginLowLevelEvaluation.ExpressionEvaluation
''' ...
GlobalEnvironment.FileName = store.FileName
''' ...
End Function
Inside Dispose:
Public Sub Dispose() Implements IDisposable.Dispose
''' ...
DoSomething(GlobalEnvironment.FileName)
''' ...
End Sub
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
Alexander O. Melnik 11/20/2015 10:39:00 PM
#5 Posted: 11/20/2015 10:38:57 PM
Davide, your code should be enough to achieve what I would like to do (if I don't run into too many errors). Just fyi you might have misunderstood my intentions - I would like to store the names of excel workbook (which I can get easily), so I believe I do not need the 2nd part of you code dealing with store.Filename.
If everything works I will get my EXCEL plugin to close all .xlsx workbooks opened during its work - which would be great!
Thanks again
If everything works I will get my EXCEL plugin to close all .xlsx workbooks opened during its work - which would be great!
Thanks again
1 users liked this post
Davide Carpi 11/21/2015 5:00:00 AM
1 Pages (5 items)
-
New Posts
-
No New Posts