Left$ Function, not selecting left: PLEASE HELP :-)

Left$ Function, not selecting left: PLEASE HELP :-)

Post by Mle » Tue, 09 Jan 2007 19:54:08


I am up early, Again, hi VB partners!

I need to read text from a large textbox and to output what I tell VB
to individual textboxes. The code is working and it is selecting the
text told "use' as one example. The problem is VB is selecting the
wrong chars, and I can't seem to find where I failed:

'I wanted to not create a file and just read straight out of Text6.Text
(my large textbox) and
'output my findings in legal textboxes (Text2.Text and so on...)
'I also needed/had to, because OF LACK OF EXPERIENCE, figure out
whether
my finding was true first
'before outputting, thus Text1.Text = Text6.SelLength =
Len(strGetWords) was born
'when true, Text2.Text = strGetWords

I searched 'use' by adding it to Text3.Text
'Text3.Text attempts to search below text and Text1.Text (My dummy
Textbox) will only be true if 'use' actually exists
'It does, my friends, but in the wrong position, I told VB,
Left$(Text3.Text, 3)

I found 'use' in becaUSE, can you believe this?

Here is the Text I plugged in:

'I also needed/had to, because OF LACK OF EXPERIENCE, figure out
whether
my finding was true first
'before out putting, thus Text1.Text = Text6.SelLength =
Len(strGetWords) was born
'when true, Text2.Text = strGetWords


Here is the code:


Private Sub strGetWordsTEXT1_Click() 'Button to search Text6.Text (My
large textbox) data
Dim strGetWords, strFromThis ' strGetWords finds the words from
strFromThis
strGetWords = LCase(Left$(Text3.Text, 3)) 'my trick did not work here,
tried to force it :-)
strFromThis = InStr(Text6.Text, strGetWords)
If strFromThis Then 'if there is any text at all
Text6.SetFocus 'keep focus in Text6
Text6.SelText = Left$(Text3.Text, 3) 'select the word I need, this is
not helpng either
Text6.SelStart = strFromThis - 1 'starts me off pretty good, but to
no avail, again
'I took this out and got and an additional 3 character becauseuse
Text6.SelLength = Len(strGetWords) 'use was found, therefore Len
record 3 chars, still weak
End If
Text1.Text = Text6.SelLength = Len(strGetWords) ' Text1 will tell me
if use was found, thus True
If Text1.Text = True Then 'use found therefore give priority to
Text2.Text
Text2.Text = strGetWords 'Text2.Text use, since Text1.Text is True
ElseIf Text1.Text = False Then
MsgBox "Oh lee Molee" 'this was merely for testing, just in case of a
missplell in my word selection
End If
End Sub

'There you have it, I am stuck, my son is unhappy for the amount of
time spent on here, Please help!

Thank for putting this group together...

Mles
 
 
 

Left$ Function, not selecting left: PLEASE HELP :-)

Post by Desserte » Tue, 09 Jan 2007 23:52:47


"Mles" < XXXX@XXXXX.COM > skrev i en meddelelse

I am up early, Again, hi VB partners!

I need to read text from a large textbox and to output what I tell VB
to individual textboxes. The code is working and it is selecting the
text told "use' as one example. The problem is VB is selecting the
wrong chars, and I can't seem to find where I failed:

'I wanted to not create a file and just read straight out of Text6.Text
(my large textbox) and
'output my findings in legal textboxes (Text2.Text and so on...)
'I also needed/had to, because OF LACK OF EXPERIENCE, figure out
whether
my finding was true first
'before outputting, thus Text1.Text = Text6.SelLength =
Len(strGetWords) was born
'when true, Text2.Text = strGetWords

I searched 'use' by adding it to Text3.Text
'Text3.Text attempts to search below text and Text1.Text (My dummy
Textbox) will only be true if 'use' actually exists
'It does, my friends, but in the wrong position, I told VB,
Left$(Text3.Text, 3)

I found 'use' in becaUSE, can you believe this?

Here is the Text I plugged in:

'I also needed/had to, because OF LACK OF EXPERIENCE, figure out
whether
my finding was true first
'before out putting, thus Text1.Text = Text6.SelLength =
Len(strGetWords) was born
'when true, Text2.Text = strGetWords


Here is the code:


Private Sub strGetWordsTEXT1_Click() 'Button to search Text6.Text (My
large textbox) data
Dim strGetWords, strFromThis ' strGetWords finds the words from
strFromThis
strGetWords = LCase(Left$(Text3.Text, 3)) 'my trick did not work here,
tried to force it :-)
strFromThis = InStr(Text6.Text, strGetWords)
If strFromThis Then 'if there is any text at all
Text6.SetFocus 'keep focus in Text6
Text6.SelText = Left$(Text3.Text, 3) 'select the word I need, this is
not helpng either
Text6.SelStart = strFromThis - 1 'starts me off pretty good, but to
no avail, again
'I took this out and got and an additional 3 character becauseuse
Text6.SelLength = Len(strGetWords) 'use was found, therefore Len
record 3 chars, still weak
End If
Text1.Text = Text6.SelLength = Len(strGetWords) ' Text1 will tell me
if use was found, thus True
If Text1.Text = True Then 'use found therefore give priority to
Text2.Text
Text2.Text = strGetWords 'Text2.Text use, since Text1.Text is True
ElseIf Text1.Text = False Then
MsgBox "Oh lee Molee" 'this was merely for testing, just in case of a
missplell in my word selection
End If
End Sub


Don't understand a word of your code.... but anyway, it seems you need to
use mid$ instead of left$........with mid$ you can pick any number of
characters from any place in a string or text1.text ............use instr to
find the position of your "search" string and mid$ to pick it out anyway you
like..........hope I understod a litlle bit anyway

 
 
 

Left$ Function, not selecting left: PLEASE HELP :-)

Post by Mle » Wed, 10 Jan 2007 08:41:42

My apologies Desserten. Thanks for your reply. I am cleaning it up


(1)Please make up a form with 3 TextBoxes, name them Text6, Text3,
Text2, Text1,
and one command button, name it strGetWordsTEXT1 or you can do
whatever you want

(2)Text6 is set True for multiline, this is where text is added

(3)Text3 is your search box, the word 'use' will be added there

(4)Text2 will carry the word found, use will be visible after you run
the code

(5)Text1 is a dummy, it holds either True or false. If use is found in
Text6, it is true, if not, False

(6)Plug in Text below in your Text6

(7)Add use in your Text3

(8)Hit your strGetWordsTEXT1 command button


Here is the text:

I also needed/had to, because OF LACK OF EXPERIENCE, figure out wheter
my finding was true first.
You will find that use is picked up in because. I need VB to only Pick
up use if it is by itself


Here is the code:

Private Sub strGetWordsTEXT1_Click()
'Button to search Text6.Text (My large textbox) data

Dim strGetWords, strFromThis

strGetWords = LCase(Left$(Text3.Text, 3))


strFromThis = InStr(Text6.Text, strGetWords)

If strFromThis Then
Text6.SetFocus
Text6.SelText = Left$(Text3.Text, 3)
Text6.SelStart = strFromThis - 1
Text6.SelLength = Len(strGetWords)
End If

Text1.Text = Text6.SelLength = Len(strGetWords)

If Text1.Text = True Then
Text2.Text = strGetWords
ElseIf Text1.Text = False Then
MsgBox "Oh lee Molee"
End If
End Sub



I am not sure how Mid$ will work if Left$ is grabbing the extreme right
of the text. What do you see happening?

Have a great night, Desserten...

Mles
 
 
 

Left$ Function, not selecting left: PLEASE HELP :-)

Post by Steve Gerr » Wed, 10 Jan 2007 16:01:25


First of all, the Left$ function does not tell VB to find the word "use" at the
left end of a word.
All it does is assign the first 3 letters of Text3.Text to your variable named
strGetWords, so that strGetWords = "use".
So that is not going to help.

Start with a simplified version of your code, where Text1 is for entering the
word to search for, and Text2 is a multiline box for the text.
Then you can write:

Private Sub Command1_Click()
Dim nPosition As Long

nPosition = InStr(1, Text2.Text, Text1.Text, vbTextCompare)

If nPosition = 0 Then
Text1.Text = "?"
Else
Text2.SetFocus
Text2.SelStart = nPosition - 1
Text2.SelLength = Len(Text1.Text)
End If

End Sub

As you have noticed, this will find the letters "use" in the word "because", and
highlight them.

If you want to find whole words, then you will have to do some more work, and
decide what makes a whole word. You will need to test each location found by
InStr to see if the word is a whole word or part of another word.

A simple way might be to find the word with a space before it and after it. This
won't work for punctuation, however, but it will get you started.

Private Sub Command1_Click()
Dim nPosition As Long

nPosition = InStr(1, Text2.Text, " " & Text1.Text & " ", vbTextCompare)

If nPosition = 0 Then
Text1.Text = "?"
Else
Text2.SetFocus
Text2.SelStart = nPosition
Text2.SelLength = Len(Text1.Text)
End If

End Sub
 
 
 

Left$ Function, not selecting left: PLEASE HELP :-)

Post by Mle » Wed, 10 Jan 2007 17:13:35

Steve,

Much appreciated, quick response...

I will toy around with the code, Steve, perhaps that'll get us
somewhere as far punctuation. But barring any unforseen issues, your
example should work just fine. I was once referred to vbTextComapre.
I think I wrote it wrong, and it did not work:

If InStrB(strGetWords, "use", vbTextComapre) <> 0 Then
this and that here...

End If.

I know why it was not working right. I need to also set exact position
or location. I was under the impression Left$ would have done it.
Anyway, Excellent...Let's give this one a whirl, thanks, Steve.

Mles