?
Solved

Creating a loop?

Posted on 2006-04-25
6
Medium Priority
?
186 Views
Last Modified: 2010-04-07
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
0
Comment
Question by:RedRado03
  • 3
  • 2
6 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 16535552
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
 
LVL 28

Assisted Solution

by:vinnyd79
vinnyd79 earned 1000 total points
ID: 16535568
Or Instr:

MyStr = "Mike : This is my name"

Text1.Text = Left$(MyStr, InStr(MyStr, ":") - 1)
Text1.Text = Mid$(MyStr, InStr(MyStr, ":") + 1)
0
 

Author Comment

by:RedRado03
ID: 16536369
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16536424
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 16536450
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16536471
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question