Find Ordinal Extensions for Strings|
(By Martin Allen)
Examine the last character in the string and add the correct extension.
Public Function DateExtension(ByVal DateNum As String) As String
Dim date_extension As String
date_extension = ""
If Len(DateNum) > 1 Then
Select Case Right$(DateNum, 2)
Case "11", "12", "13"
date_extension = DateNum & "th"
If Len(date_extension) = 0 Then
' We still haven't found the answer.
Select Case Right$(DateNum, 1)
date_extension = DateNum & "st"
date_extension = DateNum & "nd"
date_extension = DateNum & "rd"
date_extension = DateNum & "th"
DateExtension = date_extension
(By Maurice Calvert)
To round to the nearest 5 cents you can use the easy formula
CInt(amount * 20) / 20
Combining Characters Using Xor
(By Ken Ives)
Have you ever wondered about the Xor command and how it works? Of course,
if you really want to get confused, read the VB help file. This will will
ruin your day. :-)
When you use the Xor command, you are making a bitwise comparison of the binary representation of two values. Xor stands for "exclusive or." A bit in A Xor B is true is the corresponding bit in A is set or the corresponding bit in B is set but not both.
Remember that a binary values consists of bits, each representing a power of 2. For example, the binary value 63 is represented by 00111111 = 32 + 16 + 8 + 4 + 2 + 1.
When working with text, one 8-bit byte represents one character with a value between 0 and 255. For example:
|A||65||01000001||64 + 1 = 65|
|?||63||00111111||32 + 16 + 8 + 4 + 2 + 1 = 63|
If you combine these binary values one bit at a time using Xor, you get 01111110 which represents 64 + 32 + 16 + 8 + 4 + 2 = 126 which is the ASCII code for the "~" character. Therefore "A" Xor "?" = "~"
Encrypting With Xor
(By Marc van Steijn)
'Date : 25-01-2001
'Functie : String crypter
'Description: Call this function to crypt and call
' it also to decrypt a string
Public Function CryptString(ptSource As String, _
ptPassword As String) As String
Dim tdest As String
Dim lteller As Long
Dim lPasswTeller As Long
tdest = ptSource
For lteller = 1 To Len(ptSource)
lPasswTeller = lPasswTeller - 1
If lPasswTeller < 1 Then lPasswTeller = Len(ptPassword)
Mid$(tdest, lteller, 1) = _
Chr$(Asc(Mid$(ptSource, lteller, 1)) Xor _
Asc(Mid$(ptPassword, lPasswTeller, 1)))
CryptString = tdest
[Note that this function may produce non-printable characters and that can have some bad side effects depending on what you do with the results. For example, if the results contain a formfeed character (ASCII 12), a TextBox will truncate the results at that character. -- Rod]
To take a root, use:
root_value = number ^ (1 / root)
For example, the cubed root of X is:
root_value = X ^ (1 / 3)
Seed the Random Number Generator
You can use Rnd -1 followed by Randomize to seed Visual Basic's random number generator. Whenever you use the same seed, Rnd will produce the same sequence of random numbers.
Encrypt Code Easily
You can use random number generator seeds to quickly encrypt information. Seed the generator with a key value. Then for each character in the plaintext message, Xor the character with the output of Rnd to get the cypertext character.
To decrypt, seed the generator with the same key value as before. Then for each character in the encrypted message, Xor the character with the output of Rnd to get the plaintext character.
Send your Tips and Tricks to email@example.com.