Reads in the .key file as a parameter. Searches document for keyword, if found it search beside, below, and above for value. If no valid value is found, it moves on to the next keyword in the file. Code only checks IsNumber(80%) and IsFieldLengthMin(9).
<af name="Custom_SSNSearch" access="public" bInter="bInter" bDebug="bDebug" strParam="StrParam" >
<g>
<![CDATA[
Custom_SSNSearch = False
If (CurrentObj.ObjectType<>3) Then
Exit Function 'must be a field
End if
Dim keyArray
Dim sList
Dim ReadKeyFile
Dim sExtn
Dim foundKeyWord
Dim foundSSN
Dim foundNumber
Dim found
found = false
foundSSN = false
foundNumber = false
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const CreateNew = True, DoNotCreate = False
Const SysDefault = -2, OpenAsUnicode = -1, OpenAsASCII = 0
ReadKeyFile = ""
sExtn = ".key"
StrParam = Trim(StrParam)
If NOT Right(lcase(StrParam),4)=sExtn then
'Add the '.key' extension for file i/o compatibility
StrParam = StrParam & sExtn
End if
strPath = Pilot.ProjectPath
strProcessDir = FileMgr.GetParentFolderName(strPath) & "\"
sPathedParam = Trim(strProcessDir & strParam)
Set objFSO = CreateObject("Scripting.FileSystemObject")
if objFSO.FileExists(sPathedParam) then
Set oKeyFile = FileMgr.OpenTextFile(sPathedParam, ForReading, DoNotCreate, OpenAsASCII)
If oKeyFile.AtEndOfStream = False Then
sList = oKeyFile.ReadAll
Writelog("Opened and read key file: " & sPathedParam)
keyArray = Split(sList,vbCrLf)
End if
oKeyFile.Close
End If
For each x in keyArray
if x <> " " then
CurrentObj.Text = ""
Writelog("Looking for keyword: " & x)
found = WordFind(false,false,Trim(x))
if found then
Writelog("Found keyword: " & x & " now look beside it.")
Call GoRightWord(false,false,"1")
Call GroupNextWords(false,false,"1")
Call UpdateField(false,false)
foundNumber = IsNumber(false,false,"80")
foundSSN = IsFieldLengthMin(false,false,"9")
if foundNumber And foundSSN then
Writelog("Found a valid SSN beside the keyword.")
CurrentObj.Parent.Variable("FoundEmployeeSSN") = "True"
exit function
else
CurrentObj.Text = ""
Writelog("Found keyword: " & x & " now look below it.")
Call WordFind(false,false,Trim(x))
Call GoBelowWord(false,false,"1")
Call GroupNextWords(false,false,"1")
Call UpdateField(false,false)
foundNumber = IsNumber(false,false,"80")
foundSSN = IsFieldLengthMin(false,false,"9")
if foundNumber And foundSSN then
Writelog("Found a valid SSN below the keyword.")
CurrentObj.Parent.Variable("FoundEmployeeSSN") = "True"
exit function
else
CurrentObj.Text = ""
Writelog("Found keyword: " & x & " now look above it.")
Call WordFind(false,false,Trim(x))
Call GoAboveWord(false,false,"1")
Call GroupNextWords(false,false,"1")
Call UpdateField(false,false)
foundNumber = IsNumber(false,false,"80")
foundSSN = IsFieldLengthMin(false,false,"9")
if foundNumber And foundSSN then
Writelog("Found a valid SSN above the keyword.")
CurrentObj.Parent.Variable("FoundEmployeeSSN") = "True"
exit function
else
Writelog("Didn't find a valid SSN beside, below, or above the keyword. Move to next keyword.")
CurrentObj.Text = ""
end if
end if
end if
end if
end if
Next
]]></g></af>