Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you create code to extract only some data from another program?

Status
Not open for further replies.

Pulp

MIS
Jul 22, 2002
18
US
I was wondering if someone could please tell me what kind of code would work so that I could take out only a few lines of data within a server log I'm working with. The data I want to extract all have one thing in common, they all have the letter "S" at the 38th character of their line. The rest of the lines within this log do not have an "S" at their 38th position. I was wondering if someone with a heart of gold could tell me how I could create a code in VB that extracts only the lines with the letter "S" at the 38th character of their line.

Thank you,
Pulp

 
Easily done!

First, create two string variables.
Read one line from the file, using ReadLine(), and set
the first string variable equal to it.
Use Mid() to extract a string one character long and
starting at the 38th character. Set this second
string variable equal to this (one-character-long)
string.
Then, IF (this second string) = "S", THEN
(Add the first string to the saved stuff)
Then, repeat if anything more.

 

Dim MyFileName As String, MyFileNumb As Integer
Dim TextLine As String

MyFileName = "path to file"
MyFileNumb = FreeFile

Open MyFileName For Input As #MyFileNumb

Do While Not EOF(MyFileNumb)

Line Input #MyFileNumb, TextLine

If Mid(TextLine, 38, 1) = "S" Then

'Found Character In This Line So Do your Processing Here

End If

Loop

Close #MyFileNumb


Good Luck
 
Thanks Alot You guys I'm gonna give it a try!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top