By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,557 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,557 IT Pros & Developers. It's quick & easy.

Looks like a wildcard would work: Any ideas VB 6.0 VS Access

Dököll
Expert 100+
P: 2,364
Greetings Again, All!

I know a bit more of the back end of things than front. Every now and then I use wildcard to retrieve data via sql advantage, oracle, and of course, our beloved MS Access ;-) I can't seem to find a wild card that will work in VB 6.
in spl advantage Ic an ue a 'Sam%' to find all Sam(s) and '%Sam' for Sam like, Example Samuel would show up here. Is there such a thing in VB 6, recent searches and reading hve come up empty, VB in "twenty one days" is useless; any ideas!

Dököll
Nov 26 '06 #1
Share this Question
Share on Google+
21 Replies


Dököll
Expert 100+
P: 2,364
Greetings Again, All!

I know a bit more of the back end of things than front. Every now and then I use wildcard to retrieve data via sql advantage, oracle, and of course, our beloved MS Access ;-) I can't seem to find a wild card that will work in VB 6.
in spl advantage Ic an ue a 'Sam%' to find all Sam(s) and '%Sam' for Sam like, Example Samuel would show up here. Is there such a thing in VB 6, recent searches and reading hve come up empty, VB in "twenty one days" is useless; any ideas!

Dököll
For got to post what I hd in mind, let's say it were:

Expand|Select|Wrap|Line Numbers
  1. Dim GoSplit As Variant
  2. Dim strGetWords As String
  3.  
  4. FileName = "\usermate.txt"
  5. f = FreeFile
  6. Open App.Path + FileName For Input As 1
  7. Do While Not EOF(f)
  8. Line Input #1, strGetWords
  9. GoSplit = Split(strGetWords, " ")
  10.  
  11. If strGetWords$ like "bus" <> 0 Then  '  want bus but I also get bus from busted
  12. 'Is there anything to add here that would make only the instance of bus to pop up
  13.  
  14. 'Adding asterisk as in "bus*" give me nada, not a thing...
  15.  
  16. Text4(8).Text = "bus"
  17. End If
  18.  
  19. 'What I hope to do make sure "busted" is not picked up since "bus" gets picked up from "busted"
  20.  
  21. I am posting this because I did find a solution.  If you recall, I decided to set visibility to false for the text bx that would have carried "bus" if "busted" was found.  The problem is I had an error 'procedure too large, proof that my if statement was out of this world.  A wildcard woul greatly reduce my risks, I do not appreciate that pop up too much "Procedure Too LARGE!" what is that?
  22.  
  23. What are yur thoughts on this?
  24.  
  25. Dököll
  26.  
  27.  
Nov 26 '06 #2

Expert 5K+
P: 8,434
You should check the online help for the Like operator, but I think you'll find the asterisk (*) is the wildcard character you're after.
Nov 26 '06 #3

Dököll
Expert 100+
P: 2,364
You should check the online help for the Like operator, but I think you'll find the asterisk (*) is the wildcard character you're after.
I'll give it a whirl, many thanks...I'm surprised 'help' included with thr software did no provide much assistance. Will let you know...
Nov 26 '06 #4

Dököll
Expert 100+
P: 2,364
I think I figured out why (*) as wildcard is not working through VB 6.0 Professional. Checked Knowledge base, my attempt is to grab what I want from a .txt file where text (lyrical conten) would be temporarily stored. VB does give me the option to use the Like operator but to retrieve from an access database (Recordset) or other. I should have been more specific (VB 6.0 Vs .txt file). I will shrink the code in hopes that'll do the trick. Thanks for your support and assistance. I'll post my findings here when found, should help us tackle this mistery...

Dököll
Nov 26 '06 #5

Expert 5K+
P: 8,434
According to the doco...
Like Operator Example
This example uses the Like operator to compare a string to a pattern.
Expand|Select|Wrap|Line Numbers
  1. Dim MyCheck
  2. MyCheck = "aBBBa" Like "a*a"   ' Returns True.
  3. MyCheck = "F" Like "[A-Z]"     ' Returns True.
  4. MyCheck = "F" Like "[!A-Z]"    ' Returns False.
  5. MyCheck = "a2a" Like "a#a"     ' Returns True.
  6. MyCheck = "aM5b" Like "a[L-P]#[!c-e]"  ' Returns True.
  7. MyCheck = "BAT123khg" Like "B?T*"      ' Returns True.
  8. MyCheck = "CAT123khg" Like "B?T*"      ' Returns False.
I've just tested the second example in plain VB6, and it worked. I found that when looking it up in the MSDN doco, it had two entries - VB and VBA. As is (for some weird reason) so often the case, selecting VBA gave me the relevant info, while VB gave me the info relating to an SQL query.
Nov 26 '06 #6

Dököll
Expert 100+
P: 2,364
According to the doco...I've just tested the second example in plain VB6, and it worked. I found that when looking it up in the MSDN doco, it had two entries - VB and VBA. As is (for some weird reason) so often the case, selecting VBA gave me the relevant info, while VB gave me the info relating to an SQL query.
Indeed, Saw it too, thought it to be helpful, but I have to admit I do not quite understand it, nor can I use it it seems. The txt file is added then read straight away. Seems like a wild card does not work for a .txt file, here is another protion of the code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub GtWords_Click()
  2.  
  3. If Text6.Text = "" Then
  4. MsgBox ("Looks, you forgot to add a lyric please add lyrical text to continue!")
  5. Text6.SetFocus
  6. ElseIf Text6.Text <> "" Then      
  7.  
  8. Open App.Path + "\usermate.txt" For Output As #1 'file is opened as inWrite because it is Writing back into the program
  9.                 Write #1, , Text6.Text
  10.  
  11.                 Close #1
  12.  
  13. Dim GoSplit As Variant
  14. Dim strGetWords As String
  15.  
  16. FileName = "\usermate.txt"
  17. f = FreeFile
  18. Open App.Path + FileName For Input As #1
  19. Do While Not EOF(f)
  20. Line Input #1, strGetWords
  21. GoSplit = Split(strGetWords, " ")
  22.  
  23.  
'This helps record the whole text from Text6 andbe read to find words collected. As we exchange notes, I am begining to see perhpas, the text must be added already formatted, therefore no "bus" even though busted is found (busted is not among words to find in text. We're still looking...thank you by te way, for posting your example from the microsoft site, I think I'll plug in some of it, trweak it see what happens. Again I have yet to undertstand it:

The SQL command I will be using later on will support your helpful comment previously added, fuzzy a bit, I think I should be good. It looks as though this sort of a command will not work to grab the absolute value::::::::::::::Whoa, Do you know about abolutevalue in VB, I learned there was such athing. What if I looked for the abolute value in strGetWords$, would that do the trick. Gotta go....

Dököll, thanks for posting
Nov 27 '06 #7

Expert 5K+
P: 8,434
Indeed, Saw it too, thought it to be helpful, but I have to admit I do not quite understand it, nor can I use it it seems. The txt file is added then read straight away. Seems like a wild card does not work for a .txt file
I'm afraid I couldn't really tell much from the code.

Could you give more detail on exactly how the Like operator "doesn't work"? Maybe it's something we can fix, because I've tested one or two of the samples from the documentation, and it definitely did work. I don't see how a text file being involved would affect it.

As for "abolute value" :- if you mean absolute value, then that is basically just a number without taking the sign into account. So for example, Abs(-3) and Abs(3) would both return the value 3. I don't see how it would apply to a string.
Nov 27 '06 #8

Dököll
Expert 100+
P: 2,364
I'm afraid I couldn't really tell much from the code.

Could you give more detail on exactly how the Like operator "doesn't work"? Maybe it's something we can fix, because I've tested one or two of the samples from the documentation, and it definitely did work. I don't see how a text file being involved would affect it.

As for "abolute value" :- if you mean absolute value, then that is basically just a number without taking the sign into account. So for example, Abs(-3) and Abs(3) would both return the value 3. I don't see how it would apply to a string.
Right on point, I spoke too soon, thanks for replying. The like operator works when I send the words found to an Access database, whereby frequent hits to it, unsing a wildcard (*), grabs all instances of "bus" inthe database. The problem is before the text is formatted to reflect exactly what the program asked, the format is useless; it's as if pickingup a dictionary and looking up words. When GtWords button is pushed, the code I previously posted starts running, accompagnied by a series of if statements, as in this posted solution:

Dim GoSplit As Variant
Dim strGetWords As String

FileName = "\usermate.txt"
f = FreeFile
Open App.Path + FileName For Input As 1
Do While Not EOF(f)
Line Input #1, strGetWords
GoSplit = Split(strGetWords, " ")

If InStrB(strGetWords$, "busted") <> 0 Then

Text4(9).Text = "busted"
convert_my_text="BUSTED
convert_me_modu.change_it_now 'this fires up my module named conert_me_modu
End If


''''''Additional if statements are added here,

My Module

Public convert_my_text As String

Public Sub change_it_now ()

If UCase(convert_my_text) = "BUSTED" Then
'first value performed
LyricalContentfind.Text4(9).Text = ""
'empty string works here, no need to set vsibilty to false
End If

End Sub


'This is working, but I will need to also tell VB the words I do not need it to find, thus busted. A wildcard, if it exists for searching a .txt file should do the trick, since searching the actual database "Bus*" does in fact give me "Bus", addded/found from different text, typed my son's "the magic school bus" grabbed "the wheels on the bus" as well from my database; this means, my recordset had two hits for bus...

If a 'something_wildcard' can be used for .txt, whether it picks up "bus" a number of times, the results will be specific to only "bus" not busted. I attempting vbTextCompare again, perhaps something's a miss. Oh! here is what my Like operator atttempt loked like:

Expand|Select|Wrap|Line Numbers
  1. If strGetWords$ Like "dancing" <> 0 Then
  2. Text17(10).Text = "Dancing"
  3. End If
'If you typed up godancing, you got dancing out of that. I gt an idea :-)
In a bit!
Nov 27 '06 #9

Expert 5K+
P: 8,434
Oh! here is what my Like operator atttempt loked like:
Expand|Select|Wrap|Line Numbers
  1. If strGetWords$ Like "dancing" <> 0 Then
  2. Text17(10).Text = "Dancing"
  3. End If
'If you typed up godancing, you got dancing out of that. I gt an idea :-)
In a bit!
I suppose it might depend on the Option Compare setting, which I've never touched. But as far as I know, that Like comparison will return the same result as using the = operator. The whole point of Like is that it allows you to use wildcards to indicate patterns or unknown parts in the string. By the way, the <> 0 is pointless, as well. The only two values that might be returned from the Like comparison are True (-1) and False (0). You’d do better to say If strGetWords$ Like "whatever" Then

How's this for an idea? If you have a string and you want to check whether a specific word appears within it, say "dancing", and you don't care about the case (upper/lower), perhaps you could use this...
Expand|Select|Wrap|Line Numbers
  1. If Lcase(strGetWords$) Like "* dancing *"0 Then
  2.   …
  3. End If
You might also want to try this, to account for words at the start or end of the string.
Expand|Select|Wrap|Line Numbers
  1. If Lcase(strGetWords$) Like "* dancing *" _
  2.     Or Lcase(strGetWords$) Like "dancing *" _
  3.     Or Lcase(strGetWords$) Like "* dancing" _
  4.     Then
  5.        …
  6. End If
One thing I don't understand is this. If you have already used Split to separate the string into words, why don't you just loop through and use = to check each of them?
Nov 27 '06 #10

Dököll
Expert 100+
P: 2,364
I suppose it might depend on the Option Compare setting, which I've never touched. But as far as I know, that Like comparison will return the same result as using the = operator. The whole point of Like is that it allows you to use wildcards to indicate patterns or unknown parts in the string. By the way, the <> 0 is pointless, as well. The only two values that might be returned from the Like comparison are True (-1) and False (0). You’d do better to say If strGetWords$ Like "whatever" Then

How's this for an idea? If you have a string and you want to check whether a specific word appears within it, say "dancing", and you don't care about the case (upper/lower), perhaps you could use this...
Expand|Select|Wrap|Line Numbers
  1. If Lcase(strGetWords$) Like "* dancing *"0 Then
  2.   …
  3. End If
You might also want to try this, to account for words at the start or end of the string.
Expand|Select|Wrap|Line Numbers
  1. If Lcase(strGetWords$) Like "* dancing *" _
  2.     Or Lcase(strGetWords$) Like "dancing *" _
  3.     Or Lcase(strGetWords$) Like "* dancing" _
  4.     Then
  5.        …
  6. End If
One thing I don't understand is this. If you have already used Split to separate the string into words, why don't you just loop through and use = to check each of them?
Genius, I was about to post yet another idea, but I think yours will work. I wanted to allow strGetWords$ to do the work but still be able to pick up say:

Expand|Select|Wrap|Line Numbers
  1.  If strGetWords$ like " bus " <> 0 then 
  2. ' By the way, I agree with you here, <> 0 was left behind with InstrB, decided to roll with it anyway.  Now even though it is useless, could it screw up the code just being added in...I'll get rid o it nonetheless, just checking
  3.  
  4. GoSplit=strGetWords$(Trim(" bus ")
  5. LyricalContentfind.Text4(8).Text ="Bus"
  6.  
  7. End If
  8.  
  9.  
I wanted to try this because if I were to trim spaces from left to right, VB would give me the exact word searched, not bus because of busted; bus because it was included in a phrase. I attempted * at both ends as well, but I did not have any spaces, looks like you have space after *, will go to it again. Appreciate your reply...
Nov 28 '06 #11

Dököll
Expert 100+
P: 2,364
Genius, I was about to post yet another idea, but I think yours will work. I wanted to allow strGetWords$ to do the work but still be able to pick up say:

Expand|Select|Wrap|Line Numbers
  1.  If strGetWords$ like " bus " <> 0 then 
  2. ' By the way, I agree with you here, <> 0 was left behind with InstrB, decided to roll with it anyway.  Now even though it is useless, could it screw up the code just being added in...I'll get rid o it nonetheless, just checking
  3.  
  4. GoSplit=strGetWords$(Trim(" bus ")
  5. LyricalContentfind.Text4(8).Text ="Bus"
  6.  
  7. End If
  8.  
  9.  
I wanted to try this because if I were to trim spaces from left to right, VB would give me the exact word searched, not bus because of busted; bus because it was included in a phrase. I attempted * at both ends as well, but I did not have any spaces, looks like you have space after *, will go to it again. Appreciate your reply...
Thanks much for your post, looks like we're still battling againt this beast. I get dancing out of godancing
Expand|Select|Wrap|Line Numbers
  1.  
  2. 'this helped a great deal, first of all, I can further minimize lines of code with this, then add more words, my client/buddy was helpeful and deleted gave me a new list of words, attempting to assist me with the 'Procedure too large' error I got earlier on.
  3.  
  4. If Lcase(strGetWords$) Like "* dancing *" _
  5.     Or Lcase(strGetWords$) Like "dancing *" _
  6.     Or Lcase(strGetWords$) Like "* dancing" _
  7.     Then
  8.        …
  9. End If
  10.  
  11. 'my previous syntax will probably work, not in thecurrent form, I am not sure what I wrote, the idea came to in a flash.
  12.  
  13.  
I wanted to try the above an I am glad I did. I think triminng spaces may work, works for tab delimited .txt files through sql advantage results, there's got to be a way to pin this to VB and it takes it, you know -)
Nov 28 '06 #12

Expert 5K+
P: 8,434
Genius, I was about to post yet another idea, but I think yours will work. I wanted to allow strGetWords$ to do the work but still be able to pick up say:
Now you're making me blush!
Expand|Select|Wrap|Line Numbers
  1. GoSplit=strGetWords$(Trim(" bus ")
Um... I don't think that statement makes sense. Did you intend to include an Instr in there? As it stands, it looks as though you are trying to treat a string like a function. That might work in Java, but I don't think VB will be happy about it.
I wanted to try this because if I were to trim spaces from left to right, VB would give me the exact word searched, not bus because of busted; bus because it was included in a phrase. I attempted * at both ends as well, but I did not have any spaces, looks like you have space after *, will go to it again.
Yes, it's a little bit tricky. But the three variations I wrote should catch a word in the middle of a sentence, or at the start or end. But it should detect only whole words.

It might be a good idea to write a function which applies those three variations of the Like( ) function to a passed string, rather than coding it all the time. Then you can write more easily reasble code. For example...
Expand|Select|Wrap|Line Numbers
  1. If StringContainsWord(strGetWords$, "bus") Then ...
Nov 28 '06 #13

Dököll
Expert 100+
P: 2,364
Now you're making me blush!
Um... I don't think that statement makes sense. Did you intend to include an Instr in there? As it stands, it looks as though you are trying to treat a string like a function. That might work in Java, but I don't think VB will be happy about it.
Yes, it's a little bit tricky. But the three variations I wrote should catch a word in the middle of a sentence, or at the start or end. But it should detect only whole words.

It might be a good idea to write a function which applies those three variations of the Like( ) function to a passed string, rather than coding it all the time. Then you can write more easily reasble code. For example...
Expand|Select|Wrap|Line Numbers
  1. If StringContainsWord(strGetWords$, "bus") Then ...
Not intended, I get all worked up when good ideas come about, well deserved. I think I'll try trim somehow but with a function I set up like you said, just to be sure I get what I want everytime, double-checking if you know what I mean. This is what I'll do now. OK, here is another idea that popped up, I trust trimming more though. What if, mind you the text is being added in the following fashion:

Expand|Select|Wrap|Line Numbers
  1. Private Sub GtWords_Click()
  2.  
  3. If Text6.Text = "" Then
  4. MsgBox ("Looks, you forgot to add a lyric please add lyrical text to continue!")
  5. Text6.SetFocus
  6. ElseIf Text6.Text <> "" Then      
  7.  
  8. Open App.Path + "\usermate.txt" For Output As #1 'file is opened as inWrite because it is Writing back into the program
  9.                 Write #1, , Text6.Text
  10.  
  11.                 Close #1
  12.  
  13. End If, Sub and so on
  14.  
  15.  
When/while it is being added, what if I add stuff to it, likequotation marks (" "), for instance: "the" "wheels" "on" "the" "bus". I remember having to do this to replace a word from astring. What are your thoughts on this? Could we do this then still search, I mean why not, right. I will be searching for the code here. Perhaps, not to replace "the" "wheels" "on" "the" "bus", but at least add characters (" ") to each word so that they are valid everytime, "bus", "rain", and so on. By the time you read this, I may think of something else but please stop me if you think I am heading to desaster.

Dököll
Nov 28 '06 #14

Expert 5K+
P: 8,434
Not intended, I get all worked up when good ideas come about, well deserved. I think I'll try trim somehow but with a function I set up like you said, just to be sure I get what I want everytime, double-checking if you know what I mean.
Yes, the modular approach makes it much simpler to debug and test each part. And once your function is working and tested, you can reuse it without having to get it working again.


...What if, mind you the text is being added in the following fashion: ...
Expand|Select|Wrap|Line Numbers
  1. ElseIf Text6.Text <> "" Then
Actually, all you need there is Else.

By the time you read this, I may think of something else but please stop me if you think I am heading to desaster.
No disaster that I'm aware of. But I'm afraid I'm not really following very well.

Anyway, probably the best way to learn this stuff is to try it, and see what happens.
Nov 28 '06 #15

Dököll
Expert 100+
P: 2,364
Yes, the modular approach makes it much simpler to debug and test each part. And once your function is working and tested, you can reuse it without having to get it working again.


Actually, all you need there is Else.

No disaster that I'm aware of. But I'm afraid I'm not really following very well.

Anyway, probably the best way to learn this stuff is to try it, and see what happens.
That's ok. It's been a long and draining two days thus far. I think I am up to something though. Else gave me an error by itself on one line, accept if I was ending it right then...


Expand|Select|Wrap|Line Numbers
  1. If....then
  2.  
  3. .....
  4.  
  5. Else
  6.  
  7. MsgBox("...")
  8.  
  9. End If
  10.  
  11. 'worked ok, no errors, but...
  12.  
...code to fetch words runs here...after End If

I wanted End If all the way at the end of my if statement so the code runs to find words. End If, before I reopened the file to see what was added, did not allow that part of the code to run. I can't think of the whole code now, will post what I find out, in a bit...
Nov 29 '06 #16

Expert 5K+
P: 8,434
Sounds as though I may have misinterpreted your logic. However, given this code as posted
Expand|Select|Wrap|Line Numbers
  1. If Text6.Text = "" Then
  2.   ...
  3. ElseIf Text6.Text <> "" Then
  4.   ...
  5. End If
I was just pointing out that you'd have got much the same result with
Expand|Select|Wrap|Line Numbers
  1. If Text6.Text = "" Then
  2.   ...
  3. Else
  4.   ...
  5. End If
It's really not a big deal.
Nov 29 '06 #17

Dököll
Expert 100+
P: 2,364
Sounds as though I may have misinterpreted your logic. However, given this code as posted
Expand|Select|Wrap|Line Numbers
  1. If Text6.Text = "" Then
  2.   ...
  3. ElseIf Text6.Text <> "" Then
  4.   ...
  5. End If
I was just pointing out that you'd have got much the same result with
Expand|Select|Wrap|Line Numbers
  1. If Text6.Text = "" Then
  2.   ...
  3. Else
  4.   ...
  5. End If
It's really not a big deal.
Understood...I came up with something, but need professional help to make it work. In order for the application to grab just the word I need, I think I need to talk to VB a little more. We'll start with previously posted example, very helpful, by the way, I have more room to play:

Expand|Select|Wrap|Line Numbers
  1.  
  2. If Lcase(strGetWords$) Like "* dancing *" _
  3.     Or Lcase(strGetWords$) Like "dancing *" _
  4.     Or Lcase(strGetWords$) Like "* dancing" _
  5.     Then
  6.        …
  7. End If
  8.  
I need to tell VB when it finds "rain" to make sure it is giving me the extreme left characters of "rain", threfore train will not get licked up, "t" being the first cahracter here. Here is what I have:

Expand|Select|Wrap|Line Numbers
  1.  
  2. strGetWords$ will attempt to give me "rain" from train, so I am not worried too much.  But when it finds train:
  3.  
  4. If Left$(strGetWords$, 4) = "rain" And Lcase(strGetWords$) Like " rain *"  Then
  5.       this and that here...
  6. End If
  7.  
  8.  
Note above 4 is where I am stuck. I know there is a way to add the character length to Left$ to lock in just "rain". What are your thoughts?

I am still getting, rain from train.
Dec 3 '06 #18

Expert 5K+
P: 8,434
...
Expand|Select|Wrap|Line Numbers
  1. strGetWords$ will attempt to give me "rain" from train, so I am not worried too much.  But when it finds train:
  2.  
  3. If Left$(strGetWords$, 4) = "rain" And Lcase(strGetWords$) Like " rain *"  Then
  4.       this and that here...
  5. End If
  6.  
Note above 4 is where I am stuck. I know there is a way to add the character length to Left$ to lock in just "rain". What are your thoughts?

I am still getting, rain from train.
As far as I can see, the sort of check that I suggested for dancing should work. See whether you like any of these variations on the theme...
Expand|Select|Wrap|Line Numbers
  1. ' Just to make code shorter, and reduce the number of
  2. ' function calls, let's convert our text and store in another var.
  3. Temp$ = Lcase(strGetWords)
  4.  
  5.  
  6. ' Version 1 should find any line starting with the 4 letters "rain"...
  7. If Temp$ Like "rain*" Then
  8.       this and that here...
  9. End If
  10.  
  11. ' Version 2 should find only "rain" as the first word...
  12. If Temp$ Like "rain *" Then
  13.       this and that here...
  14. End If
  15.  
  16. ' Version 3 should find any word starting with "rain"...
  17. If Temp$ Like "* rain*" Then
  18.       this and that here...
  19. End If
  20.  
  21.  
  22. ' Version 4 should find the word "rain" anywhere in the string...
  23. If Temp$ Like "* rain *" Or Temp$ Like "rain *" Or Temp$ Like "* rain" Then
  24.       this and that here...
  25. End If
  26.  
I may have mentioned this before, but I think it would be a good idea to make a function out of this, so you can just pass the word you're interested in. For example, to implement version 4 in a function...
Expand|Select|Wrap|Line Numbers
  1. Public Function WordExistsIn(ByVal StrSentence as String, ByVal strWord as String) As Boolean
  2. If StrSentence Like "* " & strWord & " *" Or _
  3.    StrSentence Like strWord & " *" Or _
  4.    StrSentence Like "*" & strWord Then
  5.      WordExistsIn = True
  6. End If
  7. End Function
  8.  
Dec 3 '06 #19

Dököll
Expert 100+
P: 2,364
As far as I can see, the sort of check that I suggested for dancing should work. See whether you like any of these variations on the theme...
Expand|Select|Wrap|Line Numbers
  1. ' Just to make code shorter, and reduce the number of
  2. ' function calls, let's convert our text and store in another var.
  3. Temp$ = Lcase(strGetWords)
  4.  
  5.  
  6. ' Version 1 should find any line starting with the 4 letters "rain"...
  7. If Temp$ Like "rain*" Then
  8.       this and that here...
  9. End If
  10.  
  11. ' Version 2 should find only "rain" as the first word...
  12. If Temp$ Like "rain *" Then
  13.       this and that here...
  14. End If
  15.  
  16. ' Version 3 should find any word starting with "rain"...
  17. If Temp$ Like "* rain*" Then
  18.       this and that here...
  19. End If
  20.  
  21.  
  22. ' Version 4 should find the word "rain" anywhere in the string...
  23. If Temp$ Like "* rain *" Or Temp$ Like "rain *" Or Temp$ Like "* rain" Then
  24.       this and that here...
  25. End If
  26.  
I may have mentioned this before, but I think it would be a good idea to make a function out of this, so you can just pass the word you're interested in. For example, to implement version 4 in a function...
Expand|Select|Wrap|Line Numbers
  1. Public Function WordExistsIn(ByVal StrSentence as String, ByVal strWord as String) As Boolean
  2. If StrSentence Like "* " & strWord & " *" Or _
  3.    StrSentence Like strWord & " *" Or _
  4.    StrSentence Like "*" & strWord Then
  5.      WordExistsIn = True
  6. End If
  7. End Function
  8.  
That's refreshing! Let's give it whirl...
Dec 4 '06 #20

Expert 5K+
P: 8,434
That's refreshing! Let's give it whirl...
Good luck! :)

If you want the function to be more widely applicable, you could set it up to accept options to find the passed word at start of sentence, end of sentence, full word, partial word, or whatever. (Just speculating because I'm interested, here...) You could have an option which accepts values to indicate you want to find a match:
  • At start of string,
  • At end of string,
  • At start of a word,
  • At end of a word,
  • Whole word only, or
  • Anywhere in string
Extra credit assignment :)
As an educational exercise, research and set up a public Enum with named values for these options, and a function to use them. (If you haven't played with an Enum before, it's astonishingly simple.)
Dec 4 '06 #21

Dököll
Expert 100+
P: 2,364
Good luck! :)

If you want the function to be more widely applicable, you could set it up to accept options to find the passed word at start of sentence, end of sentence, full word, partial word, or whatever. (Just speculating because I'm interested, here...) You could have an option which accepts values to indicate you want to find a match:
  • At start of string,
  • At end of string,
  • At start of a word,
  • At end of a word,
  • Whole word only, or
  • Anywhere in string
Extra credit assignment :)
As an educational exercise, research and set up a public Enum with named values for these options, and a function to use them. (If you haven't played with an Enum before, it's astonishingly simple.)
Killer, thanks for posting this, and I will check into 'Start of' & 'End o' string, see where it gets me. I am not familiar with Enum, I checked into it and it seems t be specific to numbers, is this correct?

Going forward, it looks like you did not see my previous note, I copied it and will add to this reply so you can see what I have been up to. Here it goes:

PREVIOUSLY NOTED


HAPPY NEW YEAR VB Fans!!! Hopefully, we continue battling against VB for years to come, unless Microsoft makes this steadily unusable, there's probably big plans when Vista is "Fully" operational, hee, hee...

My friends, Killler, WillAkaWill, VB friends accross the country, I thank you for your support and patience. I think we are almost there. Much appreciated help, by the way, with the code, especially adding the below to the mix. The code works great, but does not seem to be doing what you told me Killer; of course, I am to blame for being a newbie and all. Seems as though, a text file does not abide by rules of certain databases, where VB would be reading from cells containing text/word as opposed to a block of text/words in a .txt file. What do you see happening, I am blind back here. Send me some brain waves, will you?

Should I set a character length I am certain is reachable, whereby one word in the program supports the highest possible character length, 13 characters for lightningbolt...I have been in and out of the code trying diffrent things, my latest brought me to:

Expand|Select|Wrap|Line Numbers
  1.  
  2. temp$Left$(strGetWords$, 13)
  3.  
  4. temp$=LCase(StrGetWords$)
  5.  
  6.  
I need a do while loop here, that will check to see if any characters were met, meaning:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Do While temp$ <= 13
  3.  
  4. ' then have if statements here to grab anything that falls under 13 chars.
  5.  
  6.  
Would you tell me if this is possible? Works by itself and grabs characters already set. Any idea you can provide is helpful. This was an attempt to stay away from looping, I kept getting stuck in a loop:

Expand|Select|Wrap|Line Numbers
  1.  
  2. temp$ = LCase(strGetWords)
  3.  
  4. temp$ = Left$(strGetWords, 4) 
  5. ' this should give me rain or anything in that length catagory
  6.  
  7.  
  8. temp$ = Left$(strGetWords, 5) 
  9. ' this should give me Train or anything in that length catagory
  10.  
  11.  
  12. temp$ = Left$(strGetWords, 6) 
  13. ' this should give me Grains or anything in that length catagory
  14.  
  15.  
  16. ' Version 1 should find any line starting with the 4 letters "rain"...
  17. If temp$ = "rain" Then
  18. Text1.Text = "Rain"    'this and that here...
  19. End If
  20.  
  21. ' Version 2 should find only "rain" as the first word...
  22. If temp$ = "Train" Then
  23. Text2.Text = Text6.Text      'this and that here...
  24. End If
  25.  
  26. ' Version 3 should find any word starting with "rain"...
  27. If temp$ Like "Grains" Then
  28. Text3.Text = "Grains"    'this and that here...
  29. End If
  30.  
  31.  
The only problem here is, the first temp$ variable grabs rain straight away and ignores the other words. I added each word as rain, Train, Grains, and only rain was picked up. My guess is a loop will tell VB to jump over after rain is found in order to find other words from the text box. Any ideas, I know this was a mouth full, Sorry. If the loop is not doable and your previous postings should work please clarify a bit more. :-)
Dec 29 '06 #22

Post your reply

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