|
-
Nov 6th, 2000, 09:37 PM
#1
Thread Starter
New Member
I need to get a first name and last name from a textbox such as:
Whole$ = Text1.Text
Pos% = InStr (Whole$, " ")
FstName$ = Mid$(Whole$, Pos% + 1, InStr(Whole$, " ") - 1)
LstName$ = Mid$(Whole$, Len(FstName$) + 2, Len(Whole$) - 1)
I have to enter: -new johnnyboy nighty
-new is the command
johnnyboy is the first name
nighty is the last name
and I get:
FstName$ -- john
LstName$ -- johnnyboy nighty
Whats wrong?
P.S. I am sorry for posting so many messages in one day, but whenever a problem arises I can't seem to fix, there is no one I know that can help me.
-
Nov 6th, 2000, 09:52 PM
#2
Put it into an Array and search it that way.
Code:
Private Sub Command1_Click()
ArrayName = Split(Text1.Text, " ")
For i = 0 To UBound(ArrayName)
ArrName = ArrName & ArrayName(i) & vbCrLf
Next i
MsgBox ArrName
End Sub
-
Nov 6th, 2000, 10:09 PM
#3
_______
<?>
Code:
'better coding practice to declare your variables
'if you have VB6 you can do it this way.
'same idea as Matthew..just a little more explanatory
Option Explicit
Private Sub Command1_Click()
Dim sWhole As String, FstName As String
Dim LstName As String
Dim mySplit As Variant 'must always be a varian to hold a split
sWhole = Text1.Text
mySplit = Split(sWhole, " ")
'the 3 elements of the split
'mySplit(0) = new
FstName = mySplit(1)
LstName = mySplit(2)
MsgBox "First Name is " & FstName
MsgBox "Last Name is " & LstName
End Sub
Private Sub Form_Load()
Text1 = "new johnnyboy nightly"
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 6th, 2000, 10:17 PM
#4
Thread Starter
New Member
Thank you all. My program is working now. It was easier to split into a vector (array).
-
Nov 6th, 2000, 10:19 PM
#5
Did I forget to declare? Oops..
Code:
Dim ArrayName As Variant
Dim ArrName As String
Dim i As Integer
...I feel so much better now .
-
Nov 6th, 2000, 10:21 PM
#6
_______
<?>
Code:
'this is your way
Private Sub Command1_Click()
whole$ = Text1.Text
Pos% = InStr(whole$, " ")
whole = Right(whole, Len(whole) - Pos)
Pos% = InStr(whole$, " ")
LstName$ = Right(whole, Len(whole) - Pos)
whole = Left(whole, Pos)
FstName$ = whole
MsgBox FstName
MsgBox LstName
End Sub
Private Sub Form_Load()
Text1 = "new johnnyboy nightly"
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|