Results 1 to 2 of 2

Thread: Text file operation..

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2004
    Posts
    18

    Text file operation..

    Ok, let's say I have a variable named Word.

    Lets say word's value is 30

    I have a txt file with 40 words in it
    I want to add to a txtbox the 30th word (word's value)

    Is there a way to do it?
    Later, buddies.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Assuming that each line in the TextFile has a CarriageReturn, then like:
    VB Code:
    1. Option Explicit
    2.  
    3. Dim strArr() As String
    4.  
    5. Private Sub Form_Load()
    6. On Error GoTo Err_Handler
    7.  
    8.     'Open and load the Array with the Text File
    9.     Open App.Path & "\TextFile.txt" For Input As #1
    10.         strArr = Split(Input(LOF(1), 1), vbCrLf)
    11.     Close #1
    12.  
    13. Exit Sub
    14.  
    15. Err_Handler:
    16.     MsgBox "Number: " & Err.Number & vbCrLf & _
    17.     "Description: " & Err.Description, vbOKOnly + vbInformation, "File I/O Error"
    18. End Sub
    19.  
    20. Private Sub Command1_Click()
    21.     'Display the Data specified by Line number
    22.     MsgBox strArr(Text1.Text) + 1
    23. End Sub




    Bruce.

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