[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Generate 12 character passkey from DateOfBirth and ZipCode

Posted on 2004-11-14
3
Medium Priority
?
137 Views
Last Modified: 2010-05-18
I am using VBScript and want some code that can generate a 12 character passkey using strDateOfBirth and strZipCode.

strDateOfBirth will be in format ddmmyyyy so 29/03/2004 would be 29032004.
This string will be a fixed length of 8 characters.

strZipCode will be of variable length and format as it could be a Zip/Post code from any where around the world.

I want the process to be reversible so given the 12 character (alphanumeric) passkey I can get the original DOB and Postcode from it.
0
Comment
Question by:holgrave
  • 2
2 Comments
 
LVL 19

Accepted Solution

by:
Shauli earned 1200 total points
ID: 12579332
'in form declaration area
Dim strDateOfBirth As String, strZipCode As String

'in command button or where you want to activate functions
Private Sub Command1_Click()
Dim strPassKey As String
strDateOfBirth = Format(Text1.Text, "ddmmyyyy")
strZipCode = Text2.Text

'activate function to build passkey
strPassKey = Build_PassKey(strDateOfBirth, strZipCode)
MsgBox strPassKey

'activate sub to reverse passkey
Call Reverse_PassKey(strPassKey)
 MsgBox "DOB: " & strDateOfBirth & ",  ZipCode: " & strZipCode
End Sub

'function to build passkey
Public Function Build_PassKey(ByVal fnDOB As String, fnZipCode As String) As String
Dim dayOfBirth As String, monthOfBirth As String, yearOfBirth As String
'get initial data
dayOfBirth = Left(fnDOB, 2)
monthOfBirth = Mid(fnDOB, 3, 2)
yearOfBirth = Right(fnDOB, 4)
'set day to one character
If dayOfBirth > 9 Then dayOfBirth = UCase(Chr(Val(dayOfBirth) + 55))

Build_PassKey = dayOfBirth & Hex(monthOfBirth) & yearOfBirth & Format(Replace(fnZipCode, Chr(32), ""), "000000")
End Function

'sub to reverse passkey
Public Sub Reverse_PassKey(ByVal fnPassKey As String)
Dim dayOfBirth As String, monthOfBirth As String, yearOfBirth As String, zLoop As Integer
'get initial data
dayOfBirth = Left(fnPassKey, 1)
monthOfBirth = Mid(fnPassKey, 2, 1)
yearOfBirth = Mid(fnPassKey, 3, 4)
'reverse day of birth
If Not IsNumeric(dayOfBirth) Then dayOfBirth = Asc(UCase(dayOfBirth)) - 55
'reverse DOB
strDateOfBirth = dayOfBirth & "/" & Str(monthOfBirth) & "/" & yearOfBirth
'reverse zip
strZipCode = Right(fnPassKey, 6)
For zLoop = 1 To 6
    If Left(strZipCode, 1) = "0" Then strZipCode = Right(strZipCode, Len(strZipCode) - zLoop)
Next zLoop
End Sub

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12579378
One correction in the sub to reverse :)

Public Sub Reverse_PassKey(ByVal fnPassKey As String)
Dim dayOfBirth As String, monthOfBirth As String, yearOfBirth As String, zLoop As Integer
'get initial data
dayOfBirth = Left(fnPassKey, 1)
monthOfBirth = Mid(fnPassKey, 2, 1)
yearOfBirth = Mid(fnPassKey, 3, 4)
'reverse day of birth
If Not IsNumeric(dayOfBirth) Then dayOfBirth = Asc(UCase(dayOfBirth)) - 55
'reverse DOB
strDateOfBirth = dayOfBirth & "/" & Val("&H" & monthOfBirth) & "/" & yearOfBirth   '<<< here the correction
'reverse zip
strZipCode = Right(fnPassKey, 6)
For zLoop = 1 To 6
    If Left(strZipCode, 1) = "0" Then strZipCode = Right(strZipCode, Len(strZipCode) - zLoop)
Next zLoop
End Sub

S

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question