Reading text file

I have a text file. What I want to do is to read every 4th line in that file and store it in a variable. Please tell me how I can do this using VB?

Thanks in advance
RR
r_nairAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

crazymanCommented:
dim intFile as freefile
dim strtemp as string
dim x as integer
open "c:\whatever.txt" for input as #intfile
do while not eof(intfile)
    x=x+1
   line input #intfile,strTemp
   if x = 4 then
       msgbox strtemp
       x=0
   end if
loop
close #intfile
0
crazymanCommented:
the message box will be each 4th line of text
0
crazymanCommented:
Forgot

IntFile=FreeFile

before the open statement
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

danlevansCommented:
r_nair

Private Sub Command1_Click()
  Dim intfile As String
  Dim l As String
  Dim ctr As Integer
  Dim urvariable As String
  ctr = 1
  intfile = FreeFile
  Open "c:\urfile" For Input As #intfile
  Do Until EOF(intfile)
    Line Input #intfile, l
    If ctr = 4 Then
        urvariable = l
        ctr = 1
    Else
        ctr = ctr + 1
    End If
  Loop
  Close #intfile
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
r_nairAuthor Commented:
Hi
It gives me an error "User defined type
not defined" at the line Dim Intfile As freefile


Thanks
RR
0
BarryTiceCommented:
r_nair: This loads your lines into the strData() array. I warn you that it is not what a lot of people would consider best programming, though, because it leaves strData(0) empty. Other than that, it should do the trick for you. -- b.r.t.

dim intFile as Integer
dim strData() as String
dim intCount as Integer
dim intCount2 as Integer

intFile = FreeFile
intCount = 1
intCount2 = 1
redim strData(1)

Open "C:\FileName.txt" for input as #intFile
Do While Not EOF(intFile)
    Line Input #intFile, strData(intCount)
    intCount2 = intCount2 + 1
    If intCount2 Mod 4 = 0 Then
        intCount = intCount + 1
        Redim Preserve strData(intCount)
    End If
Loop
Close #intFile

redim Preserve strData(intCount - 1)


0
crazymanCommented:
Dim intfile as integer
intfile=freefile
0
crazymanCommented:
It was a typo
it is an integer
0
BarryTiceCommented:
r_nair

Crazyman meant to say:

Dim intFile as Integer
intFile = FreeFile
0
BarryTiceCommented:
Sorry Crazyman. You beat me to the correction.
0
crazymanCommented:
DanLevans you have dimmed

>>dim IntFile as string <--typo?
0
danlevansCommented:
oops I was trying to get ahead of you guys :-)
0
crazymanCommented:
LOL :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.