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

observer pattern , vb.net , mvc Calgary, Canada
  • 11 years ago
    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 '''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

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Anyone who considers arithmetic methods of producing random digits is, of course, in a state of sin.” - John von Neumann