Solved!Lines in a txt file

New to FreeBASIC? Post your questions here.
STBasic
Posts: 156
Joined: Feb 17, 2006 11:51
Location: Manchester, England

Solved!Lines in a txt file

Postby STBasic » Apr 22, 2013 7:32

I have got a txt file with 20 names in it , and when i load it in how can i check to see how many names are in the list.

here is the loading code

Code: Select all

        Dim lf As String
        dim as integer l,icount=0
        dim as string T(1 to 24)
   Cls
   ListDirectory()
   Locate 20,5:Print "Enter name of file to load"
   Locate 20,32:Line Input lf
   If lf="" Then End
   Open lf For Input As #1
   For l=1 To 24
      Input #1,T(l)
      'Print T(l)
       icount = icount +1   
   Next
   Close #1


in the for line i have used 24 but i need to know if there are any more names in the text file
Last edited by STBasic on Apr 23, 2013 11:18, edited 1 time in total.
I3I2UI/I0
Posts: 90
Joined: Jun 03, 2005 10:39
Location: Germany

Re: Lines in a txt file

Postby I3I2UI/I0 » Apr 22, 2013 8:04

Hi STBasic

Code: Select all

Dim As String filename, lf="main.txt"
filename = Dir("*.exe")

Open lf For Output As #1
Do While Len(filename)
  Print #1, filename
  filename = Dir()
Loop
Close #1

Dim As String t()
Dim As Integer i
Open lf For Input As #1
Do until EOF(1)
  i+=1
  ReDim t(i)
  Input #1,t(i)
  ? i,t(i)
Loop
Close #1
Sleep
STBasic
Posts: 156
Joined: Feb 17, 2006 11:51
Location: Manchester, England

Re: Lines in a txt file

Postby STBasic » Apr 22, 2013 8:25

I3I2UI/I0 wrote:Hi STBasic

Code: Select all

Dim As String filename, lf="main.txt"
filename = Dir("*.exe")

Open lf For Output As #1
Do While Len(filename)
  Print #1, filename
  filename = Dir()
Loop
Close #1

Dim As String t()
Dim As Integer i
Open lf For Input As #1
Do until EOF(1)
  i+=1
  ReDim t(i)
  Input #1,t(i)
  ? i,t(i)
Loop
Close #1
Sleep


Thanks so much
STBasic
Posts: 156
Joined: Feb 17, 2006 11:51
Location: Manchester, England

Re: Lines in a txt file

Postby STBasic » Apr 22, 2013 8:54

With the above code how do i print in another sub, i can only print the names in do..loop code it will not print from the get name sub proc.
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: Lines in a txt file

Postby petan » Apr 22, 2013 10:03

STBasic
Posts: 156
Joined: Feb 17, 2006 11:51
Location: Manchester, England

Re: Lines in a txt file

Postby STBasic » Apr 22, 2013 10:11

Yes i have solved this i put the wrong array in sorry again

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 4 guests