title: Public function in VB.NET
body: <p>I want to write a global function for my whole project to use in every form. I tried creating a public module and create a public function, but when I call it to my form, it generates error. </p>
  
  <p>let say my global function is about connection to the database. Then when I call it, it says that the connection property is not initialized.</p>
  
  <p>In my function file, I used:</p>
  
  <pre><code> Imports System.Data.SqlClient
   Public Module Connection
      Dim myConnection As SqlConnection
      Public Sub ConnectToDatabase()
         myConnection = New SqlConnection(".............")
         myConnection.Open()
      End Sub
   End Module
  </code></pre>
  
  <p>And in my form, I used:</p>
  
  <pre><code> Private Sub Form_Load(...........) Handles MyBase.Load
      ConnectToDatabase()   'I call the function here
      ...............................................
   End Sub
  </code></pre>
  
  <p>And this does not work.
  Thanks.</p>