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

VB 6.0 Professional + execute Left() function through module

Dököll
Expert 100+
P: 2,364
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(strGetWords, " ")

If InStrB(strGetWords$, "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 = LyricalContentfind.Text2(0).Text
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
LyricalContentfind.Text2(0).Text = "Bicycle"
Else
MsgBox("No words here fun boy!")

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

LyricalContentfind.Text2(0).Text = ""

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
Nov 5 '06 #1
Share this Question
Share on Google+
14 Replies


Expert 5K+
P: 8,434
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?
Nov 6 '06 #2

100+
P: 1,646
Line Input #1, strLine
GoSplit = Split(strGetWords, " ")

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

Dököll
Expert 100+
P: 2,364
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
Nov 7 '06 #4

100+
P: 1,646
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
Nov 7 '06 #5

Expert 5K+
P: 8,434
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...
Nov 7 '06 #6

Dököll
Expert 100+
P: 2,364
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
Nov 8 '06 #7

Dököll
Expert 100+
P: 2,364
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(strGetWords, " ")

If InStrB(strGetWords$, "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(strGetWords$, "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 :-)
Nov 8 '06 #8

Expert 5K+
P: 8,434
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.
Nov 8 '06 #9

Dököll
Expert 100+
P: 2,364
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...
Nov 9 '06 #10

Dököll
Expert 100+
P: 2,364
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(strGetWords$, "train") <> 0 Then 'train is available, give me Trains

Text2(3).Text = "Trains"
Text4(1).Visible = 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(strGetWords$, "train") = 0 And InStrB(strGetWords$, "rain") <> 0 Then

Text4(1).Text = "Rain" ' Looking to pick up only "rain", thus to outputting "Rain"
Text2(3).Visible = 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
Nov 18 '06 #11

P: 2
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,development skill,how diagnosis the error,arrangment 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
Nov 18 '06 #12

100+
P: 1,646
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(strGetWords$, "train") <> 0 Then 'train is available, give me Trains

Text2(3).Text = "Trains"
Text4(1).Visible = 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(strGetWords$, "train") = 0 And InStrB(strGetWords$, "rain") <> 0 Then

Text4(1).Text = "Rain" ' Looking to pick up only "rain", thus to outputting "Rain"
Text2(3).Visible = 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?
Nov 18 '06 #13

Dököll
Expert 100+
P: 2,364
Where is this word 'Train' or 'Brain' coming from and where is the strGetwords string coming from?
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(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

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
Nov 26 '06 #14

Dököll
Expert 100+
P: 2,364
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:

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 27 '06 #15

Post your reply

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