Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline Alex M.  
#1 Posted : 20 November 2015 18:22:35(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

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

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Davide Carpi  
#2 Posted : 20 November 2015 20:37:03(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,654
Man
Italy
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
thanks 1 user thanked Davide Carpi for this useful post.
on 20/11/2015(UTC)
Offline Alex M.  
#3 Posted : 21 November 2015 00:31:35(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

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

Offline Davide Carpi  
#4 Posted : 21 November 2015 03:21:57(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,654
Man
Italy
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
thanks 1 user thanked Davide Carpi for this useful post.
on 21/11/2015(UTC)
Offline Alex M.  
#5 Posted : 21 November 2015 04:38:57(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

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
thanks 1 user thanked Alex M. for this useful post.
on 21/11/2015(UTC)
Users browsing this topic
Guest
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.