Question Global Public Generic Functions in Singleton Class

aychekay

Member
Joined
Oct 10, 2011
Messages
11
Programming Experience
3-5
What's the recommended way to make common, generic functions globally available throughout my application? I do recognize that there probably isn't much need for this since I should be explicitly defining and implementing classes (and their functions/methods) whenever and wherever possible.

For a real world example, I have a function called Nz to duplicate the Nz function in MS Access. It prevents null errors when assigning database values to string variables or textboxes. I plan to use this throughout my application.

VB.NET:
    Private Function Nz(ByVal v, ByVal r)
        If IsDBNull(v) Then
            Nz = r
        Else
            Nz = v
        End If
    End Function

On a form I would use this function something like this:
VB.NET:
    Me.lblPODate.Text = Nz(rdr("dtePODate"), "(No PO Date)")

I will also have generic functions to save and retrieve user settings (I'm handling these myself, in my own database table because we are still actively developing in MS Access). It might make more sense to put these in a class but it seems like it will require more code every time I need to lookup a setting.

Is there no reason to use global public functions? If it's OK to do this, what's the best way to accomplish it?
 

Latest posts

Back
Top