VB 6.0 Professional + execute Left() function through module

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

    #1

    VB 6.0 Professional + execute Left() function through module

    Hey VB Gang!

    I attempted to send this previously but failed. behold the introduction of a newbie :-)

    Anyway, I am hoping t find a shortcut to fixing a problem. Modifying a text reader software which is supposed to pick only the words I tell it, "Bicycle" as one example:

    My form

    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, strLine
    GoSplit = Split(strGetWor ds, " ")

    If InStrB(strGetWo rds$, "bicycle") <> 0 Then

    'Left() would have picked up "Bicycle"
    'InStrB is grabing everything in sight, provided the're somewhat alike like motorcycle

    Text2(0).Text = "Bicycle"
    End If

    I should have used Left() here. Nonetheless I do not have the time to modify the code, my client leaves in aweek to test it.

    My Module

    Dim MyStr As Variant
    Dim GrabMore As String
    Public Sub SendOnly()
    GrabMore = LyricalContentf ind.Text2(0).Te xt
    MyStr = Left(GrabMore, 7)
    'hoping to grab only bicyle's 7 characters
    'for the time being I am also gettin "cycle" NOT IN THE CODE...
    'I get cycle when motocycle is found in the text.

    If Left(GrabMore, 7) <> "" Then 'first value performed
    LyricalContentf ind.Text2(0).Te xt = "Bicycle"
    Else
    MsgBox("No words here fun boy!")

    'only if there are no words were found, should above come up

    LyricalContentf ind.Text2(0).Te xt = ""

    End If

    End Sub

    If you can point me to a solution, it would be great. I am also a VB fan, and would rather make the code do what I want. Any sort of hints you have is appreciated. Have a great week All!

    Dököll
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Hi Dököll.

    Sorry, but maybe I'm a little slow - I just could not make out exactly what the problem is. Could you please try to give us a brief summary of what you want the code to do, and in this case perhaps what you don't want it to do?

    Comment

    • willakawill
      Top Contributor
      • Oct 2006
      • 1646

      #3
      Originally posted by Dököll
      Line Input #1, strLine
      GoSplit = Split(strGetWor ds, " ")

      Dököll
      Hi, what exactly do you expect to find in strGetWords?
      You have just declared this variable and stored nothing in it.

      Comment

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

        #4
        First off, I would like to thank you for your prompt reply and I apologize for the typo, strLine does not exist in the code: Line Input #1, strGetWords, Not Line Input #1, strLine ' I am attempting to read a file already created...

        strGetWords grabs Bicycle and outputs both Bicycle and cycle
        GoSplit reads the whole TEXT file

        If motorcycle is found in the text, I do not want cycle to be outputted. It seems like strGetWords is forcing part of text out regardless my efforts to control it with the Left() function in a module.

        Any direction you have is appreciated.

        Dököll

        Comment

        • willakawill
          Top Contributor
          • Oct 2006
          • 1646

          #5
          Originally posted by Dököll
          First off, I would like to thank you for your prompt reply and I apologize for the typo, strLine does not exist in the code: Line Input #1, strGetWords, Not Line Input #1, strLine ' I am attempting to read a file already created...

          strGetWords grabs Bicycle and outputs both Bicycle and cycle
          GoSplit reads the whole TEXT file

          If motorcycle is found in the text, I do not want cycle to be outputted. It seems like strGetWords is forcing part of text out regardless my efforts to control it with the Left() function in a module.

          Any direction you have is appreciated.

          Dököll
          Perhaps the InStr() function will work better for you. It will not pick up motorcycle when you are testing for bicycle. Make sure it is set to vbTextCompare

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by willakawill
            Perhaps the InStr() function will work better for you. It will not pick up motorcycle when you are testing for bicycle. Make sure it is set to vbTextCompare
            Although I admit to much difficulty in determining exactly what the question was, I think the problem referred to here is picking up parts of words (Eg. look for "cycle", find "Bicycle" and/or "motorcycle ") when they are not wanted In which case, Instr may not help.

            In other words, it sounds as though the OP wants a "non-absolute" scan, as we would call it at work, rather than an "absolute" scan, which finds text anywhere.

            I don't have more of an answer, because as stated above, I don't yet understand the question. But I'm trying, really I am...

            Comment

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

              #7
              Originally posted by willakawill
              Perhaps the InStr() function will work better for you. It will not pick up motorcycle when you are testing for bicycle. Make sure it is set to vbTextCompare
              I think I will try that, thanks, I will let you know

              Comment

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

                #8
                Originally posted by Killer42
                Although I admit to much difficulty in determining exactly what the question was, I think the problem referred to here is picking up parts of words (Eg. look for "cycle", find "Bicycle" and/or "motorcycle ") when they are not wanted In which case, Instr may not help.

                In other words, it sounds as though the OP wants a "non-absolute" scan, as we would call it at work, rather than an "absolute" scan, which finds text anywhere.

                I don't have more of an answer, because as stated above, I don't yet understand the question. But I'm trying, really I am...
                My apologies, here is a simpler version, although by th time you read this I would have figured this out, I think vbTextCompare may do the trick, I intend to read up on it.

                Dim GoSplit As Variant

                'should grab everything in the file, strGetWords will handle "Bicycle"

                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$, "bicycle") <> 0 Then

                'Left() would have picked up "Bicycle"
                'InStrB is grabing everything in sight, provided the're somewhat alike like motorcycle

                Text2(0).Text = "Bicycle"
                End If



                here's the problem:

                If InStrB(strGetWo rds$, "rain") <> 0 Then

                Text2(3).Text = "Rain"
                End If

                I got Rain when B[rain] is picked up in the string, Brain is not in the code. Iwant the program to grab only the words I specify. Please write again if this not clear, I seem to confuse a lot of people. In a bit :-)

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Sorry, I'm in a rush right now, but what about if you do a loop through the array in GoSplit and simply compare each one to the string you're looking for ("cycle", "rain" or whatever) - no Left, Instr or any other functions required.
                  Last edited by Killer42; Nov 8 '06, 02:28 AM. Reason: Typo

                  Comment

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

                    #10
                    Originally posted by Killer42
                    Sorry, I'm in a rush right now, but what about if you do a loop through the array in GoSplit and simply compare each one to the string you're looking for ("cycle", "rain" or whatever) - no Left, Instr or any other functions required.
                    That's OK, I am bouncing off the walls these days..but I am at it as we speak and will report back to you guys soon. In a bit...

                    Comment

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

                      #11
                      Originally posted by willakawill
                      Perhaps the InStr() function will work better for you. It will not pick up motorcycle when you are testing for bicycle. Make sure it is set to vbTextCompare
                      Here goes:

                      (1) vbTextCompare did not seem to work, but I kept on with InStrB, like you said, for my sake anyway, being a newbie and all. Anyway, I learned it the hard way and the code is doing what I want to a T. Lukilly, my friend and client gave me more time to complete the project...I feel bad about it because this was to be the trial product

                      (2) the answer can be simpler and is lurking about, I am sure, perhaps after postings my findings, you can see what I really hoped to achieve. Tackle it for the next version, I still worry of speed of the application.

                      That said. Being that strGetWords was taking in any word matching "rain" thus train, brain, grain, drain. I saw it best fitting to simply disable the darn textbox that would have carried "rain" if in case "Insane in the brain" is part of the text, I'd rather "rain" not picked up. Here is what the code looks like now:


                      If InStrB(strGetWo rds$, "train") <> 0 Then 'train is available, give me Trains

                      Text2(3).Text = "Trains"
                      Text4(1).Visibl e = False

                      'I do not need "Rain" to be shown since train is the true value...An empty string did not seem to work here (not sure why) so I had to set Text4(1) visibility to false.

                      End If

                      If InStrB(strGetWo rds$, "train") = 0 And InStrB(strGetWo rds$, "rain") <> 0 Then

                      Text4(1).Text = "Rain" ' Looking to pick up only "rain", thus to outputting "Rain"
                      Text2(3).Visibl e = False 'just in case, I want this invisible
                      End If

                      Here there you have it...an ugly way of doing this but that's the solution that is working.

                      Nevertheless, I need your help figuring out a simple way to achieve this. I could have added a Do while loop, having x as interger, respectfully (x), where x is part of an array to what I need to find in each textbox (Example: Text2(x), Text4(x). I think strGetWords$ will still add "Rain" in my textbox even then when train or similarly brain is found. Please tell me your thoughts on this...

                      Dököll

                      Comment

                      • rani deshmukh
                        New Member
                        • Nov 2006
                        • 2

                        #12
                        hi,
                        thanks to joining me in ur community,
                        i have problem in visual basic project development means in exact to make a perfect project what kind of skills reuired, n to make that give me idea to how they can design ,coding skill,developme nt skill,how diagnosis the error,arrangmen t of project,every things related to development of project in visual basi 6.0 and visual basic which having new things founded by r&d developers,plz give me reply






                        thanks
                        rani deshmukh

                        Comment

                        • willakawill
                          Top Contributor
                          • Oct 2006
                          • 1646

                          #13
                          Originally posted by Dököll
                          Here goes:

                          (1) vbTextCompare did not seem to work, but I kept on with InStrB, like you said, for my sake anyway, being a newbie and all. Anyway, I learned it the hard way and the code is doing what I want to a T. Lukilly, my friend and client gave me more time to complete the project...I feel bad about it because this was to be the trial product

                          (2) the answer can be simpler and is lurking about, I am sure, perhaps after postings my findings, you can see what I really hoped to achieve. Tackle it for the next version, I still worry of speed of the application.

                          That said. Being that strGetWords was taking in any word matching "rain" thus train, brain, grain, drain. I saw it best fitting to simply disable the darn textbox that would have carried "rain" if in case "Insane in the brain" is part of the text, I'd rather "rain" not picked up. Here is what the code looks like now:


                          If InStrB(strGetWo rds$, "train") <> 0 Then 'train is available, give me Trains

                          Text2(3).Text = "Trains"
                          Text4(1).Visibl e = False

                          'I do not need "Rain" to be shown since train is the true value...An empty string did not seem to work here (not sure why) so I had to set Text4(1) visibility to false.

                          End If

                          If InStrB(strGetWo rds$, "train") = 0 And InStrB(strGetWo rds$, "rain") <> 0 Then

                          Text4(1).Text = "Rain" ' Looking to pick up only "rain", thus to outputting "Rain"
                          Text2(3).Visibl e = False 'just in case, I want this invisible
                          End If

                          Here there you have it...an ugly way of doing this but that's the solution that is working.

                          Nevertheless, I need your help figuring out a simple way to achieve this. I could have added a Do while loop, having x as interger, respectfully (x), where x is part of an array to what I need to find in each textbox (Example: Text2(x), Text4(x). I think strGetWords$ will still add "Rain" in my textbox even then when train or similarly brain is found. Please tell me your thoughts on this...

                          Dököll
                          Where is this word 'Train' or 'Brain' coming from and where is the strGetwords string coming from?

                          Comment

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

                            #14
                            Originally posted by willakawill
                            Where is this word 'Train' or 'Brain' coming from and where is the strGetwords string coming from?
                            Originally posted by willakawill
                            Where is this word 'Train' or 'Brain' coming from and where is the strGetwords string coming from?
                            Hello! strGetWords is dimensioned as string, GoSplit as variant: Train is being added in large textbox, capable of recording at least 300 to 400 words,m in a lyrical text, for example. Glad you wrote by the way, I found out something else: while I managed to make textbox invisbl thus to not carry rain, I find that "Bus" is being added to its textbox, Text4(9).Text when "busted", is found. My analysis brought me to yet another simple solution--"Busted" having a cap first letter dos not ght picked up, so I decided to convert all lowercased "busted/s" to Uppercase,then say, give nothing when BUSTED is found, it works well and here is the code again, See module, as well (part of the 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

                            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

                            Comment

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

                              #15
                              Originally posted by willakawill
                              Where is this word 'Train' or 'Brain' coming from and where is the strGetwords string coming from?
                              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:

                              Code:
                              temp$Left$(strGetWords$, 13)
                              
                              temp$=LCase(StrGetWords$)
                              I need a do while loop here, that will check to see if any characters were met, meaning:

                              Code:
                              Do While temp$ <= 13
                              
                              ' then have if statements here to grab anything that falls under 13 chars.
                              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:

                              Code:
                              temp$ = LCase(strGetWords)
                              
                              temp$ = Left$(strGetWords, 4) 
                              ' this should give me rain or anything in that length catagory
                              
                              
                              temp$ = Left$(strGetWords, 5) 
                              ' this should give me Train or anything in that length catagory
                              
                              
                              temp$ = Left$(strGetWords, 6) 
                              ' this should give me Grains or anything in that length catagory
                              
                              
                              ' Version 1 should find any line starting with the 4 letters "rain"...
                              If temp$ = "rain" Then
                              Text1.Text = "Rain"    'this and that here...
                              End If
                              
                              ' Version 2 should find only "rain" as the first word...
                              If temp$ = "Train" Then
                              Text2.Text = Text6.Text      'this and that here...
                              End If
                              
                              ' Version 3 should find any word starting with "rain"...
                              If temp$ Like "Grains" Then
                              Text3.Text = "Grains"    'this and that here...
                              End If
                              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. :-)

                              Comment

                              Working...