Results 1 to 12 of 12

Thread: File Input

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Angry

    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


  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    Talking 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

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    Talking 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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Red face

    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


  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Thumbs down

    Check your code, that doesn't give me anything!!!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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

  8. #8
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    Talking

    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

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    What if i wanted it to choose a random line everytime
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  10. #10
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    then randomize where the 7 is
    instead put ((20 * Rnd) + 1)
    that will give you random num between 1 and 20

  11. #11
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>


    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

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
  •  



Click Here to Expand Forum to Full Width