473,396 Members | 2,010 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,396 software developers and data experts.

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

Dököll
2,364 Expert 2GB
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
21 3417
Dököll
2,364 Expert 2GB
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
Killer42
8,435 Expert 8TB
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
2,364 Expert 2GB
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
2,364 Expert 2GB
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
Killer42
8,435 Expert 8TB
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
2,364 Expert 2GB
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
Killer42
8,435 Expert 8TB
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
2,364 Expert 2GB
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
Killer42
8,435 Expert 8TB
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
2,364 Expert 2GB
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
2,364 Expert 2GB
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
Killer42
8,435 Expert 8TB
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
2,364 Expert 2GB
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
Killer42
8,435 Expert 8TB
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
2,364 Expert 2GB
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
Killer42
8,435 Expert 8TB
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
2,364 Expert 2GB
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
Killer42
8,435 Expert 8TB
...
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
2,364 Expert 2GB
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
Killer42
8,435 Expert 8TB
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
2,364 Expert 2GB
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

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

Similar topics

1
by: Law.Win | last post by:
I have an IIF statement in the criteria of a query. I would like to know how to use a wildcard with the varaibles inside it. For example IIF(, , ) I would like the wildcard after variable 2. ...
0
by: Torsten | last post by:
I am attempting to issue an SQL query in C# to and Access database using the Microsoft.Jet.OLEDB.4.0 provider. The only wildcard character that seems to work is ‘%’. When using ‘#’,...
2
by: Ken Yee | last post by:
First a little background: I've written an httphandler to handle wildcard extensions (i.e., I want to handle all URLs that come in rather than just URLs w/ a specific file extension so I can give...
2
by: JohnT | last post by:
Okay... I'm using VB.net (2003) and I am accessing an MS Access DB file. I have two DataAdapters that I use to search for specific info. The two of them are similar except one is a Date, the...
7
by: SlimFlem | last post by:
I have searched hard for 2 days on this and keep hitting a wall. I have a custom IHttpHandler setup to do Url mappings to prop up some old Urls for our site. I have also created a wildcard...
13
by: hawkesed | last post by:
If I have a list, say of names. And I want to count all the people named, say, Susie, but I don't care exactly how they spell it (ie, Susy, Susi, Susie all work.) how would I do this? Set up a...
2
by: googlegroups.dsbl | last post by:
I'm really confused here, and am wondering if someone knows what could be the issue with my TableAdapter query. A few months ago, I created a really neat program that has th ability to search by...
11
by: google | last post by:
I need a simple wildcard pattern matching function written in JS. I have wrestled with regular expresions but frankly am struggling to come up with anything less than an epic function of many lines...
5
by: Dave | last post by:
I need to filter an Access 2000 result set in ASP 30 using the ADO recordset.filter. I build the filter in pieces. The first clause of the filter is this... WHERE word LIKE 'S%' ... to...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.