PDA

Click to See Complete Forum and Search --> : To extract the first word from a text box


Caro
Dec 6th, 1999, 10:29 PM
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?

dmuir
Dec 6th, 1999, 10:41 PM
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

hayessj
Dec 6th, 1999, 10:45 PM
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

Ruchi
Dec 8th, 1999, 12:52 AM
Two text boxes. A command button.

Add the following 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