|
-
Nov 10th, 2000, 01:56 AM
#1
Thread Starter
New Member
How can i read only one line or specific line of a text file?
-
Nov 10th, 2000, 02:45 AM
#2
New Member
Public Sub ReadDetails(IsFilename As String)
' read the text from file
Set fso = CreateObject("Scripting.FileSystemObject")
Set tem = fso.OpenTextFile(IsFilename)
Do Until am = "end" Or am = "End" Or am = "END"
am = tem.readline
Loop
end Sub
This will read one line at a time, and in this spesific routine, it will stop when it hits the word "END" or "end" or "End". IsFilename = full path and filename.
hope this helps.
-
Nov 10th, 2000, 02:51 AM
#3
Replace the bold number with whatever line number you want to get.
Code:
Private Sub Command1_Click()
Dim strLine As String
Dim iLine As Integer
iLine = 0
iFile = FreeFile
Open "C:\MyText.txt" For Input As iFile
Do While Not EOF(iFile)
Line Input #iFile, strLine$
iLine = iLine + 1
If iLine = 50 Then MsgBox strLine$: Exit Sub
Loop
Close #iFile
End Sub
-
Nov 10th, 2000, 02:52 AM
#4
Thread Starter
New Member
what i really need is to get a specific line in a text file and let it equal a varible. example: i need line 5 to go into CNsme snf line 10 to go into gender ( cname and gender being varibles)
-
Nov 10th, 2000, 07:01 AM
#5
transcendental analytic
Here's what you can do, open in binary and read the whole file into a buffer, then split it into lines and read any line into any variable anytime:
Code:
Dim buffer as string, lines() as string
Open File for binary as 1
buffer=space(lof(1))
get#1,,buffer
lines=split(buffer,vbcrlf)
CNsme = lines(4)
gender = lines(9)
close 1
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|