SMath Studio Forum
»
SMath Studio
»
Questions
»
SMath plugins - can they do an action on SMath workbook being closed?
Rank: Advanced Member Groups: Registered
Joined: 03/03/2014(UTC) Posts: 418 Was thanked: 125 time(s) in 96 post(s)
|
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
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,654 Location: Italy Was thanked: 1340 time(s) in 879 post(s)
|
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) Code:
#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 Code:this.Parent.OnBeforeWorksheetUnoad += ...
Edited by user 20 November 2015 20:40:55(UTC)
| Reason: Not specified |
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |
1 user thanked Davide Carpi for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 03/03/2014(UTC) Posts: 418 Was thanked: 125 time(s) in 96 post(s)
|
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 Edited by user 21 November 2015 00:33:15(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,654 Location: Italy Was thanked: 1340 time(s) in 879 post(s)
|
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: Code: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: Code: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: Code:Public Sub Dispose() Implements IDisposable.Dispose
''' ...
DoSomething(GlobalEnvironment.FileName)
''' ...
End Sub
Edited by user 21 November 2015 03:30:24(UTC)
| Reason: Not specified |
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |
1 user thanked Davide Carpi for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 03/03/2014(UTC) Posts: 418 Was thanked: 125 time(s) in 96 post(s)
|
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
|
1 user thanked Alex M. for this useful post.
|
|
|
SMath Studio Forum
»
SMath Studio
»
Questions
»
SMath plugins - can they do an action on SMath workbook being closed?
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.