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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

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

    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
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by Dököll
    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:

    Code:
    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 strGetWords$ like "bus" <> 0 Then  '  want bus but I also get bus from busted
    'Is there anything to add here that would make only the instance of bus to pop up
    
    'Adding asterisk as in "bus*" give me nada, not a thing...
    
    Text4(8).Text = "bus"
    End If
    
    'What I hope to do make sure "busted" is not picked up since "bus" gets picked up from "busted"
    
    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?
    
    What are yur thoughts on this?
    
    Dököll

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      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.

      Comment

      • Dököll
        Recognized Expert Top Contributor
        • Nov 2006
        • 2379

        #4
        Originally posted by Killer42
        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...

        Comment

        • Dököll
          Recognized Expert Top Contributor
          • Nov 2006
          • 2379

          #5
          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

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            According to the doco...
            Originally posted by MSDN Library
            Like Operator Example
            This example uses the Like operator to compare a string to a pattern.
            Code:
            Dim MyCheck
            MyCheck = "aBBBa" Like "a*a"   ' Returns True.
            MyCheck = "F" Like "[A-Z]"     ' Returns True.
            MyCheck = "F" Like "[!A-Z]"    ' Returns False.
            MyCheck = "a2a" Like "a#a"     ' Returns True.
            MyCheck = "aM5b" Like "a[L-P]#[!c-e]"  ' Returns True.
            MyCheck = "BAT123khg" Like "B?T*"      ' Returns True.
            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.

            Comment

            • Dököll
              Recognized Expert Top Contributor
              • Nov 2006
              • 2379

              #7
              Originally posted by Killer42
              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:
              [CODE=VB]
              Private Sub GtWords_Click()

              If Text6.Text = "" Then
              MsgBox ("Looks, you forgot to add a lyric please add lyrical text to continue!")
              Text6.SetFocus
              ElseIf Text6.Text <> "" Then

              Open App.Path + "\usermate. txt" For Output As #1 'file is opened as inWrite because it is Writing back into the program
              Write #1, , Text6.Text

              Close #1

              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(strGetWor ds, " ")

              [/CODE]
              '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

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by Dököll
                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.

                Comment

                • Dököll
                  Recognized Expert Top Contributor
                  • Nov 2006
                  • 2379

                  #9
                  Originally posted by Killer42
                  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(strGetWor ds, " ")

                  If InStrB(strGetWo rds$, "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


                  ''''''Additiona l if statements are added here,

                  My Module

                  Public convert_my_text As String

                  Public Sub change_it_now ()

                  If UCase(convert_m y_text) = "BUSTED" Then
                  'first value performed
                  LyricalContentf ind.Text4(9).Te xt = ""
                  '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_wild card' 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:

                  Code:
                  If strGetWords$ [B]Like[/B] "dancing" <> 0 Then
                  Text17(10).Text = "Dancing"
                  End If
                  'If you typed up godancing, you got dancing out of that. I gt an idea :-)
                  In a bit!

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Originally posted by Dököll
                    Oh! here is what my Like operator atttempt loked like:
                    Code:
                    If strGetWords$ [B]Like[/B] "dancing" <> 0 Then
                    Text17(10).Text = "Dancing"
                    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...
                    Code:
                    If Lcase(strGetWords$) Like "* dancing *"0 Then
                      …
                    End If
                    You might also want to try this, to account for words at the start or end of the string.
                    Code:
                    If Lcase(strGetWords$) Like "* dancing *" _
                        Or Lcase(strGetWords$) Like "dancing *" _
                        Or Lcase(strGetWords$) Like "* dancing" _
                        Then
                           …
                    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?

                    Comment

                    • Dököll
                      Recognized Expert Top Contributor
                      • Nov 2006
                      • 2379

                      #11
                      Originally posted by Killer42
                      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...
                      Code:
                      If Lcase(strGetWords$) Like "* dancing *"0 Then
                        …
                      End If
                      You might also want to try this, to account for words at the start or end of the string.
                      Code:
                      If Lcase(strGetWords$) Like "* dancing *" _
                          Or Lcase(strGetWords$) Like "dancing *" _
                          Or Lcase(strGetWords$) Like "* dancing" _
                          Then
                             …
                      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:

                      Code:
                       If strGetWords$ like " bus " <> 0 then 
                      ' 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
                      
                      GoSplit=strGetWords$(Trim(" bus ")
                      LyricalContentfind.Text4(8).Text ="Bus"
                      
                      End If
                      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...

                      Comment

                      • Dököll
                        Recognized Expert Top Contributor
                        • Nov 2006
                        • 2379

                        #12
                        Originally posted by Dököll
                        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:

                        Code:
                         If strGetWords$ like " bus " <> 0 then 
                        ' 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
                        
                        GoSplit=strGetWords$(Trim(" bus ")
                        LyricalContentfind.Text4(8).Text ="Bus"
                        
                        End If
                        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
                        Code:
                        '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.
                        
                        If Lcase(strGetWords$) Like "* dancing *" _
                            Or Lcase(strGetWords$) Like "dancing *" _
                            Or Lcase(strGetWords$) Like "* dancing" _
                            Then
                               …
                        End If
                        
                        'my previous syntax will probably work, not in thecurrent form, I am not sure what I wrote, the idea came to in a flash.
                        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 -)

                        Comment

                        • Killer42
                          Recognized Expert Expert
                          • Oct 2006
                          • 8429

                          #13
                          Originally posted by Dököll
                          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!
                          Originally posted by Dököll
                          Code:
                          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.
                          Originally posted by Dököll
                          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...
                          Code:
                          If StringContainsWord(strGetWords$, "bus") Then ...

                          Comment

                          • Dököll
                            Recognized Expert Top Contributor
                            • Nov 2006
                            • 2379

                            #14
                            Originally posted by Killer42
                            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...
                            Code:
                            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:

                            Code:
                            Private Sub GtWords_Click()
                            
                            If Text6.Text = "" Then
                            MsgBox ("Looks, you forgot to add a lyric please add lyrical text to continue!")
                            Text6.SetFocus
                            ElseIf Text6.Text <> "" Then      
                                   
                            Open App.Path + "\usermate.txt" For Output As #1 'file is opened as inWrite because it is Writing back into the program
                                            Write #1, , Text6.Text
                                          
                                            Close #1
                            
                            End If, Sub and so on
                            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

                            Comment

                            • Killer42
                              Recognized Expert Expert
                              • Oct 2006
                              • 8429

                              #15
                              Originally posted by Dököll
                              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.


                              Originally posted by Dököll
                              ...What if, mind you the text is being added in the following fashion: ...
                              Code:
                              ElseIf Text6.Text <> "" Then
                              Actually, all you need there is Else.

                              Originally posted by Dököll
                              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.

                              Comment

                              Working...