Muhnamana
Muhnamana

Reputation: 1044

What's the best way to reference code over and over?

Just as an example, say I'd like to reference a msgbox in multiple areas, could I create a function for this? Private or Public? Differences?

Here's an example.

Public Function Message() As String
   MsgBox("Test Message")
End Function

Also, why would I get the following message: Function 'Message' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used

It seems as though its just a warning and it seemed to work when I called the function.

Upvotes: 0

Views: 46

Answers (1)

asawyer
asawyer

Reputation: 17808

Make it Sub so it's not expecting a return value.

Public Sub Message() As String
   MsgBox("Test Message")
End Sub

Upvotes: 1

Related Questions