"Field" function
A function in LotusScript that provides the equivalent functionality of the @WORD @Function.



Download: IT Certifications 101
Inside this exclusive essential guide, our independent experts break down which IT certifications are worth your time and effort, and how to get started obtaining them to further your career— including specific certifications that any cloud or desktop pro should seriously consider.
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
You also agree that your personal information may be transferred and processed in the United States, and that you have read and agree to the Terms of Use and the Privacy Policy.
A function in LotusScript that provides the equivalent functionality of the @WORD @Function.
Function Field(InputStr As String, DelimChr As String, PosNo As Integer) 'The DelimChr must be a single character or else function will return an error 'InputStr is a text string of any length that contains delimiters 'DelimChr must be a single text character used to delimit substrings (values) 'PosNo is a integer that indicates which value is to be returned MaxLen = Len(InputStr) ErrMsg = "" 'Check for various types of errors If PosNo < 1 Then ErrMsg = "Starting position < 1" Elseif DelimChr = "" Then ErrMsg = "Delimeter is null" Elseif Len(DelimChr) > 1 Then ErrMsg = "Delimeter is > 1 character" Elseif MaxLen < 1 Then Field = "" Exit Function 'No input string passed to function - just return an empty string - not considered an error End If If ErrMsg <> "" Then 'If there was error detected - display message and exit Msgbox "Error: Invalid parameter!" + Chr(13) + Chr(13) + ErrMsg,16,"Field Function" Field = "" Exit Function End If DelimCnt = 0 'Keeps track of how many delimiters were found StartSrchPos = 1 'Initialize where to start looking in the string StartDelimPos = 0 'Will hold the physical postion where the desired delimiter was found EndDelimPos = 0 'Will hold the physical position where the next delimiter was found For J = 1 To PosNo DelimPos = Instr(StartSrchPos,InputStr,DelimChr) If DelimPos > 0 Then 'Delimiter found in the sub- string DelimCnt = DelimCnt + 1 'Keep track of what number of delimiter this is If DelimCnt = PosNo - 1 Then StartDelimPos = DelimPos 'Keep going - not the right delimiter position Elseif DelimCnt = PosNo Then EndDelimPos = DelimPos Exit For 'Exit loop - the right delimiter position has been found End If StartSrchPos = DelimPos + 1 'The next search will begin just after the last delimiter was found Else Exit For 'Exit loop - no more delimiters found End If Next J If StartDelimPos > 0 And EndDelimPos > 0 Then If StartDelimPos+1 = EndDelimPos Then Field = "" Exit Function 'There is no gap between the two delimiter positions - return nothing End If End If If StartDelimPos > 0 Or EndDelimPos > 0 Then If EndDelimPos > 0 Then Field = Mid$(InputStr,StartDelimPos+1,EndDelimPos- (StartDelimPos+1)) 'Return those bytes between the 2 delimiter positions Else Field = Mid$(InputStr,StartDelimPos+1,MaxLen) 'No subsequent delimiter was found - return the remainder of the string End If Else 'If the input string doesn't contain a delimiter and the 1st occurrance was requested, just return the entire string else return nothing If PosNo = 1 And DelimCnt = 0 Then Field = InputStr Else Field = "" End If End Function
Start the conversation
0 comments