Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb.net - global function

I want to create a global function to use throughout my application. Let say it's about the connection to the database.

My code that i plan to use in my global function is:

myConnection = New SqlConnection("...........")
 myConnection.Open()

So that I can call it to use in every form throughout my application. This can make me easy to edit the connection later.

Could anyone help me show how to define this global function and how to call this function in the form.

Best regard,

like image 219
Tepken Vannkorn Avatar asked Feb 21 '26 06:02

Tepken Vannkorn


1 Answers

Public NotInheritable Class Utilities

Private Sub New()
End Sub

Public Shared Function MyMethod(myParam As Object) As MyObject
    'Do stuff in here
    Return New MyObject()
End Function

 End Class

And then to consume

Dim instance As MyObject = Utilities.MyMethod(parameterObject)
like image 54
Paulie Waulie Avatar answered Feb 24 '26 13:02

Paulie Waulie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!