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

searching a text file

175 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub readFile()
  3.  
  4.     Open "example.txt" For Input As #1
  5.  
  6.     Dim sInputData As String
  7.  
  8.     While Not EOF(1)
  9.  
  10.         Line Input #1, sInputData   
  11.  
  12.         If InStr(1, sInputData, "word") Then
  13.  
  14.             tbDataIn = tbDataIn & vbCrLf & sInputData
  15.  
  16.         End If
  17.  
  18.     Wend
  19.  
  20.     Close #1
  21.  
  22.  
this is how I'm reading a file basically. I'm curious if it's possible to search a file with text such as

___AAA
111
222
333
___BBB
333
222
___CCC
555

(the underscores are there to show a space)
...and what I want to do, is read that data in, and search for "AAA" for example (which isn't a problem), but when I find what i'm searching for, I want to pull the next lines out with it UNTIL i get to another line that starts with a space. So, if i search for "AAA", the result would be...

AAA
111
222
333
Feb 27 '07 #1
2 1283
Killer42
8,435 Expert 8TB
Just set a flag when you find your starting line (AAA), then clear the flag or exit your loop when you see the ending line. Something like...
Expand|Select|Wrap|Line Numbers
  1. Start Loop
  2.   Get line from file
  3.   If flag is set Then
  4.     If Line starts with space Then
  5.       Clear Flag (or exit loop)
  6.     Else
  7.       Process this line
  8.     End If
  9.   Else
  10.     If AAA Then
  11.       Set Flag
  12.     End If
  13.   end If
Disclaimer: The above is not valid Visual Basic syntax. :)
Feb 27 '07 #2
after u got the searched string then
code:
do
read next line
loop until (mid(line,1,1)=" ") ' u can read till another line starts with " "
Feb 28 '07 #3

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

Similar topics

3
by: hivie | last post by:
I have a problem that is causing me problems. I have a text file that stores 5 lines of crap (stuff that I dont need( for the user only)). After that there is data that is in three columns...
4
by: Michi | last post by:
I was wondering what the best solution is for making large numbers of TEXT (or BLOB?) fields searchable. For example, if I have a forum, what is the best way to be able to search for specific...
3
by: Paul H | last post by:
I have a text file that contains the following: ******************** __StartCustomerID_41 Name: Fred Smith Address: 57 Pew Road Croydon
1
by: Bud Dean | last post by:
I need to search files for given text. In particular, I'm searching dll's, exe's, asp, aspx and html pages. I am having difficulty converting the byte arrays to strings. The following code...
2
by: angus | last post by:
hello everybody, i'm having some problems searching a text file and then deleting the line. since i used fileopen(), i can use the eof() function to loop through the file, searching for the...
5
by: robinsiebler | last post by:
I have a batch of files that I am trying to search for specific text in a specific format. Each file contains several items I want to search for. Here is a snippet from the file: .......
7
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search...
4
by: Hunk | last post by:
Hi I have a binary file which contains records sorted by Identifiers which are strings. The Identifiers are stored in ascending order. I would have to write a routine to give the record given...
3
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a...
12
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.