|
-
Aug 30th, 2000, 09:44 AM
#1
Thread Starter
Fanatic Member
I have a file (20 Lines long), and I want to input one of the lines into a text box. How do I do that!
Visual Basic 6.0
Visual C++ 5
Delphi 5

-
Aug 30th, 2000, 09:52 AM
#2
Frenzied Member
play with that
Code:
Dim MyChar
Open "TESTFILE" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
MyChar = Input(1, #1) ' Get one character.
Debug.Print MyChar ' Print to the Immediate window.
Loop
Close #1 ' Close file.
play with that to get one line
-
Aug 30th, 2000, 09:55 AM
#3
Frenzied Member
here is for line
Code:
Dim MyStringOpen "TESTFILE" For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Loop until end of file.
Input #1, MyString' Read data into variables.
msgbox "Line is " & MyString
Loop
Close #1 ' Close file
-
Aug 30th, 2000, 10:22 AM
#4
Thread Starter
Fanatic Member
What if I want a specific line, let's say line 6. I want to get everything on line six without getting any thing from the lines before that or after that.
Visual Basic 6.0
Visual C++ 5
Delphi 5

-
Aug 30th, 2000, 10:27 AM
#5
Frenzied Member
add a counter
Code:
Dim MyChar
dim counter as integer
Dim MyStringOpen "TESTFILE" For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Loop until end of file.
counter = counter + 1
if counter = 6 then Input #1, MyString' if 6 gives you line 7, type 5, so on and so forthLoop
Close #1 ' Close file
-
Aug 30th, 2000, 11:00 AM
#6
Thread Starter
Fanatic Member
Check your code, that doesn't give me anything!!!
Visual Basic 6.0
Visual C++ 5
Delphi 5

-
Aug 30th, 2000, 11:24 AM
#7
_______
<?>
Code:
Option Explicit
Private Sub Command1_Click()
Dim myLine As String, myFile As String
Dim intNum As Integer, myCounter As Integer
Dim i As Integer
intNum = FreeFile
myFile = "c:\my documents\myfile.txt"
Open myFile For Input As intNum
Do While Not EOF(intNum)
Line Input #intNum, myLine
i = i + 1
If i = 6 Then
MsgBox myLine
Exit Do
End If
Loop
Close intNum
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 30th, 2000, 11:31 AM
#8
Frenzied Member
Code:
Dim s As String
Dim c As Integer
Dim fileNum As Integer
fileNum = FreeFile
Open "f:\test.txt" For Input As #fileNum
Do Until EOF(1)
c = c + 1
If c = 7 Then
MsgBox s
Exit Sub
End If
Input #fileNum, s
Loop
Close #fileNum
tested that
n it works
-
Aug 30th, 2000, 12:00 PM
#9
Thread Starter
Fanatic Member
What if i wanted it to choose a random line everytime
Visual Basic 6.0
Visual C++ 5
Delphi 5

-
Aug 30th, 2000, 12:26 PM
#10
Frenzied Member
then randomize where the 7 is
instead put ((20 * Rnd) + 1)
that will give you random num between 1 and 20
-
Aug 30th, 2000, 12:33 PM
#11
_______
<?>
Code:
'change it here
dim myRandom as integer
Randomize
myRandom = int(Rnd*50)'50 could be any number
'
If i = myRandom Then
MsgBox myLine
Exit Do
End If
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 30th, 2000, 01:12 PM
#12
transcendental analytic
have a look at your other thread, should give you the lines in an array wherefrom you can pick any lines:
http://forums.vb-world.net/showthrea...threadid=28550
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
|