Hi

I'm looking for the VB.NET way to segregating my controller code and the form. Let me explain. In VB6 I had something like this, please bear with me.

VB Code:
  1. ' Inside frmMain
  2. Private pvObjFormController as clsMainFormController
  3.  
  4. Private sub Form_Load()
  5.   set pvObjFormController = new clsMainFormController
  6.   pvObjFormController.init Me
  7. End Sub
  8. Private Sub cmdSave_Click()
  9.     If pvObjFormController.Save Then
  10.         Msgbox "Data was successfully saved"
  11.     Else
  12.         MsgBox "Failed to save data " & pvObjFormController.ErrMsg
  13.     End If
  14. End Sub
  15. private sub Form_Unload()
  16.   set pvObjFormController = nothing
  17. End Sub
  18.  
  19. ' ------
  20. ' Code inside clsMainFormController.cls
  21.  
  22. ' define a class level variable to hold reference to the form
  23. Private pvFrmMain as frmMain
  24. private pvObjCustomer as clsCustomer
  25.  
  26. public ErrMsg as string
  27. Public Sub Init(byval oFrm as frmMain)
  28.    set pvFrmMain = oFrm
  29. End Sub
  30.  
  31. Public Function Save() as Boolean
  32.    Call ControlsToObect
  33.    If pvObjCustomer.Update Then
  34.        Save = True
  35.    Else
  36.        Save = False
  37.         Me.ErrMsg = pvObjCustomer.ErrMsg
  38.    
  39.    End If
  40.  
  41. End Function
  42. private ControlsToObject()
  43.    pvObjCustomer.CustomerID = pvFrmMain.txtCustomerID
  44.    pvObjCustomer.Surname= pvFrmMain.txtSurname
  45.   ' And so on assign control properties to my class object properties
  46.  
  47.  
  48. End Sub
  49. private sub ObjectToControls()
  50.    pvFrmMain.txtCustomerID = pvObjCustomer.CustomerID
  51.    pvFrmMain.txtSurname  = pvObjCustomer.Surname
  52.   ' And so on assign object properties from control properties object properties
  53.  
  54. End Sub
  55. private function DataIsValid() as boolean
  56.  
  57.   ' code to validate controls
  58. End Function

Now if you're wondering why I use this technique is that we use sourcesafe and while one developer concentrates on the visual interface of the form another can write the necessary validation code and stuff like this. For example in my sample above developer A works on the form, developer B works on clsMainFormController.cls while developer C works in the clsCustomer.cls. Of course developer A will have to advise developer B about any new controls added etc. I also like this technique because if you mess up the form (which happens very often) your validation and save routines are intact.

Thanks for being patient to read up to here . My question is, how do I apply the same principle in VB.NET? To begin with I won't want to make all my controls as public since you can access controls as frmMain.txtCustomer.text as in VB6. Should I inherit the Main form in a class and apply the necessary validations etc. I would really appreciate if our VB.NET experts in this forum could use the above VB6 code and show some VB.NET samples.

Thanks a lot