I want to create a toolbar button, which controls toolbar is on MDIForm and I make a function in the Module.
My code like this:

VB.NET Code:
  1. Sub AddToolbarButtons()
  2.         'MDI Main form
  3.         Dim fMain As MDIMain
  4.  
  5.         'create toolbar buttons
  6.         With fMain.TBar
  7.             .Buttons.Clear()
  8.             .Buttons.Add(setButton("Add", 1))
  9.             .Buttons.Add(setButton("Modify", 2))
  10.             .Buttons.Add(setButton("Delete", 3))
  11.             .Buttons.Add(setButton("Preview", 4))
  12.             .Buttons.Add(setButton("Refresh", 5))
  13.             .Buttons.Add(setButton("Close", 6))
  14.         End With
  15.  
  16. Function setButton(ByVal txt, ByVal imgIdx) As ToolBarButton
  17.         Dim btn As New ToolBarButton
  18.         btn.Text = txt
  19.         btn.ImageIndex = imgIdx
  20.         Return btn
  21.     End Function

and I get an error message like this:
Code:
An unhandled exception of type 'System.NullReferenceException' occurred in POSClient.exe

Additional information: Object reference not set to an instance of an object.
at
VB.NET Code:
  1. 'create toolbar buttons
  2.         With fMain.TBar

what's the solution ?

thank you