none
vb.net help with visio add in RRS feed

  • Question

  • Hey all,

    I've created an add in that is made of a custom ribbon with a button. When you click the button a windows form appears that has another button. All I'm trying to do is make a shape appear and drop on the page when the button in the windows form is clicked. I've literally tried everything I can think of and for some reason I keep getting an error saying my variable hasn't been asigned to a value (or something to that nature).

    I'm adding this code under the button click event handler. This is what I have right now.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim vsoshape As Visio.Shape
            Dim xbeg As Double
            Dim ybeg As Double
            Dim xend As Double
            Dim yend As Double

            vsoshape.DrawRectangle(xbeg, ybeg, xend, yend)

        End Sub

    I'm new to writing code of any kind so any help would be greatly appreciated.

    Monday, September 2, 2013 9:17 AM

Answers

  • Hi,

    The object need to be instantiated before using.

    According to your code, I think you are trying to insert shapes to the Visio Page.

    Here is code for your reference:

    Define a global variable in the Form:

    Dim p As Microsoft.Office.Interop.Visio.Page

    Modify Form construct:

    Sub New(ByRef p As Microsoft.Office.Interop.Visio.Page)
    
    
            Me.p = p
    
            ' This call is required by the designer.
    
            InitializeComponent()
    
    
            ' Add any initialization after the InitializeComponent() call.
    
            'replace your usercontrl here
    
            Me.Controls.Add(New UserControl1())
    
    
    End Sub

    Modify Ribbon Button Click: 

       Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
    
            Dim form1 As New Form1(Globals.ThisAddIn.Application.ActivePage)
            form1.Show()
    End Sub

    Modify Form Button Click: 

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            'Dim vsoshape As Visio.Shape
    
            Dim xbeg As Double = 1
    
            Dim ybeg As Double = 2
    
            Dim xend As Double = 2
    
            Dim yend As Double = 1
    
            Dim shape = p.DrawRectangle(xbeg, ybeg, xend, yend)
    
            shape .DrawRectangle(xbeg, ybeg, xend, yend)
    
    
        End Sub


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Wednesday, September 4, 2013 9:29 AM
    Moderator

All replies

  • I just realized I didn't assign values to the variables. It still doesn't change anything though.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim vsoshape As Visio.Shape
            Dim xbeg As Double = 1
            Dim ybeg As Double = 2
            Dim xend As Double = 2
            Dim yend As Double = 1

            vsoshape.DrawRectangle(xbeg, ybeg, xend, yend)

        End Sub

    Tuesday, September 3, 2013 12:34 AM
  • Hi,

    The object need to be instantiated before using.

    According to your code, I think you are trying to insert shapes to the Visio Page.

    Here is code for your reference:

    Define a global variable in the Form:

    Dim p As Microsoft.Office.Interop.Visio.Page

    Modify Form construct:

    Sub New(ByRef p As Microsoft.Office.Interop.Visio.Page)
    
    
            Me.p = p
    
            ' This call is required by the designer.
    
            InitializeComponent()
    
    
            ' Add any initialization after the InitializeComponent() call.
    
            'replace your usercontrl here
    
            Me.Controls.Add(New UserControl1())
    
    
    End Sub

    Modify Ribbon Button Click: 

       Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
    
            Dim form1 As New Form1(Globals.ThisAddIn.Application.ActivePage)
            form1.Show()
    End Sub

    Modify Form Button Click: 

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            'Dim vsoshape As Visio.Shape
    
            Dim xbeg As Double = 1
    
            Dim ybeg As Double = 2
    
            Dim xend As Double = 2
    
            Dim yend As Double = 1
    
            Dim shape = p.DrawRectangle(xbeg, ybeg, xend, yend)
    
            shape .DrawRectangle(xbeg, ybeg, xend, yend)
    
    
        End Sub


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Wednesday, September 4, 2013 9:29 AM
    Moderator