473,507 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InStr function Position Glitch

Dököll
2,364 Recognized Expert Top Contributor
Don't you just love debugginh!

Sent a note to Steve, and my professor on this one. Smile, Killer, you hinted the code may not work as flawlessly as stated. Again, make no mistake about it, Steve's help has made a lot of sense, and yours, and still intend to engrave all names responsible (credits due and given). Going forward, I wanted to debug before screaming at the top of my lungs. And at the risk of making this one a mouth full, I will post several fables to explain the likelihood of drilling a hole in my notebook:-)

My friends, "I can't seem to find the meaning of funky"... if you like progressive house music, you might have heard above track. Anyhoot, my position is lost in the mix:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim strGetWords As Long
  3. strGetWords = InStr(1, Text6(0).Text, " " & Text1.Text & " ", vbTextCompare)
  4. If strGetWords = 0 Then
  5. Text1.Text = "?"
  6. Else
  7. Text6(0).SetFocus
  8. Text6(0).SelStart = strGetWords
  9. Text6(0).SelLength = Len(Text1.Text)
  10. End If
  11.  
  12.  
What's the problem now?

Well I'll tell you...Let's go to commercial first...
Jan 13 '07 #1
11 1688
Dököll
2,364 Recognized Expert Top Contributor
Tonight VB 6.0 Forum, followed by "The Love Boat"...click, click, click, we're back:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim strGetWords As Long
  3. strGetWords = InStr(1, Text6(0).Text, " " & Text1.Text & " ", vbTextCompare)
  4. If strGetWords = 0 Then
  5. Text1.Text = "I get nothing here"
  6. Else
  7. Text6(0).SetFocus
  8. Text6(0).SelStart = strGetWords
  9. Text6(0).SelLength = Len(Text1.Text)
  10. End If
  11.  
  12.  
I get nada if the first position. Example:

"Wheels on the bus goes round and round"

When round is searched Text1.Text = "Round"

When Wheels searched Text1.Text = "I get nothing here"

Let's "analyze this" problem, shall we?
Jan 13 '07 #2
Dököll
2,364 Recognized Expert Top Contributor
I attempted to remove the " " $ and the & " " works just fine, and I do get Wheels, but I also get Wheels in "TheWheels", sounds familiar:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim strGetWords As Long
  3. strGetWords = InStr(1, Text6(0).Text, Text1.Text, vbTextCompare)
  4. If strGetWords = 0 Then
  5. Text1.Text = "Wheels"  Got this from TheWheels
  6. Else
  7. Text6(0).SetFocus
  8. Text6(0).SelStart = strGetWords
  9. Text6(0).SelLength = Len(Text1.Text)
  10. End If
  11.  
  12. 'Text6(0).SelStart = strGetWords -1 did not do the trick
  13.  
  14.  
  15.  
Your turn, Killer, or anyone who sees clearly what I intend to achieve. Just emailed my VB professor about this, he's been out the game, last he wrote; this should spring some interest. Now Killer, your code gives me the same result, Wheels not picked up but round does. Though it rids punctuation just fine, I must have done something silly to it, I am comparing the modified version to your and will post it in a moment...

In a bit, and thanks for your support, and patience.

Dököll
Jan 13 '07 #3
Killer42
8,435 Recognized Expert Expert
You might want to try this slight modification to your code (I'll highlight the modified bit)...
Expand|Select|Wrap|Line Numbers
  1. Dim strGetWords As Long
  2. strGetWords = InStr(1, " " & Text6(0).Text & " ", " " & Text1.Text & " ", vbTextCompare)
  3. If strGetWords = 0 Then
  4.   Text1.Text = "I get nothing here"
  5. Else
  6.   Text6(0).SetFocus
  7.   Text6(0).SelStart = strGetWords
  8.   Text6(0).SelLength = Len(Text1.Text)
  9. End If
Jan 13 '07 #4
Dököll
2,364 Recognized Expert Top Contributor
Still attempting to diagnose Position Glitch in

Expand|Select|Wrap|Line Numbers
  1.  
  2. strGetWords = InStr(1, Text6(0).Text, " " & Text1.Text & " ", vbTextCompare) ...
  3.  
  4.  
Here is what I found out in your beautifully written code, Killer. It is now working and deals with positioning as suspected previously. It was not picking up the first word in "Wheels on the bus..." because of:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Text6(0).SelStart = P - 1' I get an invalid use of property  error
  3.  
  4.  
I commented it out Text6(0).SelStart = P - 1 and it works great. Now encountered another glitch. I decided t add the remaining text on the next line as in the below. I am now unable to find "and" but "so" does pop up:

The Wheels on the bus goes round (first line in Text6(0).Text)
and round, if so where...(second line in Text6(0).Text)

Any idea how to remedy this. You have a pretty good idea I amj sure, I simply can't see it:

Please see next posting, your function to fetch puntuation is apparently not working. I wonder if I've done something wrong, Again. The Module added to plug it in is called/and dot-noted " KillerSays.WordFoundInText", I now get an "argument not optional" error. I can't figure out how I made it work.

I am happy with it thus far, I am debugging, see what gives :-)
Jan 13 '07 #5
Dököll
2,364 Recognized Expert Top Contributor
Much appreciated response...

Thanks for adding your two-sense here: I get the same deal as in the previous:

The Wheels on the bus goes round (first line in Text6(0).Text)
and round, if so where...(second line in Text6(0).Text)

"and" is not picked up, "The" is:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim strGetWords As Long
  3. strGetWords = InStr(1, " " & Text6(0).Text & " ", " " & Text1.Text & " ", vbTextCompare)
  4. If strGetWords = 0 Then
  5. Text1.Text = "?" ' for 'and' I get ?
  6.  
  7.  
I will keep going...
Jan 13 '07 #6
MMcCarthy
14,534 Recognized Expert Moderator MVP
Just a quick note. Please don't put messages in the title. Just put a question description. This is because the titles are searched by google and the messages just make them harder to find.

Thanks

ADMIN
Jan 13 '07 #7
Dököll
2,364 Recognized Expert Top Contributor
Got it, thanks, Mary...
Still learning how this works.

Make it a great week-end!
Jan 13 '07 #8
Dököll
2,364 Recognized Expert Top Contributor
I guess this also involves punctuation, correct!
Jan 13 '07 #9
MMcCarthy
14,534 Recognized Expert Moderator MVP
Got it, thanks, Mary...
Still learning how this works.

Make it a great week-end!
You too Dokoll.

Thanks
Jan 13 '07 #10
Killer42
8,435 Recognized Expert Expert
If a line break is causing poroblem, just treat it like punctuation, and convert it to spaces. If you're dealing with individual characters, then you could search for vbCR and vbLF and replace each of them with a space. If number of characters isn't so important, just scan for vbNewLine or vbCRLF and replace with a space.

(This is all just in the temporary copy of the text for searching, of course - not the "real" text.)
Jan 13 '07 #11
Dököll
2,364 Recognized Expert Top Contributor
You read my mind, I was coming here to let you know I found out why the first word on the next line (second line) did not get picked up:

If Text is added in a multiline TextBox, at the end of line, the TextBox forces text to next line (as in text)...If I physically tab or hit enter the word/text typed in afterwards does not get picked. I am about to do exactly what you said; well really I thought add Chr(13), Chr(10) to the list, I have read or heard vbNewLine and vbCrLF runs with both, so this is pretty cool.

Have a good morning, and a great day, I'm tired now...Thanks.
Jan 14 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

5
309861
by: DTB | last post by:
I am trying to convert a complex function from Oracle to SQL Server and have come across Oracle's Instr() function. I see SQL Server has CHARINDEX() which is similar, however it does not provide...
1
25805
by: Icaro | last post by:
Hi everybody, I was looking for an equivalent ORACLE INSTR Function in MSSQL but I don´t found it and I don´t know if it exist so I must to write it and this is the code. Maybe it will be...
11
2983
by: Ted Mayett | last post by:
OK. Here is a glitch, sorry if this has been mentioned before. This is an erratic glitch. I am now up to three other people besides myself who have been able to see this glitch. It seems it...
3
72983
by: Fancy Pants | last post by:
Hi everyone, What is similar to the Instr function that is in ASP, in javascript? I am trying to search text boxes in a contact form, for certain characters. Justin
6
3992
by: Chris Calzaretta | last post by:
Hello Everybody, Question instr function will give you the first instance of the finding so EX: so your string looks like string1 = "testing>This is > just a test > testtesttest"...
4
3905
by: fischerspooner | last post by:
Hi, I'm banging my head against the desk because I can't find a solution for the following simple problem. Case: There is a column in a table that has FamilyName and FirstName(s) in one field....
12
2947
by: rodchar | last post by:
hey all, i'm getting a result that i don't understand i have a string "test1, test2" If InStr("test1") and InStr("test2") Then 'Inside EndIf The inside is not running for some reason. Any...
2
2178
by: Puneet Bhatnagar | last post by:
A textual comparison starting at position 4. Returns 6. MyPos = Instr(4, SearchString, SearchChar, 1) ' A binary comparison starting at position 1. Returns 9. MyPos = Instr(1, SearchString,...
6
2555
by: Brian | last post by:
what is the equivlant of the vb 6 instr I have a string there has "*D*N" I want to find the position that the D is in with a dotnet (VB) function
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.