Visitor Database Program Walkthrough
Written By Fiebig

Let me preface this with a bit of an introduction. If you know me, you'll know that I am primarily a hardware geek, meaning that I find building circuits more enjoyable than building programs. However, during a recent period of revilation, a change of mind took place. I made the all too real discovery that, simply put, the industrial revolution is over. Now is the information revolution and we must adapt thusly. What does this mean? It means that anymore, we can't rely on hardware alone. To become a hardware geek one must necessarily become a software geek as well, lest one be left addled in the wake of an ever expanding world of HMI/MMI applications and sciences. The evolution of these sciences is clearly evident in the field of modern prosthetics. In the past, a prosthetic limb may have been anything from a wooden arm or leg to a plastic replacement controlled solely by physical actions of the user. With the advent of the information revolution, a prosthetic limb can be controlled by the brain, which is, in reality, in and of itself the most complex computer system known. Regardless, after my revilation, I began work on several projects which involved human interface, one of which you are seeing right now.



It is important to note that the magnetic strip reader which I am using intercepts the keyboard, inputting data as straight text. This is actually very nice because it does not require a special program to detrmine information on the card. I initially got this to just screw around with, but realized the potential when I swiped my driver's license and my name and address were among the data entered. I started playing around in VB, developing a simple program to parse out your name, city and state. At that point I began to get a litle more serious about it. I had already been messing around with accessing a webcam via VB during a failed attempt at producing facial recognition software. I threw some of the webcam code into my program, and then devised a final plan. "This would be perfect for conventions," I thought, and began to plan a simple UI which required a minimal ammount of actual human interface, while still producing an end result based completly on the user. I already knew that I could easily keep a program going after one small act of human interface (that, of course, being the user swiping his card) and from that point on my goal was to completly automate the program.

It is also important to note that within this program, I perform a lot of tasks which don't particularly need to be done. For example, I display the tracks as I break them up. There is a textbox for almost all stages of breaking up the code. For the same reason, I have a lot of variables, which in reality I wouldn't need. This is obviously not necessary. All of this could be done 'behind the scenes', but I wanted this program to inform, not just show off.

It begins of course, with the swipe of a driver's license. The program reads in the information stored on the magnetic strip (AKA the tracks), inputting it into a textbox. The program recognizes a complete set of data by looking for what is called the End Sentinel. All magnetic srtips have up to three tracks of information on them. These tracks are differentiated using characters to signify the start and end of the tracks called the Start Sentinel and the End Sentinel. The start sentinel for track one (usually '%') is different from the start sentinels for tracks two and three (usually ';'). The end sentinel is usually a consistant '?'. An example may look like this: %carddata?;carddata?.Since my track reader only handles tracks one and two, my program looks for the second end sentinel, signifying the end of all tracks of data (likewise, if my reader could handle three tracks, my program would have to look for the third end sentinel). Once the program knows that there is no more information being input, it disables the input box, and calls a function called 'parse', which I wrote to perform all the scrubbing on the information necessary.

First, the parse funcion looks for the Start Sentinel of track two. It then removes track two using substring.

trackOne = allTracks.Substring(0, allTracks.LastIndexOf(";"))

Next, the parse function creates a duplicate of track one and names it trackOneUseful (for lack of a better name...). Using a for loop, the name and address information are then parsed out by looking for carots. Like the start and end sentinels, carots signify a change in the data. In this case, carots are used to seperate fields of data. For example, within a track, there may be three fields (ie; state, name, address). This track of data would look like this: %state^name^address?.

For i = 0 To trackOneUseful.Length() - 1

  If trackOneUseful.Chars(i) = "^" Then
    carots = carots + 1
  End If

  If carots < 2 Then
    nameAddyRaw = nameAddyRaw + trackOneUseful.Chars(i)
  End If

Next i


The reason this code works is because on a driver's license, the order if data on track one is: state, city, name, address. The fields are broken up thusly: statecity^name^address. Therefore, by finding the second carot and using a substring to remove all data after the second carot, the result is: statecity^name.

Now we must seperate the city and state from the name. This is done simply enough using another substring.

addressRaw = nameAddyRaw.Substring(0, nameAddyRaw.LastIndexOf("^"))
nameRaw = nameAddyRaw.Substring(nameAddyRaw.LastIndexOf("^"), (nameAddyRaw.Length() - addressRaw.Length()))


Now that we have the 'raw' name, which looks like this: FIEBIG$MATTHEW$M, we need to fix it up. First I'd like to point out the new character we are seeing in the name. That is the '$'. As I mentioned earlier, a strip is broken up into tracks, which are seperated using your start and end sentinels. Within a track, there are fields which are broken up using carots. Now, within a field, different data is further broken up using dollar signs. Anyway, the name is broken up by my program in a way similar to how the full tracks were.

Dim addTo As String
addTo = "last"

For i = 0 To nameRaw.Length() - 1

  If (nameRaw.Chars(i) = "$" Or nameRaw.Chars(i) = " ") And addTo = "last" Then
    addTo = "first"
  ElseIf (nameRaw.Chars(i) = "$" Or nameRaw.Chars(i) = " ") And addTo = "first" Then
    addTo = ""
  Else
    Select Case addTo
      Case "last" : lname = lname + nameRaw.Chars(i)
      Case "first" : fname = fname + nameRaw.Chars(i)
    End Select
  End If

Next i

lname = Replace(lname, "$", "")
lname = Replace(lname, "^", "")
fname = Replace(fname, "$", "")
fname = Replace(fname, "^", "")
lname = StrConv(lname, vbProperCase)
fname = StrConv(fname, vbProperCase)


We have now scrubbed the name from 'FIEBIG$MATTHEW$M' to 'Matthew Fiebig'. On to the address scrubbing.

For i = 0 To addressRaw.Length() - 1
  If i = 0 Or i = 1 Then
    state = state + addressRaw.Chars(i)
  Else
    city = city + addressRaw.Chars(i)
  End If
Next i

state = StrConv(state, vbUpperCase)
city = StrConv(city, vbProperCase)