Solved

VB.net Can't use a variable anywhere else in the project

Posted on 2012-03-30
3
245 Views
Last Modified: 2012-03-30
Hi. Below is the code that has the variable TpSqlEditCustomTaskPane at the top that I am trying to call from any other part of the project but can't seem to.

Thanks



Public Class ThisAddIn


    Private _tpSqlEdit As TpSQLEdit
    Public TpSqlEditCustomTaskPane As Microsoft.Office.Tools.CustomTaskPane
    Private oUserControl1 As UserControl1
    Public oRightTaskPane As Microsoft.Office.Tools.CustomTaskPane

    Private Sub ThisAddIn_Startup() Handles Me.Startup
        'Fire the Custom TaskPane
        AddTpSqlEdit()
        AddSideTaskPane()
    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub

    'Create the Custom TaskPane and Dock Bottom
    'You must Add your Control here
    Private Sub AddTpSqlEdit()
        _tpSqlEdit = New TpSqlEdit()
        TpSqlEditCustomTaskPane = CustomTaskPanes.Add(_tpSqlEdit, "SELECT Elements")
        TpSqlEditCustomTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionBottom
        'Show TaskPane
        TpSqlEditCustomTaskPane.Visible = True
    End Sub

    Private Sub AddSideTaskPane()
        oUserControl1 = New UserControl1
        oRightTaskPane = CustomTaskPanes.Add(oUserControl1, "FROM Elements")
        oRightTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight
        'Show TaskPane
        oRightTaskPane.Visible = True
    End Sub




End Class
0
Comment
Question by:murbro
3 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 37786458
You have made "TpSqlEditCustomTaskPane" an instance variable, which means you won't have access to that member anywhere outside of this class without having a valid instance of the class ThisAddIn. In other words, if I had this function:

Function SomeFunctionOutsideOfThisAddIn

End Function

Open in new window


...I cannot do this:

Function SomeFunctionOutsideOfThisAddIn
    Dim x = TpSqlEditCustomTaskPane
End Function

Open in new window


...but I can do this:

Function SomeFunctionOutsideOfThisAddIn
    Dim c As New ThisAddIn()
    Dim x = c.TpSqlEditCustomTaskPane
End Function

Open in new window

0
 
LVL 8

Accepted Solution

by:
gpizzuto earned 250 total points
ID: 37786501
RIGHT: you declared an instance variable.
If you want the variable to be visible outside (without instancing the class)
you can also declare the variable as SHARED: All instances of the class will share THE SAME VARIABLE
0
 

Author Closing Comment

by:murbro
ID: 37788461
Thanks very much
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question