C# Snippets
Number_IsDigits
Public Shared Function IsDigits(ByVal sTextValue As String) As Boolean
Try
If gbEND_GENERAL = True Then Exit Function
Dim icharno As Int32
IsDigits = True
For icharno = 0 To sTextValue.Length - 1
If Char.IsDigit(sTextValue.Chars(icharno)) = False Then
IsDigits = False
Exit Function
End If
Next icharno
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("IsDigits", msCLASSNAME, _
"determine if '" & sTextValue & "' contains all numerical characters.", _
mobjCOMException, mobjException)
End If
End Try
End Function
Number_IsEven
Public Function Number_IsEven(ByVal TheNumber As Integer) As Boolean
Try
If TheNumber Mod 2 = 0 Then
Return True
Else
Return False
End If
Catch ex As System.Exception
Call modMessages.ErrorMessage(System.Reflection.MethodBase.GetCurrentMethod, ex.Message)
End Try
End Function
Number_IsInteger
Public Shared Function IsInteger(ByVal sTextValue As String) As Boolean
Try
Dim iresult As Integer
iresult = CType(sTextValue, System.Int32)
IsInteger = True
Catch
IsInteger = False
End Try
End Function
Number_IsItInRange
Public Function Number_IsItInRange(ByVal sngNumber As Single, _
ByVal sngMinValue As Single, _
ByVal sngMaxValue As Single, _
Optional ByVal bEqualTo As Boolean = True, _
Optional ByVal bInformUser As Boolean = False) As Boolean
Try
If My.Settings.USER_ERROR_OCCURRED = True Then Exit Function
If bEqualTo = True Then
If (sngNumber >= sngMinValue) And (sngNumber <= sngMaxValue) Then
Return True
Else
If (bInformUser = True) Then
System.Windows.Forms.MessageBox.Show("The number must be between " & sngMinValue & " and " & sngMaxValue & ".", _
"Number Out of Range")
End If
Return False
End If
Else
If (sngNumber > sngMinValue) And (sngNumber < sngMaxValue) Then
Return True
Else
If (bInformUser = True) Then
System.Windows.Forms.MessageBox.Show("The number must be between " & sngMinValue & " and " & sngMaxValue & ".", _
"Number Out of Range")
End If
Return False
End If
End If
Catch objCOMException As System.Runtime.InteropServices.COMException
m_objCOMException = objCOMException
Catch objException As Exception
m_objException = objException
Finally
If (IsNothing(m_objCOMException) = False Or IsNothing(m_objException) = False) Then
Call modMessages.ErrorMessage( _
System.Reflection.MethodBase.GetCurrentMethod, m_objCOMException, m_objException, _
"determine if the number '" & sngNumber & "' is in the range between" & _
" '" & sngMinValue & "' to '" & sngMaxValue & "' or not.")
End If
End Try
End Function
Number_LargestOneSingle
Public Shared Function LargestOneSingle(ByVal ParamArray sngNumbers() As Single) _
As Single
Try
If gbEND_GENERAL = True Then Exit Function
Dim sngNumber As Single
Dim snglargest As Single
snglargest = sngNumbers(0)
For Each sngNumber In sngNumbers
If sngNumber > snglargest Then snglargest = sngNumber
Next sngNumber
LargestOneSingle = snglargest
Catch objCOMException As System.Runtime.InteropServices.COMException
gobjCOMException = objCOMException
Catch objException As Exception
gobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((IsNothing(gobjCOMException) = False Or IsNothing(gobjException) = False)) Then
Call clsError.Handle("LargestOneSingle", "clsNumber", _
"return the largest number from all those passed in.", _
gobjCOMException, gobjException)
End If
End Try
End Function
Number_ReturnPowerOfTen
Public Shared Function ReturnPowerOfTen(ByVal sngNumber As Single) As Integer
Try
If gbEND_GENERAL = True Then Exit Function
'power of ten to multiple with for range 10 < 100
sngNumber = CSng(sngNumber * 1.0001) 'to compensate for 9.999973563636 etc
If (0 < sngNumber) And (sngNumber < 0.0000001) Then ReturnPowerOfTen = 9
If (0.0000001 < sngNumber) And (sngNumber < 0.000001) Then ReturnPowerOfTen = 8
If (0.000001 <= sngNumber) And (sngNumber < 0.00001) Then ReturnPowerOfTen = 7
If (0.00001 <= sngNumber) And (sngNumber < 0.0001) Then ReturnPowerOfTen = 6
If (0.0001 <= sngNumber) And (sngNumber < 0.001) Then ReturnPowerOfTen = 5
If (0.001 <= sngNumber) And (sngNumber < 0.01) Then ReturnPowerOfTen = 4
If (0.01 <= sngNumber) And (sngNumber < 0.1) Then ReturnPowerOfTen = 3
If (0.1 <= sngNumber) And (sngNumber < 1) Then ReturnPowerOfTen = 2
If (1 <= sngNumber) And (sngNumber < 10) Then ReturnPowerOfTen = 1
If (10 <= sngNumber) And (sngNumber < 100) Then ReturnPowerOfTen = 0
If (100 <= sngNumber) And (sngNumber < 1000) Then ReturnPowerOfTen = -1
If (1000 <= sngNumber) And (sngNumber < 10000) Then ReturnPowerOfTen = -2
If (10000 <= sngNumber) And (sngNumber < 100000) Then ReturnPowerOfTen = -3
If (100000 <= sngNumber) And (sngNumber < 1000000) Then ReturnPowerOfTen = -4
If (1000000 <= sngNumber) And (sngNumber < 10000000) Then ReturnPowerOfTen = -5
If (10000000 <= sngNumber) Then ReturnPowerOfTen = -6
Catch objCOMException As System.Runtime.InteropServices.COMException
gobjCOMException = objCOMException
Catch objException As Exception
gobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((IsNothing(gobjCOMException) = False Or IsNothing(gobjException) = False)) Then
Call clsError.Handle("ReturnPowerOfTen", "clsNumber", _
"return to what power of ten the number '" & sngNumber & "' is.", _
gobjCOMException, gobjException)
End If
End Try
End Function
Number_SmallestOneSingle
Public Shared Function SmallestOneSingle(ByVal ParamArray sngNumbers() As Single) _
As Single
Try
If gbEND_GENERAL = True Then Exit Function
Dim sngNumber As Single
Dim sngsmallest As Single
sngsmallest = sngNumbers(0)
For Each sngNumber In sngNumbers
If sngNumber < sngsmallest Then sngsmallest = sngNumber
Next sngNumber
SmallestOneSingle = sngsmallest
Catch objCOMException As System.Runtime.InteropServices.COMException
gobjCOMException = objCOMException
Catch objException As Exception
gobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((IsNothing(gobjCOMException) = False Or IsNothing(gobjException) = False)) Then
Call clsError.Handle("SmallestOneSingle", "clsNumber", _
"return the smallest number from all those passed in.", _
gobjCOMException, gobjException)
End If
End Try
End Function
Number_TenToThePowerOf
Public Shared Function TenToThePowerOf(ByVal iMultiple As Integer) As Single
Try
If gbEND_GENERAL = True Then Exit Function
Dim icount As Integer
Dim ipowersoften As Integer
ipowersoften = 1
If Math.Abs(iMultiple) = 0 Then 'if modulus is zero then no power of ten multiple
ipowersoften = 1
Else
For icount = 1 To Math.Abs(iMultiple)
ipowersoften = 10 * ipowersoften 'obtains power of ten multiple
Next icount
End If
If iMultiple <= 0 Then TenToThePowerOf = CSng(1 / ipowersoften)
'if negative divide (10E-3)
If iMultiple > 0 Then TenToThePowerOf = ipowersoften
'if positive just (10E+3)
Catch objCOMException As System.Runtime.InteropServices.COMException
gobjCOMException = objCOMException
Catch objException As Exception
gobjException = objException
Finally
If gbDEBUG_GENERAL = True Or _
((IsNothing(gobjCOMException) = False Or IsNothing(gobjException) = False)) Then
Call clsError.Handle("TenToThePowerOf", "clsNumber", _
"return 10 to the power of '" & iMultiple & "'.", _
gobjCOMException, gobjException)
End If
End Try
End Function
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top