borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (converting Column number to letters)Next Topic (Lining up colums and rows) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Find in txt file to txt1.text
Poster Message
sumesh11
Level: Protégé

Registered: 06-10-2005
Posts: 4

icon Find in txt file to txt1.text

hi i have a huge txt file
Acct= 1452           Name= Mahesh
Book=124856

now i have a huge txt file which has this data and i want to find a particuler Acct: and it should give me the Name and Book

any ideas how to fo that in vb

plz help if can

sumesh

Private Sub Command1_Click()
Dim txtvar As String
Dim file As Integer
Dim b As String

file = FreeFile

Open "C:\a.txt" For Input As #file
Do Until EOF(file)
Line Input #file, Ln
If InStr(Ln, Text1.Text) > 0 Then
      MsgBox "String Found"
      Text2.Text = Text1.Text
Else
      MsgBox "String Not Found"
      Text2.Text = ""
End If
Loop
Close #file
End Sub


hi got the code but now if it finds the account no then it should show me the Name and book name in the text box and exit the program

if you gave any idea about it
the txt files contains data like the following
Acct= 1452           Name= Mahesh
Book=124856

Acct= 1455           Name= Mahesh1
Book=12456

Acct= 1456           Name= Mahesh2
Book=124856
Acct= 1457           Name= Mahesh3

Book=1224856
Acct= 1458           Name= Mahesh4
Book=1245856

Acct= 1485           Name= Mahesh5
Book=1248856
Acct= 1432           Name= Mahesh6
Book=1248506
Acct= 1448           Name= Mahesh7
Book=12485617
Acct= 1412           Name= Mahesh8
Book=1248356
Acct= 1413           Name= Mahesh9
Book=124836
Acct= 1472           Name= Mahesh0
Book=1244856
Acct= 1451           Name= Mahesh11
Book=1248556
Acct= 1476           Name= Mahesh12
Book=1248576
Acct= 1477           Name= Mahesh13
Book=124856





[Edited by sumesh11 on 12-10-2005 at 04:56 PM GMT]

10-10-2005 at 03:50 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: Find in txt file to txt1.text

Hi,
Can you post up a sample text file pls?
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

10-10-2005 at 06:20 PM
View Profile Send Email to User Show All Posts | Quote Reply
TJ_01
Level: VB Lord


Registered: 24-08-2005
Posts: 320
icon Re: Find in txt file to txt1.text

If i am correct. I posted this code in your previous topic about .txt file. Check this out. http://www.andreavb.com/forum/viewtopic_6087.html

This code search a text on .txt file depends on the keyword you entered. I suggest, if your reading a huge file, why dont use database instead of .txt file. I also suggest that you read the .txt file horizontally depends on the format that is why stickleprojects is asking for a sample text file to see the format.

Private Sub Command1_Click()
Dim txtvar As String
Dim file As Integer
Dim b As String

file = FreeFile

Open "C:\a.txt" For Input As #file
Do Until EOF(file)
Line Input #file, Ln
If InStr(Ln, Text1.Text) > 0 Then
      MsgBox "String Found"
      Text2.Text = Text1.Text
Else
      MsgBox "String Not Found"
      Text2.Text = ""
End If
Loop
Close #file
End Sub


SORRY TO crosspost stickleprojects  




HTH..
















[Edited by TJ_01 on 11-10-2005 at 02:58 AM GMT]

____________________________
Im JAMES  

11-10-2005 at 02:51 AM
View Profile Send Email to User Show All Posts | Quote Reply
sumesh11
Level: Protégé

Registered: 06-10-2005
Posts: 4
icon Re: Find in txt file to txt1.text

hi ya you had the code but the nest step i need to get the book and the name of the person


if that possible

12-10-2005 at 04:57 PM
View Profile Send Email to User Show All Posts | Quote Reply
TJ_01
Level: VB Lord


Registered: 24-08-2005
Posts: 320
icon Re: Find in txt file to txt1.text

Can you give us a sample format of your text file containing this information and see what i can do? I find your question very interesting and i want to try.  

____________________________
Im JAMES  

13-10-2005 at 01:22 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Find in txt file to txt1.text
Previous Topic (converting Column number to letters)Next Topic (Lining up colums and rows) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder