Results 1 to 4 of 4

Thread: To extract the first word from a text box

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 1999
    Location
    Littlehampton, W Sussex GB
    Posts
    203

    Post

    I need to extract the first word from data in a text box (up to the first space) to use in an sql statement. What is the best way to do this?

  2. #2
    Junior Member
    Join Date
    Nov 1999
    Location
    Wellsburg, WV, USA
    Posts
    25

    Post

    Add a command button, a text box and try this code.

    Private Sub Command1_Click()
    Dim mytext As String
    Dim counter As Integer

    mytext = Text1.Text

    For counter = 1 To Len(Text1.Text)
    If Mid$(mytext, counter, 1) = " " Then
    GoTo NextPart
    End If
    Next counter

    NextPart:

    MsgBox "'" + Mid$(mytext, 1, counter - 1) + "'"

    End Sub


    Good Luck,
    dmuir

  3. #3
    Lively Member
    Join Date
    Dec 1999
    Posts
    106

    Post

    Try this...

    Dim sFirstWord As String
    Dim nPosition As Integer

    nPosition = InStr(1, Text1.Text, " ")
    If nPosition <> 0 Then
    sFirstWord = Left(Text1.Text, nPosition)
    Else
    sFirstWord = Text1.Text
    End If
    MsgBox sFirstWord

  4. #4
    Member
    Join Date
    Dec 1999
    Posts
    37

    Post

    Two text boxes. A command button.

    Add the following code.

    Code:
    Private Sub Command1_Click()
        Dim sword As String
        Dim sspace As String
        sword = Trim$(Text2.Text)
        sspace = InStr(sword, " ")
        Text1.Text = Left$(sword, sspace - 1)
    End Sub

    Ruchi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width