Results 1 to 4 of 4

Thread: text files???

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Australia somewhere
    Posts
    2

    text files???

    I was wondering if someone could tell me how to read a text file and put it into an array?? the text file is something like :
    9
    bill
    8
    bill
    34
    john

    I need to read the file and then put the numbers in an array and the names into another.
    I know its probably simple but Im not as smart as the average bear!!! Please help

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    reading file into array sample

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim sArr() As String
    3.     Dim i As Integer
    4.     Open "C:\TEST.TXT" For Input As #1
    5.         sArr = Split(Input(LOF(1), 1), vbCrLf)
    6.     Close #1
    7.     For i = 0 To UBound(sArr())
    8.         Debug.Print sArr(i)
    9.     Next i
    10. End Sub
    -= a peet post =-

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Australia somewhere
    Posts
    2
    Thanx but I wanted to do it something like this

    Dim name As String
    Dim seat As String
    Dim i As Integer
    txtIndex = row & SeatNo

    Open "A:seat.txt" For Input As #1

    Do While Not EOF(1)

    Input #1, seat
    lstSeat.AddItem txtSeatNo
    ReDim Preserve CustSeat(0 To 71)

    txtSeatNo = seat

    Input #1, name
    lstName.AddItem txtName()
    'CustName.AddItem
    ReDim Preserve CustName(0 To 71)

    txtName() = CustName(0, 71)
    'i = i + 1

    Loop

    Close #1

    The array needs to be in a module

  4. #4
    Lively Member Maartin's Avatar
    Join Date
    Jan 2000
    Location
    Benoni, Gauteng, South-Africa
    Posts
    99
    just do what peet has done and then add the items to the lst controls after you've read the file. or into the arrays that you want to use and then onto the controls.
    Have Fun ;-)
    Maartin
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    if it ain't broke don't fix, rewrite it.
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

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