Function Tachhoten(ByVal hovaten As String, n As String) As String
Dim space_left As Integer
Dim space_right As Integer
If hovaten = vbNullString Then GoTo endfunc:
hovaten = Trim(hovaten)
space_left = InStr(hovaten, " ")
space_right = InStrRev(hovaten, " ")
If space_left < 0 Or space_left - 1 < 0 Or space_left + 1 > Len(hovaten) Or space_right < 0 Or _
space_right - 1 < 0 Or space_right + 1 > Len(hovaten) Then GoTo endfunc:
Select Case n
Case "ho"
Tachhoten = Left(hovaten, space_left - 1)
Case "dem"
If space_right < space_left + 1 Then GoTo endfunc:
Tachhoten = Mid(hovaten, space_left + 1, space_right - space_left - 1)
Case "ten"
Tachhoten = Mid(hovaten, space_right + 1)
Case Else
MsgBox ("Chi nhap vao cac gia tri 'ho', 'dem', 'ten'." & vbNewLine & "Hay nhap lai du lieu")
GoTo endfunc:
End Select
endfunc:
End Function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment