473,898 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Left$ Function, Looping through

Dököll
2,364 Recognized Expert Top Contributor
Hiya, Partners!

I have been into it for 12 hours straight this week-end, my son is very unhappy. Looks like I am getting pretty close but need your help, Again. I will post my first Option/Solution, then the next through another post. Here it goes:

'PROPOSED SOLUTION 1
'Button below formats words in one column, the words however, are all
over the place
'I attemepted to use vbCrlf to enable LineFeed, no joy there.
'Well it gets me to the next line, the words are broken in pieces.
'The Big idea I have is to later have the application look through
Text6.Text using a simple function
'that'll grab exactly the words I want, thus 'GiveMeIt= Asc("Rain") something in that kind of a line, but at least what I want :-)
Expand|Select|Wrap|Line Numbers
  1. Private Sub ClonegetLength_Click()
  2. Open App.Path + "\Test.txt" For Output As #1 
  3. 'file is opened as in Print to get rid of quotes, just learned this :-)
  4. Print #1, Text6.Text 
  5. 'this should hold enough text, wouldn't you say?
  6.  
  7. Close #1 'close, then reopen below
  8.  
  9. Dim strGetWords As String
  10.  
  11.  
  12. FileName = "\Test.txt" 'here is our fancy text file again
  13. f = FreeFile
  14. Open App.Path + FileName For Input As #1
  15. 'this time we want to, not only see what's inside, we will ATTEMPT to 
  16. format
  17.  
  18. Do While Not EOF(f) 'all the way 'til we're happy
  19. Line Input #1, strGetWords
  20.  
  21. i = False 'wonderful looping mechanism, allows us to chop it up and 
  22. fromat,
  23. 'set to false (Be sure to do this!)
  24.  
  25. Do Until i = True
  26.  
  27. intLength = Len(strGetWords) ' the first time in we read the whole 
  28. piece
  29. If intLength <= 8 Then 'here is the trick I have been talking about, 
  30. I wanted to add
  31. 'to give it the highest length specific to words the if statement 
  32. will hope to grab
  33. 'as one example, database. But ladies and gentlemen, my format will 
  34. attempt to break down
  35. 'database depending on its position. For now we'll move on, we'll 
  36. get to that later
  37. Exit Do 'I got what I wanted, 8 chars for database
  38. End If
  39. strBringIn = strBringIn & Left(strGetWords, 8) & vbCrLf
  40. 'I am reading left here to make sure I get Train, not rain
  41. strGetWords = Right(strGetWords, intLength - 8)
  42. ' I also want to read right to allow others words to be tucked under
  43. 'previous words, having 10 chars
  44. Loop 'do until Loop ends here
  45.  
  46. Text6.Text = strBringIn 'add the formatted results in
  47. Loop ' found end of file, may or may not search again, provided we're 
  48. happy...
  49.  
  50. End Sub 'that's it for us...Below are the results of our positioning of 
  51. these few words
  52.  
  53.  
  54.  
'FIRST THE TEXT ADDED IN Text6.Text, before ClonegetLength is pressed:

'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...
'Oh! here is what my Like operator atttempt loked like: database is
added here just to see how it's
'getting picked up elsewhere



'SECONDLY, HERE IS THE FORMAT RETURED:

's well f
'rom my d
'atabase. (I lost my d here)
'Oh! here
' is what
' my Like
' operato (there is a space in here, Ltrin will take care of it but the
least of our problems right now)
'r atttem
'pt loked
' like:
'Database (looks good here)
' is adde
'd here j
'ust to s
'ee how i
'getting
'picked u
'p elsewh


'REMARKS: I need my format to read whole words, then drop/tuck them
under one another to resamble:

'well
'from
'my
'database.
'Oh!
'here
'is
'what
'my
'Like
'operator
'atttempt


' I will need to repeat do until to record additional characters I
want, if I need bus for instance

'Do Until i = True

'intLength = Len(strGetWords ) ' the first time in we read the whole
piece
'If intLength <= 3 Then 'here is the trick I have been talking
about, I wanted to add...

'Exit Do 'I got what I wanted, 8 chars for database
'End If
'strBringIn = strBringIn & Left(strGetWord s, 3) & vbCrLf
'strGetWords = Right(strGetWor ds, intLength - 3)
'Loop 'do until Loop ends here

'Text6.Text = strBringIn 'add the formatted results in
'Loop ' found end of file, may or may not search again, provided we're
happy...



In a bit (for Option/Solution 2 forthcoming)
Jan 7 '07 #1
22 2178
willakawill
1,646 Top Contributor
Hi D, why don't you use Split() ??
Jan 7 '07 #2
Dököll
2,364 Recognized Expert Top Contributor
Hi D, why don't you use Split() ??
Hey Will, Split did not seem to work when I used InstrB:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Line input, strGetWords
  3.  
  4. GoSplit=Split(strGetWords, " ")
  5.  
  6. If InstrB(strGetWords, "Rain") <> 0 Then
  7.  
  8. this and that here...
  9.  
  10. End If
  11.  
  12.  
when Train was found in the text, rain was pulled up as well :-(

I thought, forget about it, move on with my life.

Do you think now that I am adding everything in one column, it might work?

D
Jan 7 '07 #3
Dököll
2,364 Recognized Expert Top Contributor
Hello again, Will!

Tried Split with the new code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim GoSplit As Variant
  3. Dim strGetWords As String
  4.  
  5.  
  6. FileName = "\Test.txt"  'here is our fancy text file again
  7. f = FreeFile
  8. Open App.Path + FileName For Input As #1
  9. 'this time we want to, not only see what's inside, we will ATTEMPT to 
  10. format
  11.  
  12. Do While Not EOF(f) 'all the way 'til we're happy
  13. Line Input #1, strGetWords
  14. GoSplit=Split(strGetWords, " ")
  15.  
  16. i = False 'wonderful looping mechanism, allows us to chop it up and 
  17. fromat,
  18. 'set to false (Be sure to do this!)
  19.  
  20.  
Got nada, same deal...

Making a mad dash for it, perhaps another 12 hours will do thr trick :-)

D
Jan 7 '07 #4
willakawill
1,646 Top Contributor
Hello again, Will!

Tried Split with the new code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim GoSplit As Variant
  3. Dim strGetWords As String
  4.  
  5.  
  6. FileName = "\Test.txt"  'here is our fancy text file again
  7. f = FreeFile
  8. Open App.Path + FileName For Input As #1
  9. 'this time we want to, not only see what's inside, we will ATTEMPT to 
  10. format
  11.  
  12. Do While Not EOF(f) 'all the way 'til we're happy
  13. Line Input #1, strGetWords
  14. GoSplit=Split(strGetWords, " ")
  15.  
  16. i = False 'wonderful looping mechanism, allows us to chop it up and 
  17. fromat,
  18. 'set to false (Be sure to do this!)
  19.  
  20.  
Got nada, same deal...

Making a mad dash for it, perhaps another 12 hours will do thr trick :-)

D
Split will give you an array of the words in the string
You can check each of the elements for the word you are searching with
Expand|Select|Wrap|Line Numbers
  1. For lp = 0 To UBound(GoSplit)
  2. If InstrB(GoSplit(lp), "Rain") <> 0 Then
Jan 7 '07 #5
Dököll
2,364 Recognized Expert Top Contributor
Hey, thanks for your quick response. Is GoSplit a Variant here or a String?

Expand|Select|Wrap|Line Numbers
  1.  
  2. For lp = 0 To UBound(GoSplit)
  3. If InstrB(GoSplit(lp), "Rain") <> 0 Then
  4.  
  5.  
Dököll
Jan 8 '07 #6
willakawill
1,646 Top Contributor
Hey, thanks for your quick response. Is GoSplit a Variant here or a String?

Expand|Select|Wrap|Line Numbers
  1.  
  2. For lp = 0 To UBound(GoSplit)
  3. If InstrB(GoSplit(lp), "Rain") <> 0 Then
  4.  
  5.  
Dököll
It is a variant that becomes an array of strings
Jan 8 '07 #7
Dököll
2,364 Recognized Expert Top Contributor
Greetings, Will!
What happens to strGetWords, I cannot get it to work:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim GoSplit As Variant
  3. Dim strGetWords As String
  4. Dim lp As Integer
  5.  
  6.  
  7. FileName = "\Test.txt"  'here is our fancy text file again
  8. f = FreeFile
  9. Open App.Path + FileName For Input As #1
  10. 'this time we want to, not only see what's inside, we will ATTEMPT to 
  11. format
  12.  
  13. Do While Not EOF(f) 'all the way 'til we're happy
  14. Line Input #1, strGetWords
  15. GoSplit=Split(strGetWords, " ")
  16.  
  17. For lp = 0 To UBound(GoSplit)
  18. If InStrB(GoSplit(lp), "Rain") <> 0 Then
  19. Text1.Text = GoSplit
  20. End If
  21. Next lp
  22.  
  23.  
I get a type mismatched error. If GoSplit has taken over for strGetWords, won't it still grab Rain from Train. strGetWords has already gone into the file to find stuff. Should lp be in the plave of strGetWords as such:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim GoSplit As Variant
  3. Dim lp as Integer
  4.  
  5. FileName = "\Test.txt"  'here is our fancy text file again
  6. f = FreeFile
  7. Open App.Path + FileName For Input As #1
  8. 'this time we want to, not only see what's inside, we will ATTEMPT to 
  9. format
  10.  
  11. Do While Not EOF(f) 'all the way 'til we're happy
  12. Line Input #1, lp
  13. GoSplit=Split(lp, " ")
  14.  
  15. For lp = 0 To UBound(GoSplit)
  16. If InStrB(GoSplit(lp), "Rain") <> 0 Then
  17. Text1.Text = GoSplit
  18. End If
  19. Next lp
  20.  
  21.  
I am up early, perhaps I am missing a beat :-)
Jan 8 '07 #8
willakawill
1,646 Top Contributor
Expand|Select|Wrap|Line Numbers
  1. Text1.Text = GoSplit(lp)
You can also check that length of GoSplit(lp) is the same as the search string length so you will not get Train instead of rain. As you are checking only single words you should use StrComp

Expand|Select|Wrap|Line Numbers
  1. If StrComp(GoSplit(lp), "rain", 1) = 0 Then
  2. 'this is an exact match and is not case sensitive
  3. End If
Jan 8 '07 #9
Dököll
2,364 Recognized Expert Top Contributor
Will,

I think we've got it, just added a note to Killer about this. vbTextCompare is now working. When you mentioned it, I wrote:

[code]
If InStr(strGetWor ds, "use", vbTextCompare) <> 0 Then

it did not work, so I gave up...

End If

[\CODE]

It's likely you saw my other post (Vol 2), this is the one that is doing wha I hoped to achieve:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub GtWords_Click()
  3. Dim strGetWords As Long
  4. strGetWords = InStr(1, Text6(0).Text, " " & Text1.Text & " ", vbTextCompare) 
  5. If strGetWords = 0 Then
  6. Text1.Text = "Steve says no way"
  7. Else
  8. Text6(0).SetFocus
  9. Text6(0).SelStart = strGetWords
  10. Text6(0).SelLength = Len(Text1.Text)
  11. End If
  12. End Sub
  13.  
  14.  
I appreciate your help and assitance, Will...

Stay tuned!

Dököll
Jan 10 '07 #10

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

Similar topics

8
4067
by: kaptain kernel | last post by:
i've got a while loop thats iterating through a text file and pumping the contents into a database. the file is quite large (over 150mb). the looping causes my CPU load to race up to 100 per cent. Even if i remove the mysql insert query and just loop through the file , it still hits 100 per cent CPU. This has the knock on effect of slowing my script down so that mysql inserts are occuring every 1/2 second or so.
2
2936
by: Steven Burn | last post by:
..:: The Specs: MS Access 2000 (host charges extra for SQL/MySQL) MS Windows Server 2003 (prod) / MS XP SP1 (dev) ..:: The setup: The database has been setup with two tables; tblDownloads
1
5397
by: Diva | last post by:
Hi, I have a data grid in my application. It has 20 rows and I have set the page size as 5. I have a Submit button on my form and when I click on Submit, I need to loop through the rows in the datagrid. Using the items collection just gives me the 5 rows that are displayed on the screen. Is there any way of looping through all the rows in the grid?
7
1864
by: fasanay | last post by:
Hi everybody I have got the following PHP code which I am trying to convert to ASP any help will be appreciated...I have done most of it but I cant find a replace function for Unset in asp which will discard the variable alltogether... if ($categoryid == "all") { $sql = "SELECT * FROM products where shopinspection=$shopinspection"; unset($HTTP_POST_VARS); unset($HTTP_POST_VARS);
5
4012
by: johnb41 | last post by:
I need to loop through a bunch of textbox controls on my form. The order of the loop is very important. For example, the top one must be read first, then the one below it, etc. My first attempt was to put the controls in a Panel, and then loop through the controls collection of the panel. What happened is it read the controls from the bottom of my form to the top! So I tried a more manual process. I named each textbox like this:
7
5478
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I loop through the filtered GridView to identify the selected rows and assemble some XML to be sent to a stored proc. The problem I have is that when looping through the GridView, it doesn't
18
1788
Dököll
by: Dököll | last post by:
Here it goes again, thanks again for responding: 'PROPOSED SOLUTION 2 'I wanted to not creatre a file and just read straight out of Text6.Text and 'output my findings in legal text boxes 'I also needed/had to, because OF LACK OF EXPERIENCE, figure out wheter my finding was true first 'before out putting, thus Text1.Text = Text6.SelLength = Len(strGetWords) was born 'when true, Text2.Text = strGetWords 'Here is the problem, I searched...
3
3735
by: Andy | last post by:
Hello, I have the following situation: Thread A is allocating a dataset, doing some low-level calculations and storing a pointer to the dataset in a std::list via push_back. Thread B should retrieve the pointer to the first dataset in the list, remove it from the list, and do some high level analysis. The problem now is, how do I efficiently retrieve the pointer?
10
1292
by: Charlie Brown | last post by:
I am using something like the following function to loop through a recipe program I am working on. As I was writing it, I starting thinking this isn't going to work at all... but not I'm not so sure. Will this code work, or cause me problems? Private Sub DoSomething() Dim viCount As Integer = _varianceList.Count For i As Integer = 0 To viCount - 1 Dim vi As ProductionVarianceItem = _varianceList(i) vi.ProductionOut =...
0
9993
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9841
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10858
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10484
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9662
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7188
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5882
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.