Small correction to Harry's
It was out by a little bit.
Code:
Label1.Caption = Mid(Text1.Text, InStrRev(Text1.Text, "\") + 1, Instr(Text1.Text, ".") - InStrRev(Text1.Text, "\") -1 )
HarryW's solution is a nice one line answer for you especially if the text is always going to be formatted correctly etc. Remember though, that filenames do not always have an extension so there may not be any dot in the name.
This alternative (and long winded) method will do the job but should not fail in any circumstance.
Code:
Option Explicit
Private Sub Command1_Click()
Label1.Caption = GetText(Text1)
End Sub
Public Function GetText(t As String) As String
' extracs text between the last "\" character and the first "." character following the first "\"
Dim firstDot As Integer
Dim lastSlash As Integer
'get the last slash
lastSlash = InStrRev(t, "\")
If lastSlash = 0 Or lastSlash = Len(t) Then
' there are no slashes at all or the last slash
' is at the end of the string so bail out
Exit Function
End If
' get the first dot after the last slash
firstDot = InStrRev(Mid(t, lastSlash + 1), ".")
If firstDot = 0 Then
GetText = Mid(t, lastSlash + 1, Len(t) - 1 - lastSlash)
Else
GetText = Mid(t, lastSlash + 1, firstDot - 1)
End If
End Function
Cheers