2
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by Comatose
0

Stick This in a module (or in the declarations of the form)

Public Sub LoadTextBox(NotepadFile$, XTextBox As TextBox)
Dim chk As String
Dim hld As String
If Dir(NotepadFile$, vbNormal) = "" Then
    MsgBox "File Not Found: " & NotepadFile$
    Exit Sub
End If

Open NotepadFile$ For Input As #1
Do Until EOF(1)
    Line Input #1, chk
    hld = hld & chk & vbNewLine
Loop
Close #1

hld = Left(hld, Len(hld) - 2)
XTextBox.Text = hld
End Sub

Then call it like this (from a button, or on form load, or whatever)

FName$ = "c:\path2yourfolder\notepadfile.txt"
LoadTextBox FName$, Text1
0

Yes i tried this code it works if i know the path of the text file but what if opened the file using common dialog (open window) how can i know the path and how can i get the text?"


:eek:

0

Simply pass the variable or object to the sub

FName$ = commondialog1.filename
LoadTextBox FName$, Text1
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.