Shared functions vs Non-Shared Functions



I am setting up some of my functions in a class called MyFunctions.

I am not clear as to the best time to set a function as Shared and when not
to. For example, I have the following bit manipulation routines in my
Class:

*******************************************************************************
imports System

NameSpace MyFunctions

Public Class BitHandling

'*----------------------------------------------------------*
'* Name : BitSet *
'*----------------------------------------------------------*
'* Purpose : Sets a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitSet(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H80000000 Or Number
Else
Number = (2 ^ Bit) Or Number
End If
BitSet = Number
End Function

'*----------------------------------------------------------*
'* Name : BitClear *
'*----------------------------------------------------------*
'* Purpose : Clears a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitClear(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H7FFFFFFF And Number
Else
Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
End If

BitClear = Number
End Function

'*----------------------------------------------------------*
'* Name : BitIsSet *
'*----------------------------------------------------------*
'* Purpose : Test if bit 0 to bit 31 is set *
'*----------------------------------------------------------*
Public Shared Function BitIsSet(ByVal Number As Integer, _
ByVal Bit As Integer) As Boolean
BitIsSet = False

If Bit = 31 Then
If Number And &H80000000 Then BitIsSet = True
Else
If Number And (2 ^ Bit) Then BitIsSet = True
End If
End Function

End Class

End Namespace

********************************************************************************

Now I have these set up as shared so I don't have to create an instance of
the class:

temp = BitHandling.BitSet(temp,3)

vs.

dim MyBits as new BitHandling
temp = MyBits.BitSet(temp,3)

I am also setting up my function to send out various emails which entails
reading an Sql Record and reading a text file from disk, as well as sending
the email:

SmtpMail.SmtpServer = mailServer
smtpMail.Send(message)

What would tell me that I need to make this a non-shared function vs a
shared one?

Thanks,

Tom


.



Relevant Pages

  • Re: Class not getting built
    ... Imports System.Text.RegularExpressions ... Namespace MyFunctions ... Public Shared Function BitClear(ByVal Number As Integer, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Class not getting built
    ... Imports System.Text.RegularExpressions ... Namespace MyFunctions ... Public Shared Function BitClear(ByVal Number As Integer, ...
    (microsoft.public.dotnet.framework.aspnet)

Loading