Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String extraction 3

Status
Not open for further replies.

henio

MIS
Jun 25, 2003
60
0
0
GB
Hi,

I have this code to initialise a label on a splash screen.

Private Sub UserForm_Initialize()
Label1.Caption = Environ("username")
End Sub

This can give me fred.flintstone or barney.rubble (says something aabout where I'm working!).

How can I extract the first name?

Cheers,
Henio
 
Hi,

Could do it with a function
Code:
Function UserName(sName, bFirst)
   n = InStr(sName, ".")
    If bFirst Then
        UserName = Left(sName, n - 1)
    Else
        UserName = Right(sName, Len(sName) - n)
    End If
End Function
:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Use

Left("fred.flinstone",InStr(1,"fred.flintsone","."))
 
BTW,

to use UserName
Code:
sName = "fred.flintstone"
sFirstName = UserName(sName, True)
sLastName = UserName(sName, False)




Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Or for office versions higher than 97:

Label1.Caption = Split(Environ("username"), ".")(0)

combo
 
Hi,

Thanks to all of you for replying. I tried Combo's solution first so s(he) gets my star.

There seem to be so many ways of doing anything - I need to buy a good VBA book...

Cheers

Henio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top