|
|
Title | Tell in what state a Social Security Number was probably issued |
Keywords | load data, lookup data, Social Security Numbers |
Categories | Tips and Tricks |
|
|
When you enter three digits in the TextBox, its Change event handler calls the LookupSsnState function
to see what state probably issued Social Security Numbers starting with those digits.
LookupSsnState calls subroutine LoadRangeInfo to load data about the ranges issued by each state.
For a list of the data, go to the
Social Security Administration Web site.
The program stores information in an array of the user-defined type (UDT) RangeInfoType called
m_RangeInfo. The variable m_NumRangeInfo keeps track of the number of entries in the array.
Subroutine LoadRangeInfo checks m_NumRangeInfo to see if the data is already loaded. If it is,
the routine exits. If the data is not yet loaded, LoadRangeInfo calls LoadRangeInfoEntry
to create all the array entries.
|
|
Private Type RangeInfoType
MinSsn As Integer
MaxSsn As Integer
state As String
End Type
Private m_NumRangeInfo As Integer
Private m_RangeInfo() As RangeInfoType
' Load the information array.
Private Sub LoadRangeInfo()
' If it is already loaded, don't bother.
If m_NumRangeInfo > 0 Then Exit Sub
LoadRangeInfoEntry 1, 3, "New Hampshire"
LoadRangeInfoEntry 4, 7, "Maine"
' Lots of entries deleted ...
LoadRangeInfoEntry 700, 728, "Railroad Board"
End Sub
' Load an m_RangeInfo entry.
Private Sub LoadRangeInfoEntry(ByVal min_ssn As Integer, _
ByVal max_ssn As Integer, ByVal state As String)
m_NumRangeInfo = m_NumRangeInfo + 1
ReDim Preserve m_RangeInfo(1 To m_NumRangeInfo)
With m_RangeInfo(m_NumRangeInfo)
.MinSsn = min_ssn
.MaxSsn = max_ssn
.state = state
End With
End Sub
|
|
This technique can be useful for many applications that need to load lookup tables and
large arrays or collections of data. The routines that use the data call the XxxLoadData
subroutine. That routine determines whether the data has already been loaded and exits if
it has. If the data has not been loaded yet, the routine loads it.
This method has allows the program to initialize the data structure when it is first
needed. The usual alternative is to load all of the data when the program starts.
If the program has a lot of lists to load, that can slow the program down.
This technique also works well if the program needs to load lookup tables from a database.
It lets the program hit the database only when the data is needed instead of all at once when
the program starts.
|
|
|
|
|
|