|
|
|
Atn2 - Arc tangent of Y/X
|
Total Hit (3466) |
«Code LangId=1»' arc tangent of Y/X - returns values in all four quadrants
Function Atn2(x As Double, y As Double) As Double
If x = 0 Then
Atn2 = Sgn(y) * 1.5707963267949
ElseIf x > 0 Then
Atn2 = Atn(y / x)
Else
Atn2 = Atn(y / x) + 3.14159265358979 * Sgn
....Read More |
Rating
|
|
|
|
Bin - Convert from decimal to binary
|
Total Hit (2790) |
«Code LangId=1»' convert from decimal to binary
' if you pass the Digits argument, the result is truncated
' to that number of digits
'
Function Bin(ByVal value As Long, Optional digits As Long = -1) As String
Dim result As String, exponent As Integer
' this is faster than creating t
....Read More |
Rating
|
|
|
BinToDec - Convert from binary to decimal
|
Total Hit (4112) |
«Code LangId=1»' convert from binary to decimal
'
Function BinToDec(value As String) As Long
Dim result As Long, i As Integer, exponent As Integer
For i = Len(value) To 1 Step -1
Select Case Asc(Mid$(value, i, 1))
Case 48 ' "0", do nothing
Case 4
....Read More |
Rating
|
|
|
BitClear - Clear a bit in a value
|
Total Hit (2731) |
«Code LangId=1»Function BitClear(ByVal value As Long, ByVal bit As Long) As Long
' simply AND with the negation of the bit mask
' Range checking is performed in Power2()
BitClear = (value And Not Power2(bit))
End Function
' Raise 2 to a power
' the exponent must be in the range [
....Read More |
Rating
|
|
|
BitCount - The number of "1" bits in a number
|
Total Hit (2704) |
«Code LangId=1»
' The number of 1's in a binary number
'
' This routine is based on the following property
' of binary numbers: n And (n-1) always clears the
' least significant "1" bit in the number
Function BitCount (ByVal number As Long) As Integer
Do While number
number =
....Read More |
Rating
|
|
|
BitSet - Set a bit in a number
|
Total Hit (2877) |
«Code LangId=1»' Set a bit in a value
'
' NOTE: requires Power2()
Function BitSet(ByVal value As Long, ByVal bit As Long) As Long
' simply OR with the bit mask
' Range checking is performed in Power2()
BitSet = (value Or Power2(bit))
End Function
' Raise 2 to a power
' the e
....Read More |
Rating
|
|
|
BitTest - Test the value of a bit
|
Total Hit (3580) |
«Code LangId=1»' Test the value of a bit
'
' NOTE: requires Power2()
Function BitTest(ByVal value As Long, ByVal bit As Long) As Boolean
' simply AND with the bit mask
' Range checking is performed in Power2()
BitTest = (value And Power2(bit))
End Function
' Raise 2 to a po
....Read More |
Rating
|
|
|
BitToggle - Invert a bit in a value
|
Total Hit (2961) |
«Code LangId=1»' Toggle a bit in a value
'
' NOTE: requires Power2()
Function BitToggle(ByVal value As Long, ByVal bit As Long) As Long
' simply XOR with the negation of the bit mask
' Range checking is performed in Power2()
BitToggle = (value Xor Power2(bit))
End Function
....Read More |
Rating
|
|
|
CComplexNumber - A class for dealing with complex numbers
|
Total Hit (2764) |
«Code LangId=1»Option Explicit
'------------------------------------------
' A class for dealing with complex numbers
'------------------------------------------
' The main properties
Public Real As Double
Public Imaginary As Double
' Initialize this complex number
' (returns Me)
Fu
....Read More |
Rating
|
|
|
|
CompareValue - Check whether a value is in a list of values
|
Total Hit (2808) |
«Code LangId=2»' Compares a numeric or string value with a list of other values.
' Returns the 1-based index of the matching value, or zero if the
' value doesn't appear in the list.
' String comparisons are case-sensitive.
'
' This function can conveniently replace a Select Case or a list
'
....Read More |
Rating
|
|
|
DisplayExceptionInfo - Displaying error information
|
Total Hit (2885) |
«Code LangId=2»
' A reusable routine that displays error information
' Note: requires Imports System.Reflection
Sub DisplayExceptionInfo(ByVal e As Exception)
' Display the error message.
Console.WriteLine(e.Message)
Dim st As New StackTrace(e, True)
Dim i As Integer
....Read More |
Rating
|
|
|
|
|
|
IsComDLL - Check whether a DLL is an COM self-registering server
|
Total Hit (3133) |
«Code LangId=2»<System.Runtime.InteropServices.DllImport("kernel32")> Shared Function _
LoadLibrary(ByVal path As String) As Integer
End Function
<System.Runtime.InteropServices.DllImport("kernel32")> Shared Function _
GetProcAddress(ByVal hModule As Integer, ByVal procName As String)
....Read More |
Rating
|
|
|
|
IsValidEmail - Validate an email address
|
Total Hit (2704) |
«Code LangId=2»
Function IsValidEmail(ByVal Value As String, Optional ByVal MaxLength As _
Integer = 255, Optional ByVal IsRequired As Boolean = True) As Boolean
If Value Is Nothing OrElse Value.Length = 0 Then
' rule out the null string case
Return Not IsRequired
....Read More |
Rating
|
|
|
|
IsValidUsPhoneNumber - Validating a US phone number
|
Total Hit (3085) |
«Code LangId=2»
' Validate a US phone number
' Example:
' MessageBox.Show(IsValidUsPhoneNumber("(123) 456-7890")) ' True
' MessageBox.Show(IsValidUsPhoneNumber("(123) 456-78901")) ' False
Function IsValidUsPhoneNumber(ByVal phnNum As String) As Boolean
Return System.Text.RegularExp
....Read More |
Rating
|
|
|
IsValidEmail - Validate an email address
|
Total Hit (3598) |
«Code LangId=2»
Function IsValidEmail(ByVal Value As String, Optional ByVal MaxLength As _
Integer = 255, Optional ByVal IsRequired As Boolean = True) As Boolean
If Value Is Nothing OrElse Value.Length = 0 Then
' rule out the null string case
Return Not IsRequired
....Read More |
Rating
|
|
|
IsValidUsPhoneNumber - Validating a US phone number
|
Total Hit (3035) |
«Code LangId=2»
' Validate a US phone number
' Example:
' MessageBox.Show(IsValidUsPhoneNumber("(123) 456-7890")) ' True
' MessageBox.Show(IsValidUsPhoneNumber("(123) 456-78901")) ' False
Function IsValidUsPhoneNumber(ByVal phnNum As String) As Boolean
Return System.Text.RegularExp
....Read More |
Rating
|
|
|
IsValidUsSSN - Validating a US Social Security Number (SSN)
|
Total Hit (4065) |
«Code LangId=2»
' Validate a US Social Security Number
' Example:
' MessageBox.Show(IsValidUsSSN("123-12-1234")) ' True
' MessageBox.Show(IsValidUsSSN("123-123-1234")) ' False
Function IsValidUsSSN(ByVal ssn As String) As Boolean
Return System.Text.RegularExpressions.Regex.IsMatch(
....Read More |
Rating
|
|
|
IsValidUsZip - Validating a US ZIP code
|
Total Hit (2865) |
«Code LangId=2»
' Validate a US ZIP code
' Example:
' MessageBox.Show(IsValidUsZip("12345")) ' => True
' MessageBox.Show(IsValidUsZip("12345-1234")) ' => True
' MessageBox.Show(IsValidUsZip("12345-12345")) ' => False
Function IsValidUsZip(ByVal zip As String) As Boolean
Re
....Read More |
Rating
|
|
|
KeepInRange - Ensure that a value is in a given range
|
Total Hit (2615) |
«Code LangId=2»
' Keep the first argument in the range [lowLimit, highLimit]
' If the value is adjusted, the fourth (optional) argument is set to True
'
' This function works will all basic data types and with objects
' that implement the IComparable interface
Function KeepInRange(ByVal va
....Read More |
Rating
|
|
|
|
Any2Dec - Convert from any numeric base to decimal
|
Total Hit (3320) |
«Code LangId=1»' convert from any base to decimal
' BASE can be in the range 2-36
Function Any2Dec(ByVal otherBaseNumber As String, ByVal base As Integer) As Long
Dim index As Long
Dim digits As String
Dim digitValue As Long
' check base
If base < 2 Or base > 36 T
....Read More |
Rating
|
|