slightlyoff
asked on
Global Subs and Functions VB.NET
I have a couple of functions I would like to be available across my classes and forms.
Error Logging, Progress Logging, Send Mail and a Message Box helper for debugging.
I know I can define these on my main form called "Main" and then call them in a class as Main.SubName() - but being a lazy bugger, I want to be able to just call them as SubName() without the main form name.
I created a new class here's my code:
In my forms and classes I imported myHelpers - but that did not work, mbHelper is not recognized.
Any ideas what I'm missing? Sorry if this is a simple problem - but I really appreciate the help!!!
Error Logging, Progress Logging, Send Mail and a Message Box helper for debugging.
I know I can define these on my main form called "Main" and then call them in a class as Main.SubName() - but being a lazy bugger, I want to be able to just call them as SubName() without the main form name.
I created a new class here's my code:
Public Class myHelpers
'Message Box Helper - for debugging
Public Shared Sub mbHelper(ByVal lineNumber As Integer, ByVal Task As String, ByVal message As String, ByVal additionalInfo As String)
Dim title As String = "Debug Information"
Dim messageText As String = "Line Number: " & lineNumber & vbCrLf & "Task: " & Task & vbCrLf & "Message: " & message & vbCrLf & "Additional Info: " & additionalInfo
MsgBox(messageText, MsgBoxStyle.OkOnly, title)
End Sub
End Class
In my forms and classes I imported myHelpers - but that did not work, mbHelper is not recognized.
Any ideas what I'm missing? Sorry if this is a simple problem - but I really appreciate the help!!!
In .NET there is no such concept as "global functions"--static methods are the closest equivalent. Even though the old VB6-style functions like Mid, InStr, and MsgBox are available in .NET, really they are just syntactic sugar, and their usages gets mapped into actual class/methods (Strings.Mid, Strings.InStr, Interaction.MsgBox). I'm afraid you won't get to be *that* lazy in .NET = )
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help! I guess I'll just get used to typing it out then. Thank you!
ASKER
LOL - I responded too fast. I'll give that a try.
ASKER
Perfect! Thank you so much :)