Explain to me the point of this line of code
Our instructor created a function that outputs the first word of your full name.
Function FirstWord(ss As String, sp As String) As String '--Returns the first word of the string, separator space Dim Ws As String, p As Long Ws = Trim(ss) p = InStr(Ws, sp) If p = 0 Then p = Len(Ws) + 1 Ws = Trim(Left(Ws, p - 1)) Return Ws
Sure I know how it works, but what's the point of using this line of code?? :
If p = 0 Then p = Len(Ws) + 1
Maybe so it doesn't output the first letter, if so, then why did he added p + 1 in the above line then subtract it in the left() function? I deleted the +1 and the -1, it still output the first letter instead of nothing at all as it was meant to be. Why?
Thanks for your help.
0 comments:
Post a Comment