Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 239
Default Selactively read text file

Hi,
I am trying to read a text file and accept only selective portion of
the same.
Text file will be like this. 1st line is name, 2nd line is code.
madiya
122
raja
269
tata
222
hag
9897

I would like to get the code of the name I select in my variable.
Say If I assign my variable raja, I want to read the text file and get
269,
Similarly, for tata, I get 222 etc. which means find the name in text
file and return the next line
immediatly below the name.

So fat I have below code which reads entire text file.
Sub nametocodes()
Dim LineofText As String
i = 0
Open "C:\Codelist.txt" For Input As #1
Do While Not EOF(1)
i = i + 1
Line Input #1, LineofText
Debug.Print LineofText
Loop
Close #1
End Sub

Pl help me to get only required data from text file.

Regards,
Madiya
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Selactively read text file

Try this

So fat I have below code which reads entire text file.
Sub nametocodes()
Dim LineofText As String
SearchName = "raja"
i = 0
Open "C:\Codelist.txt" For Input As #1
Do While Not EOF(1)
i = i + 1
Line Input #1, LineofText
Debug.Print LineofText
if LineofText = SearchName then
Line Input #1, LineofText
SearchValue = Lineoftext
exit do
end if
Loop
Close #1
End Sub


"Madiya" wrote:

Hi,
I am trying to read a text file and accept only selective portion of
the same.
Text file will be like this. 1st line is name, 2nd line is code.
madiya
122
raja
269
tata
222
hag
9897

I would like to get the code of the name I select in my variable.
Say If I assign my variable raja, I want to read the text file and get
269,
Similarly, for tata, I get 222 etc. which means find the name in text
file and return the next line
immediatly below the name.

So fat I have below code which reads entire text file.
Sub nametocodes()
Dim LineofText As String
i = 0
Open "C:\Codelist.txt" For Input As #1
Do While Not EOF(1)
i = i + 1
Line Input #1, LineofText
Debug.Print LineofText
Loop
Close #1
End Sub

Pl help me to get only required data from text file.

Regards,
Madiya

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 239
Default Selactively read text file

On Oct 20, 3:57*pm, Joel wrote:
Try this

So fat I have below code which reads entire text file.
Sub nametocodes()
Dim LineofText As String
SearchName = "raja"
i = 0
Open "C:\Codelist.txt" For Input As #1
* Do While Not EOF(1)
* * i = i + 1
* * Line Input #1, LineofText
* * Debug.Print LineofText
* *if LineofText = SearchName then
* * * Line Input #1, LineofText
* * * SearchValue = Lineoftext
* * * exit do
* *end if
* Loop
Close #1
End Sub



"Madiya" wrote:
Hi,
I am trying to read a text file and accept only selective portion of
the same.
Text file will be like this. 1st line is name, 2nd line is code.
madiya
122
raja
269
tata
222
hag
9897


I would like to get the code of the name I select in my variable.
Say If I assign my variable raja, I want to read the text file and get
269,
Similarly, for tata, I get 222 etc. which means find the name in text
file and return the next line
immediatly below the name.


So fat I have below code which reads entire text file.
Sub nametocodes()
Dim LineofText As String
i = 0
Open "C:\Codelist.txt" For Input As #1
* Do While Not EOF(1)
* * i = i + 1
* * Line Input #1, LineofText
* * Debug.Print LineofText
* Loop
Close #1
End Sub


Pl help me to get only required data from text file.


Regards,
Madiya- Hide quoted text -


- Show quoted text -


Joel,
Thanks.
Madiya
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read text from a non-delimited text file? Phil Excel Programming 8 May 22nd 07 01:09 PM
How do you save an excel file to be read as IBM-type text file ? Dee Franklin Excel Worksheet Functions 2 October 10th 06 02:46 AM
read text file hallie Excel Programming 2 August 17th 04 01:00 PM
read text file hallie Excel Programming 1 August 17th 04 12:37 PM
Read text file jacob[_3_] Excel Programming 2 September 23rd 03 06:41 PM


All times are GMT +1. The time now is 04:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"