473,394 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Left$ Function, Looping through: This is a mouth full. Vol 2

Dököll
2,364 Expert 2GB
Here it goes again, thanks again for responding:

'PROPOSED SOLUTION 2
'I wanted to not creatre a file and just read straight out of Text6.Text and
'output my findings in legal text boxes
'I also needed/had to, because OF LACK OF EXPERIENCE, figure out wheter 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 problem, I searched 'use' by adding it to Text3.Text
'Text3.Text attempt to search below text and Text1.Text 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 do not see what the problem is here, STUBBORN BEAST, don't you think!
'Anyway, I found use in because, can you believe this?


Here are some instructions, not previously added:

(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


Expand|Select|Wrap|Line Numbers
  1. Private Sub strGetWordsTEXT1_Click()  'Button to search Text6.Text data
  2.  
  3.  
  4. Dim strGetWords, strFromThis  ' strGetWords finds the words from strFromThis
  5.  
  6.  
  7. strGetWords = LCase(Left$(Text3.Text, 3))  'my trick did not work here
  8.  
  9.  
  10. strFromThis = InStr(Text6.Text, strGetWords)
  11.  
  12.  
  13. If strFromThis Then
  14.   Text6.SetFocus
  15.   Text6.SelText = Left$(Text3.Text, 3) 'this is not helpng either
  16.   Text6.SelStart = strFromThis - 1  'starts me off pretty good, but to no avail
  17.   'I took this out and got and an additional 3 character
  18.   Text6.SelLength = Len(strGetWords)    
  19. 'use was found, therefore Len record 3 chars, still weak
  20.   End If
  21.  
  22.  
  23. Text1.Text = Text6.SelLength = Len(strGetWords) ' we covered this already
  24.  
  25.  
  26.  
  27. If Text1.Text = True Then 
  28. 'use found therefore give priority to Text2.Text
  29.  
  30. Text2.Text = strGetWords 'Text2.Text carries use, since Text1.Text is True
  31.  
  32. ElseIf Text1.Text = False Then
  33.  
  34. MsgBox "Oh lee Molee" 
  35.  
  36. 'this was merely for testing, just in case of a missplell in my word selection
  37. End If
  38. End Sub
  39.  
  40.  
What am I not doing to the code? If you've ever fet up against the wall...My son knows this as The Project, he's nice but I have a feeling he's growing impatient. I should be able to tell VB do this and it just does it, wouldn't you say. Many thanks, VB gang!
Jan 9 '07 #1
18 1757
Killer42
8,435 Expert 8TB
So, that word-matching function I wrote for you didn't solve the problem? (Sorry, I haven't seen the thread for a while.)

Is it still the word/string matching that you are stuck on? The message here was a bit overwhelming.
Jan 10 '07 #2
Killer42
8,435 Expert 8TB
I followed your instructions, and after adding As String to the Dim statement a couple of times (because I always use DefLng and Option Explicit - old habits) it runs. But it seems to have some strange effects.

If I paste "'Anyway, I found it in because, can you believe this" into Text6, put "use" in Text3 and hit the button, what should happen?

What does happen is that it places "use" in Text2, and "True" in Text1. It alsop, and this is the part I find odd, adds "use" onto the end of Text6. So it now contains "'Anyway, I found it in because, can you believe thisuse".

Is it just supposed to tell us whether the word "use" appears in the text? I'll throw together a modified version of the code to do this, but is it what you want?
Jan 10 '07 #3
Killer42
8,435 Expert 8TB
Here's a quickie which just checks whether the word exists in the text, but as I soon discovered, it doesn't make allowances for punctuation. (In other words, using the example quoted before, it can find the word believe but not because). Should be able to overcome that, but for the moment I have to get back to work.
Expand|Select|Wrap|Line Numbers
  1. Private Sub strGetWordsTEXT1_Click()  'Button to search Text6.Text data
  2.  
  3.   Text1.Text = ""
  4.   Text2.Text = ""
  5.   If WordFoundInText(Text3.Text, Text6.Text) Then
  6.     Text1.Text = "True"
  7.     Text2.Text = Text6.Text
  8.   End If
  9.  
  10. End Sub
  11.  
  12. Private Function WordFoundInText(ByVal Word As String, ByVal Text As String) As Boolean
  13.   Word = UCase$(Trim$(Word))
  14.   Text = UCase$(Trim$(Text))
  15.   If Text Like Word & " *" _
  16.   Or Text Like "* " & Word & " *" _
  17.   Or Text Like "* " & Word Then
  18.     WordFoundInText = True
  19.   End If
  20. End Function
Jan 10 '07 #4
Dököll
2,364 Expert 2GB
You're a gentleman and scholar, Killer, nice to hear from you. Yes you are correct, use is again added in.

If you delete/comment out: Text6.SelText = Left$(Text3.Text, 3) you will not get the additional use.

Expand|Select|Wrap|Line Numbers
  1.  
  2. strFromThis = InStr(Text6.Text, strGetWords)
  3.  If strFromThis Then 
  4.  Text6.SetFocus 'keep focus in that Text box
  5.  'Text6.SelText = Left$(Text3.Text, 3) 'this did not help either
  6.  Text6.SelStart = strFromThis - 1 ...
  7.  
  8.  
This does not matter much, I think we've got it Killer. Today, the application is 15 percent done. The big idea is this, I simply wanted use to be found by itself, not connected to or associtated with anything (Because, useful, etc)...

Will's comment about vbTextCompare stuck, I just could not make it work

Expand|Select|Wrap|Line Numbers
  1.  
  2. If InStrB(strGetWord, "use", vbTextCompare) <> 0 Then
  3. this and that, gave me nothing
  4. End If
  5.  
  6.  
I revisited vbTextCompare after picking up an email from a friend, who said I would need a 1 up there, thus strGetWords as Long as opposed to String. A slight modification the code provided the below. Truth is both Textboxes should be compared to find one data from one in the other:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'The one that works...
  3.  
  4. Private Sub GtWords_Click()
  5. Dim strGetWords As Long
  6. strGetWords = InStr(1, Text6(0).Text, " " & Text1.Text & " ", vbTextCompare) 
  7. If strGetWords = 0 Then
  8. Text1.Text = "Steve says no way"
  9. Else
  10. Text6(0).SetFocus
  11. Text6(0).SelStart = strGetWords
  12. Text6(0).SelLength = Len(Text1.Text)
  13. End If
  14. End Sub
  15.  
  16.  
Steve's name, yours, Will's and everyone whose assistance and patience helped make this happen will be included in the credits, engraved my friends.

My turn to help :-)

In a bit!

Dököll
Jan 10 '07 #5
Killer42
8,435 Expert 8TB
I've got a version which I think works perfectly. I'm just leaving work now. When I get home I'll get rid of all the messy commented code and so on, and post it.

Then we'll find out whether I understood what it was supposed to do.
Jan 10 '07 #6
Killer42
8,435 Expert 8TB
I see from the other thread that you have things working. Oh well, since I wrote the code I might as well post it. Not that I'm complaining :D I love playing with this sort of thing, when I can find the time.

(Are you sure you got exactly what you want out of your code?)

Anyway, here's my version which scans the entered text for the entered word. Looks for full word only, but should work regardless of upper/lower case, and punctuation. (Note, this is all of the code in my project - it's fairly simple.)
Expand|Select|Wrap|Line Numbers
  1. ' In the form... 
  2. Option Explicit
  3. DefLng A-Z
  4. Private Sub strGetWordsTEXT1_Click()  'Button to search Text6.Text data
  5.   Dim P As Long
  6.   Text1.Text = ""
  7.   Text2.Text = ""
  8.   P = WordFoundInText(Text3.Text, Text6.Text)
  9.   If P Then
  10.     Text1.Text = "True"
  11.     Text2.Text = Text3.Text
  12.     Text6.SelStart = P - 1
  13.     Text6.SelLength = Len(Text3.Text)
  14.     Text6.SetFocus
  15.   End If
  16. End Sub
  17.  
  18. ' In a separate module (in case you want to use it anywhere else)...
  19. Option Explicit
  20. DefLng A-Z
  21.  
  22. Private Const AllPunctuation As String = "!.,?:"""
  23.  
  24. Public Function WordFoundInText(ByVal Word As String, ByVal Text As String) As Long
  25.  
  26.   If Text = "" Or Word = "" Then
  27.     Exit Function
  28.   End If
  29.  
  30.   ' Standardise the text format.
  31.   Word = UCase$(Trim$(Word))
  32.   Text = " " & UCase$(Trim$(Text)) & " "
  33.  
  34.   ' Remove specified punctuation before testing.
  35.   Dim Char As String * 1, L As Long, I As Long
  36.   L = Len(Text)
  37.   For I = 1 To L
  38.     Char = Mid$(Text, I, 1)
  39.     If InStr(AllPunctuation, Char) Then
  40.       Mid$(Text, I, 1) = " "
  41.     End If
  42.   Next
  43.  
  44.   ' Scan for word anywhere in text.
  45.   'If Text Like "* " & Word & " *" Then
  46.   '  WordFoundInText = True
  47.   'End If
  48.  
  49.   ' Scan for word anywhere in text., return position.
  50.   WordFoundInText = InStr(Text, " " & Word & " ")
  51.  
  52. End Function
It's only had a very quick test, of course.
Jan 10 '07 #7
Dököll
2,364 Expert 2GB
Great looking code, you got there...Funny you worked out a punctuation find, Steve mentioned the likelihood of having to do that, I'll strip your code, see what I can get....

But Yes, Vol 2 works flawlessly, again if the Text does not have single quotes as in, 'Jack's funny, but driven'. I have added a variable to help handle the quotes, or characters like them, mentioned this in previous reply to you:

Expand|Select|Wrap|Line Numbers
  1.  
  2. strGetWordsOO= Asc("Apple")
  3.  
  4.  
I get what I want everytime:-)

Now, here is something I hve been toying with. For the time, I am using this to clear my TextBoxes, namely Text1, Text2, and Text6. What if I wanted to to loop through the Text added in Text6, and output words found to Text1, Text2:

[code]

Private Sub TextBeGone()

For t = 0 To Text1().UBound

Text1(t).Text = "" 'this handles both Text6, Text2, Text1, for now anyway

Next

End Sub

[code]

For the the Time being, I have Form_Load handle Text into the Text1, Text2 in order to search Text6 input and it works fine. What if I wanted to be fancy?
Jan 11 '07 #8
Dököll
2,364 Expert 2GB
Killer, Papa was RollingStone! Tae-nae-nae, nae-nae, tuduhh, weeerrrgreee!!! That's guitar, by the way...

Fun, fu-huuunn, what joy to read this code again. Son's now asleep. Sooweeet, Killer. I think I woke up the beast. Works wonders, I wanted to leave my variable in there since:

Expand|Select|Wrap|Line Numbers
  1.  
  2. strGetWordsOO=Asc("Apple's") ' still gives me 65, thus true for Text1
  3.  
  4.  
But ladies and gentlemen, I think we can save ourselves some trouble typing alot of Ascs to get 'Jack Apple's looney bin', not so looney, since no longer a full moon, hee, hee... If this didn't make sense, you can forget about it 'cause it shouldn't, astronomy does this to me, proof I am happy. Great work!!!

Night night chief.

Dököll
Jan 11 '07 #9
Killer42
8,435 Expert 8TB
To quote the narrator in Kung Pow - Enter the Fist: I'll have some of whatever he's smokin'
Jan 11 '07 #10
Dököll
2,364 Expert 2GB
hey, we have another thing in common, love kung-fu, took karaté some a while back, ages ago it seems. I am not familiar with Kung Pow, it sounded like the meal Kung Pao (love it lots); my boss actually is chinese, he jokes about the food, not having the same taste, does not know Kung-fu but he seems to like Jackie Chan, not sure if there's a g in there. I like Bruce Lee, saw every film. At the risk of boring you with details though, I think end it with this, Kung-fu as I new it is coming back, there's a new Jet film coming out, must see. Time to get into coding wife's asleep. In a bit!
Jan 11 '07 #11
Dököll
2,364 Expert 2GB
Here's an idea!

Should anyone need to use a software as dictionary, which is what I started calling my, at least what it used to be 'DICTIONARYMODEL-2-30AM-WORKS... it's a lot longer than this. Anyay, my code can just pick up anything in the clear blue sky anyway. I say psot it, perhaps someone wants to teach French, or English if you're French, Polish, you name it. Have VB grab whatever and translate to whatever:

Expand|Select|Wrap|Line Numbers
  1.  
  2. If InStrB(strGetWords, "Rain") <> = 0 Then
  3. MyTextBox.Text1(0).Text = "Rain"
  4. End If
  5.  
  6.  
As you have read in previous postings, this would also pick up Rain from Grain, Brain, if we have the wonderful LCase in there, as you said to allow anything R, r to come through. I'll just bet it could work just right. Imagine it:

Expand|Select|Wrap|Line Numbers
  1.  
  2. If InStrB(strGetWords, "Oh la la!") <> = 0 Then
  3. MyTextBox.Text1(0).Text = "Oh lee smokes"
  4. Else
  5. MyTextBox.Text1(0).Text = "Holy smokes" ' just for fun
  6. End If
  7.  
  8.  
We'll call this Part on of this project. I am going to go noodle with this one too I think, why not, right!
Jan 11 '07 #12
Dököll
2,364 Expert 2GB
VB does not like Italic, have you ever heard of this?
Jan 12 '07 #13
Killer42
8,435 Expert 8TB
VB does not like Italic, have you ever heard of this?
Can you explain what you mean?

(If you copied code from here it should be alright, unless you coped from the Reply window. Then it might have the [i] tags around it, which would certainly upset VB if pasted there.)
Jan 12 '07 #14
Dököll
2,364 Expert 2GB
Must have thought you could read my mind :-)

I was itching to try the code with different Text formats, so I did with Italic. Testing before I go wild and have to go back in...

You should have seem my face when nothing popped up with the Text Italicized. So, immediately I reverted to regular Text and it works just fine; nothing huge really, my buddy can simply tell his folks add Text as regular. Nevertheless, at the risk of making more work for him, I searched Italic Text re: VB 6.0 in hopes to add a control somehow, now that it is still early in the going and I still have the muscle, anyway, nothing concrete popped up.

I wondered if such a thing exists as to forcing VB to grab Italic Text and convert to regular, I guess what UCase or LCase does to whatever format comes in. Is this possible? If not, it's fine, he's a nice guy he'll understand.

But what are your thoughts on that?
Jan 12 '07 #15
Killer42
8,435 Expert 8TB
I still don't understand. Where is it you're trying to place this "italic text"? "VB" is a very general term.
Jan 12 '07 #16
Dököll
2,364 Expert 2GB
Run this and take a look, please ignore the array in Text6, have it the way you want. Text6(0).Text (multiline=True) holds Text, in this case convert the text to Italic before adding it in, Text1.Text is the search box:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub GtWords_Click()
  3. Dim strGetWords As Long
  4. strGetWords = InStr(1, LCase(Text6(0).Text), " " & Text1.Text & " ", vbTextCompare)
  5. If strGetWords = 0 Then
  6. Text1.Text = "Oh no, not on my watch"
  7. Else
  8. Text6(0).SetFocus
  9. Text6(0).SelStart = strGetWords
  10. Text6(0).SelLength = Len(Text1.Text)
  11. End If
  12. End Sub
  13.  
  14.  
Plug in this Text, again convert to Italic before adding to Text6(0).Text:

Copy and Paste text (1) then hit GtWords

Band of the year, you should hear it to believe it. Mr Robinson was not at home at the time of the incident. Short movies, short films are not for short people. Watch out for those manhole covers, this woman almost fell in.

Search for band, or anything you want from above Text, see what happens. I am still running with the code, but like I said and because it is rather rare that Text will be italicized,m I wanted to see if VB can fix this or ignore it. I wonder if the umlaut over my name will be a problem, I hadn't yet checked it. I think I should...

In a bit.

Dököll
Jan 13 '07 #17
Killer42
8,435 Expert 8TB
I still don't get it. For a plain text box, text is just text. Formatting such as italic/bold is ignored. In fact I would have thought that the RichTextBox control is the only one where a term such as italic has any relevance at all.
Jan 13 '07 #18
Dököll
2,364 Expert 2GB
Silly me, please disregard this one, You are correct, again, my friend. Too many sleepless nights. I plugged Text not to find, that's why my search came up empty. Works whether Italic or not...
Jan 13 '07 #19

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

Similar topics

8
by: kaptain kernel | last post by:
i've got a while loop thats iterating through a text file and pumping the contents into a database. the file is quite large (over 150mb). the looping causes my CPU load to race up to 100 per...
2
by: Steven Burn | last post by:
..:: The Specs: MS Access 2000 (host charges extra for SQL/MySQL) MS Windows Server 2003 (prod) / MS XP SP1 (dev) ..:: The setup: The database has been setup with two tables; tblDownloads
1
by: Diva | last post by:
Hi, I have a data grid in my application. It has 20 rows and I have set the page size as 5. I have a Submit button on my form and when I click on Submit, I need to loop through the rows in the...
7
by: fasanay | last post by:
Hi everybody I have got the following PHP code which I am trying to convert to ASP any help will be appreciated...I have done most of it but I cant find a replace function for Unset in asp which...
7
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I...
14
by: Bryan Parkoff | last post by:
Do you know that current C++ Compiler limits to 64KB segments in source code? It is good news that Microsoft Visual C++ 2005 has expanded to 4GB segments in source code. 4GB segment is ideal for...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
22
Dököll
by: Dököll | last post by:
Hiya, Partners! I have been into it for 12 hours straight this week-end, my son is very unhappy. Looks like I am getting pretty close but need your help, Again. I will post my first...
10
by: Charlie Brown | last post by:
I am using something like the following function to loop through a recipe program I am working on. As I was writing it, I starting thinking this isn't going to work at all... but not I'm not so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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
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...
0
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...

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.