Question about a download in "Support"

Add-in Express™ Support Service
That's what is more important than anything else

Question about a download in "Support"
How to switch between several task panes programmatically 
Leon Lai Kan




Posts: 119
Joined: 2018-12-20
Hi,

I am playing with the foll. download example:
How to switch between several task panes programmatically
https://www.add-in-express.com/support/vb-net-excel.php


In AddinModule.vb, there are 2 Subs with the same name, but different parameters:


Public Sub ActivateExcelTaskPane(ByVal number As Integer)
        If number = 1 Then
            ActivateTaskPane(AdxExcelTaskPanesCollectionItem2.TaskPaneInstance)
        Else
            ActivateTaskPane(AdxExcelTaskPanesCollectionItem3.TaskPaneInstance)
        End If
    End Sub


Private Sub ActivateTaskPane(ByVal TaskPane As AddinExpress.XL.ADXExcelTaskPane)
        If TaskPane IsNot Nothing Then
            TaskPane.Activate()
        End If
    End Sub



-----------------------
I understand the first Sub clearly:
There are 2 simple task panes: ADXExcelTaskPane1 and ADXExcelTaskPane2.

In ControllingTaskPane.vb, there is another task pane with radio buttons.
If you click on radio button 1, ADXExcelTaskPane1 appears
If you click on radio button 2, ADXExcelTaskPane2 appears

OK
----------------------
But I don't understand the purpose of the 2nd Sub.
It seems essential for the radio buttons to work. Yet, I can't figure out what it does.

Could anyone explain to me what it does?

Why does it have a different parameter from the 1st Sub?

I copy the code again:


Private Sub ActivateTaskPane(ByVal TaskPane As AddinExpress.XL.ADXExcelTaskPane)
        If TaskPane IsNot Nothing Then
            TaskPane.Activate()
        End If
    End Sub



Thanks
Leon
Posted 17 Jan, 2019 05:31:56 Top
Andrei Smolin


Add-in Express team


Posts: 15826
Joined: 2006-05-11
Hello Leon,

These are so-called overloaded methods, see https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/objects-and-classes/overloaded-properties-and-methods. In your case, the method having this signature

ActivateExcelTaskPane(ByVal number As Integer)

invokes the method having this signature

ActivateTaskPane(ByVal TaskPane As AddinExpress.XL.ADXExcelTaskPane)

Note that the IDE highlights the method and all its invocations, if you place the text cursor on a method call (or the method declaration).

You can also imagine they have different names: does this explain them?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Jan, 2019 05:56:02 Top
Leon Lai Kan




Posts: 119
Joined: 2018-12-20
Hi, Andrei

Thanks for your reply.

Useful information on the way!


Private Sub ActivateTaskPane(ByVal TaskPane As AddinExpress.XL.ADXExcelTaskPane) 
        If TaskPane IsNot Nothing Then 
            TaskPane.Activate() 
        End If 
    End Sub 



But what does the above code do?


To which task pane is it referring?
> To the 2 simple task panes, or
> To the task pane containing radio buttons?

Thanks
Leon
Posted 17 Jan, 2019 06:01:52 Top
Andrei Smolin


Add-in Express team


Posts: 15826
Joined: 2006-05-11
Leon Lai Kan writes:
To which task pane is it referring?


To the task pane specified by the TaskPane parameter of that method.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Jan, 2019 06:08:31 Top
Leon Lai Kan




Posts: 119
Joined: 2018-12-20
Andrei,

Just to clear any remaining confusion:

Do you mean that the ActivateTaskPane method in red refers to the Sub in blue?


Public Sub ActivateExcelTaskPane(ByVal number As Integer)
If number = 1 Then
ActivateTaskPane(AdxExcelTaskPanesCollectionItem2.TaskPaneInstance)
Else
ActivateTaskPane(AdxExcelTaskPanesCollectionItem3.TaskPaneInstance)
End If
End Sub


Private Sub ActivateTaskPane(ByVal TaskPane As AddinExpress.XL.ADXExcelTaskPane)
If TaskPane IsNot Nothing Then
TaskPane.Activate()
End If
End Sub


I think I am starting to understand!

Could the 2 subs not be combined into one. That would have been simpler to understand. No?


Leon
Posted 17 Jan, 2019 06:18:51 Top
Andrei Smolin


Add-in Express team


Posts: 15826
Joined: 2006-05-11
Exactly. Please check the above-mentioned page.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Jan, 2019 06:22:33 Top
Leon Lai Kan




Posts: 119
Joined: 2018-12-20
Thanks Andrei

Great insight!

Best Regards,
Leon

-----------------

Hi, Andrei

One final question :-)

Must we absolutely use 2 different Subs (the 2 overloaded subs) to display a task pane (when we click a radio button)?

Is this the way ADX has to work, because one sub has an Integer parameter, and the other Sub has an "ADX...Task Pane" parameter?

Or is it possible to have a single Sub which will display a task pane (when we click a radio button)?
Posted 17 Jan, 2019 06:24:11 Top
Andrei Smolin


Add-in Express team


Posts: 15826
Joined: 2006-05-11
Leon Lai Kan writes:
Must we absolutely use 2 different Subs (the 2 overloaded subs) to display a task pane (when we click a radio button)?


No.

Leon Lai Kan writes:
Is this the way ADX has to work, because one sub has an Integer parameter, and the other Sub has an "ADX...Task Pane" parameter?


No.

Leon Lai Kan writes:
Or is it possible to have a single Sub which will display a task pane (when we click a radio button)?


It is possible. You should choose a way that suits you better.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Jan, 2019 07:18:27 Top