SuminO wrote: Fri Sep 20, 2019 12:45 pm
Function getTitle(thisFullName As String) As String
Dim Titles As Variant
Dim myCount As Integer
' สร้างตัวแปร Array ชื่อ Titles เพื่อเก็บคำนำหน้าชื่อ สามารถเพิ่มได้อีกไม่จำกัด
' ต้องให้ นางสาว มาก่อน นาง มิฉะนั้นจะตรวจสอบนางสาวไม่ได้
Titles = Array("นาย", "นางสาว", "นาง", "เด็กชาย", "ด.ช.", "ว่าที่ ร.ต.")
For myCount = 0 To UBound(Titles)
getTitle = Left(thisFullName, Len(Titles(myCount)))
If Titles(myCount) = getTitle Then
Exit Function
Else
getTitle = blank
End If
Next myCount
End Function
Function getFirstName(thisFullName As String) As String
Dim thisTitle As String
Dim firstName As String
Dim spacePos As Integer
thisTitle = getTitle(thisFullName)
spacePos = InStr(thisFullName, " ")
If spacePos = 0 Then 'ถ้าไม่มีช่องว่าง
firstName = Trim(Mid(thisFullName, Len(thisTitle) + 1, Len(thisFullName) - Len(thisTitle)))
Else
firstName = Trim(Mid(thisFullName, Len(thisTitle) + 1, InStr(thisFullName, " ") - Len(thisTitle)))
End If
getFirstName = firstName
End Function
Function getLastName(thisFullName As String) As String
Dim lastName As String
Dim spacePos As Integer
spacePos = nameAndTitle = InStr(thisFullName, " ")
If spacePos = 0 Then 'ถ้าไม่มีช่องว่าง แสดงว่าไม่มีนามสกุล
lastName = Trim(Mid(thisFullName, InStr(thisFullName, " "), Len(thisFullName)))
Else
lastName = blank
End If
getLastName = lastName
End Function