954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

import a text from notepad

Hello everybody,

how can i import a text from notepad to a text box?:rolleyes:

b.janahi
Newbie Poster
10 posts since Jun 2006
Reputation Points: 10
Solved Threads: 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
Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

i will try it
thanks 4 ur time

b.janahi
Newbie Poster
10 posts since Jun 2006
Reputation Points: 10
Solved Threads: 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:

b.janahi
Newbie Poster
10 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

Simply pass the variable or object to the sub

FName$ = commondialog1.filename
LoadTextBox FName$, Text1
Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You