CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2009
    Posts
    27

    MVC (Model-View-Controller) implementation in VB.NET

    I am wondering what I am missing in the attached code that is making it impossible for me to make the VB.NET program below work using MVC (Model-View-Controller).

    Right now, I am really lost despite my best efforts...

    I am trying to implement the observer pattern and think that my code is getting closer to MVC but not quite there yet, firstly because it wont even run ... nevertheless I know that there is someone out there who knows what I am doing wrong
    and I would definitely benefit from any guidance or help that someone more experienced in MVC VB.NET implementation can
    give .. hence this letter.

    So far Im really stumped and would forever be grateful for any help you could give.

    Gratefully,
    Matt

    P.S.
    I think the original post did not make it as when I try to search using the name of the one who posted the thread I dont get any result returned .... in that post I experimented using attachment ... looks like there is a problem with using attachment so I am redoing the posting here and this time not using any attachment and instead I have copy pasted all the source code here as shown below ... thanks

    Code:
    '''first interface the subject interface
    
    Interface Isubject
        Sub registerobserver(Iobserver o)
        sub removeobserver(Iobserver o)
        Sub notifyobservers()
    End Interface
    
    
    '''second interface the observer interface
    
    Interface Iobserver
        Sub update()
    End Interface
    
    '''1st class
    Imports Autodesk.AutoCAD.Interop
    Imports AutocadMAP
    Imports Scripting
    
    Public Class AutoCADaccess
        Private ThisDrawing As AcadDocument
        Private DrawingName As String
    
        Public Sub AutoCADaccess() implements Isubject
            Iobserver = New ArrayList
        End Sub
    
        public sub registerObserver(Iobserver o)
            Iobserver.add(o)
        End Sub
    
        Public Function connectDrawing() As AcadDocument
            Dim AcadApp As AcadApplication
            Dim DrawingTitle As String
            If ThisDrawing Is Nothing Then
                On Error Resume Next
                Err.Clear()
                AcadApp = GetObject(, "AutoCAD.Application")
                If Err.Number Then 'need to create object
                    AcadApp = CreateObject("AutoCAD.Application")
                End If
    
                AcadApp.Visible = True
                ThisDrawing = AcadApp.ActiveDocument
                AcadApp.WindowState = Common.AcWindowState.acMax
                ThisDrawing.WindowState = Common.AcWindowState.acMax
    
            End If
    
            connectDrawing = ThisDrawing
    
        End Function
    
    
        Public Function setDrawingTitle() As String
            Dim ObtainedTitle As String
            ObtainedTitle = ThisDrawing.GetVariable("dwgname")
            Me.DrawingName = "Title Block [" & ObtainedTitle & "]"
        End Function
    
    End Class
    
    '''2nd class
    
    Imports Autodesk.AutoCAD.Interop
    Imports AutocadMAP
    Imports Scripting
    
    Public Class AutoCADtitle
        Public Shared Sub main()
            Static ThisDrawing As AcadDocument
            Dim acad As New AutoCADaccess
            Dim AcadMap As AcadMap
    
            With acad
                ThisDrawing = .connectDrawing
            End With
    
            MsgBox("Title Block [" & ThisDrawing.GetVariable("dwgname") & "]")
        End Sub
    
    End Class
    
    
    '''the form which I am trying to have absorb in its caption the drawing name of the current drawing
    Option Explicit On 
    
    Imports Autodesk.AutoCAD.Interop
    Imports AutocadMAP
    Imports Scripting
    
    Public Class frmTitleBlk
        Inherits System.Windows.Forms.Form
    
    end Class
    
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''  THE GOAL, IE.. THAT OF GRABBING THE NAME OF THE           '
    ''''  CURRENT DRAWING AND PUTTING IT IN THE CAPTION OF          '
    ''''  THE LOADED FORM (frmTitle) IS EASY TO IMPLEMENT IF ONLY WE'
    ''''  ARE NOT DICTATED TO USE MVC ... IN THE LONG RUN           ' 
    ''''  I GUESS MVC ARCHITECTURE IS GOOD  SO I AM TRYING          '
    ''''  TO BUILD THE THING USING IT ... ANYHOW, THE WAY           '
    ''''  I ORIGINALLY WROTE THE PROGRAM IS SHOWN BELOW WHICH       '
    ''''  I HAVE MODIFIED TO THAT WHICH IS SHOWN ABOVE              '
    ''''  IE..THE ABOVE IS MOVING TOWARDS MVC .. BUT IN THE         '
    ''''  ABOVE I AM NOT EVEN SURE IF I CAN DO frmTitleBlk.show from'
    ''''  from the sub called main without breaking MVC rules       '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    
    Imports Autodesk.AutoCAD.Interop
    Imports AutocadMAP
    Imports Scripting
    
    Public Class AutoCADaccess
        Private ThisDrawing As AcadDocument
    
        Public Function connectDrawing() As AcadDocument
            Dim AcadApp As AcadApplication
    
            If ThisDrawing Is Nothing Then
                On Error Resume Next
                Err.Clear()
                AcadApp = GetObject(, "AutoCAD.Application")
                If Err.Number Then 'need to create object
                    AcadApp = CreateObject("AutoCAD.Application")
                End If
    
                AcadApp.Visible = True
                ThisDrawing = AcadApp.ActiveDocument
                AcadApp.WindowState = Common.AcWindowState.acMax
                ThisDrawing.WindowState = Common.AcWindowState.acMax
    
            End If
    
            connectDrawing = ThisDrawing
    
        End Function
    
    End Class
    
    
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Option Explicit On 
    
    Imports Autodesk.AutoCAD.Interop
    Imports AutocadMAP
    Imports Scripting
    
    Public Class frmTitleBlk
        Inherits System.Windows.Forms.Form
    
        Private Sub TitleBlk_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim ThisDrawing As AcadDocument
            Dim acad As New AutoCADaccess
            Dim AcadMap As AcadMap
    
            With acad
                ThisDrawing = .connectDrawing
            End With
            Me.Text = "Title Block [" & ThisDrawing.GetVariable("dwgname") & "]"
        End Sub
    
    End Class
    Last edited by Shuja Ali; April 27th, 2009 at 02:20 AM. Reason: Added code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: MVC (Model-View-Controller) implementation in VB.NET

    First, using AutoCAD might cause it's own problems, but the main thing is that you forgot your CODE TAGS.
    Code:
    ' Like This
    Go back and edit your post to correct the problem, and someone can take a look at the details. Too hard to read like that.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2009
    Posts
    27

    Re: MVC (Model-View-Controller) implementation in VB.NET

    Thanks ...

    I have tried to re-attach the VB.NET source codes here in a zip file which has two
    folders the second folder is the one that has my latest attempt:

    "Second Try trying Implementing MVC using Observer Pattern still far from success"

    My first attempt at implementing it is shown in the folder:

    "First Try Implementing MVC no good"

    Thanks again, I really appreciate it.

    Gratefully,
    Matt

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: MVC (Model-View-Controller) implementation in VB.NET

    Matt, I had this link bookmarked long time back. May be you should go through this once and see how it is done in the example that he has shown. Al though it is little old, but I guess you can still use it
    http://www.devx.com/dotnet/Article/10186

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: MVC (Model-View-Controller) implementation in VB.NET

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Apr 2009
    Posts
    27

    Re: MVC (Model-View-Controller) implementation in VB.NET

    Thank you for your valuable answer, the link is enlightening indeed and has filled in many of the gaps in most of the materials I have.

    Gratefully,
    Matt

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: MVC (Model-View-Controller) implementation in VB.NET

    Technet has a lot of info, and the blogs in general are focues on separate topics about everything
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured