Creating a loop?

How can I write a loop if I want to display only certain characters of a selection?

If my selection is:

Mike : This is my name

Need to seperate the word Mike to put in a textbox and
put This is my name in a seperate textbox.

I need to leave out the colon.

Mike
RedRado03Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinnyd79Commented:
You can use the split function:

MyStr = "Mike : This is my name"

Dim arrStr() as string
arrStr = Split(MyStr,":")
Text1.Text = arrStr(0)
Text2.Text = arrStr(1)

0
vinnyd79Commented:
Or Instr:

MyStr = "Mike : This is my name"

Text1.Text = Left$(MyStr, InStr(MyStr, ":") - 1)
Text1.Text = Mid$(MyStr, InStr(MyStr, ":") + 1)
0
RedRado03Author Commented:
Almost there.  The Mid$ statement works but I am getting an error with the Left$.

Public Property Left() As Iteger' has no parameters and its return type cannot be indexed.
Type character '$' does not match declared data type 'Integer'.

any ideas?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Are you using VB.Net?

        Dim str As String = "Mike : This is my name"
        Dim colon As Integer = str.IndexOf(":")
        If colon <> -1 Then
            Dim a As String = str.Substring(0, colon).Trim
            Dim b As String = str.Substring(colon + 1).Trim
            MsgBox(a & vbCrLf & b)
        End If
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
The VB.Net Split():

        Dim str As String = "Mike : This is my name"
        Dim parts() As String = str.Split(":".ToCharArray)
        Dim a As String = parts(0).Trim
        Dim b As String = parts(1).Trim
        MsgBox(a & vbCrLf & b)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonMiddle School Assistant TeacherCommented:
Or using the VB6 legacy string functions in VB.Net:

        Dim str As String = "Mike : This is my name"
        Dim a As String = Microsoft.VisualBasic.Left(str, Microsoft.VisualBasic.InStr(str, ":") - 2)
        Dim b As String = Microsoft.VisualBasic.Mid(str, Microsoft.VisualBasic.InStr(str, ":") + 2)
        MsgBox(a & vbCrLf & b)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.