Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,572 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,926 people online right now. Registration is fast and FREE... Join Now!




how to display initials with string

 
Reply to this topicStart new topic

how to display initials with string

powellm
3 Apr, 2008 - 03:08 PM
Post #1

New D.I.C Head
*

Joined: 30 Mar, 2008
Posts: 20

I have an application where the user enters there first middle and last name and then the application needs to display a monogram with the first and middle initials in lowercase and the last initial in uppercase

vb

Option Explicit
Private Sub cmdDone_Click()
Unload frmMonogram
End Sub

Private Sub cmdMonogram_Click()
Dim strName As String
Dim intMiddlePosition As Integer
Dim intLastPosition As Integer

strName = txtName.Text
intMiddlePosition = InStr(1, Len(strName), " ") + 1
intLastPosition = InStr(1, Len(strName), " ") + 1

End Sub


for example the initials needing to be display as mJT

How do I get the initials to display as described above?

This post has been edited by PsychoCoder: 3 Apr, 2008 - 03:16 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Display Initials With String
3 Apr, 2008 - 03:28 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You have the hard part out of the way, finding the 2 spaces between the first, middle & last names. Now we just need to use the Mid() Function to extract what we're looking for.

To ensure the proper casing we will use LCase to convert to lower case, and UCase to convert to upper case. Something like:

vb

Private Sub cmdMonogram_Click()
Dim strName As String
Dim intMiddlePosition As Integer
Dim intLastPosition As Integer
Dim strFirstInitial As String
Dim strMiddleInitial As String
Dim strLastInitial As String

strName = txtName.Text
intMiddlePosition = InStr(1, Len(strName), " ") + 1
intLastPosition = InStr(1, Len(strName), " ") + 1

'Get the first initial (lower case) using Left()
strFirstInitial = LCase(Left(strName,1))
'Get the middle initial (lower case) using Mid()
strMiddleInitial = LCase(Mid(strName,intMiddlePosition,1))
'Get the last initial (upper case) using Mid()
strLastInitial = UCase(Mid(strName,intLastPosition,1))
End Sub


Hope that helps smile.gif
User is offlineProfile CardPM
+Quote Post

powellm
RE: How To Display Initials With String
3 Apr, 2008 - 03:50 PM
Post #3

New D.I.C Head
*

Joined: 30 Mar, 2008
Posts: 20

Thanks for the help

also when I do the line of code to make the last initial uppercase it returns the same initial as the middle initial



This post has been edited by powellm: 3 Apr, 2008 - 04:18 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Display Initials With String
3 Apr, 2008 - 04:04 PM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
No problem, glad I could help smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:59PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month