Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 131,772 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,095 people online right now. Registration is fast and FREE... Join Now!




open text file and dump text into textbox

 
Reply to this topicStart new topic

open text file and dump text into textbox

smcmanus
post 9 Oct, 2008 - 08:34 AM
Post #1


New D.I.C Head

*
Joined: 9 Oct, 2008
Posts: 11

I want to put my data from the file into the textbox and not have to create a variable. I cannot get it to work? Thanks.

This CODE does not work:
CODE

Private Sub Reading_Click()
Open "c:\My Documents\sample.txt" For Input As #1
Input #1, Text1.Text
Close #1
End Sub



This CODE Works:
CODE


Private Sub Reading_Click()
Dim variable1 As String
Open "c:\My Documents\sample.txt" For Input As #1
Input #1, variable1
Text1.Text = variable1
Close #1
End Sub


Mod edit - Added code tags.
User is offlineProfile CardPM

Go to the top of the page

Reverand Dave
post 9 Oct, 2008 - 11:40 AM
Post #2


D.I.C Regular

Group Icon
Joined: 27 Jul, 2008
Posts: 373



Thanked 2 times

Dream Kudos: 50
My Contributions


Try something like this

CODE


Dim fso, MyFile,  FileP, txt
FileP = "c:\My Documents\sample.txt"

txt = text1.text

   Set fso = CreateObject("Scripting.FileSystemObject")
   Set MyFile = fso.CreateTextFile(FileP, True)
   MyFile.writeLine (txt) 'This is where you enter your string for writing the file.
                                  'Add multiple lines for each line you want in your text file
   MyFile.show 'Or you can use .close



I hope this helps
User is offlineProfile CardPM

Go to the top of the page

Reverand Dave
post 9 Oct, 2008 - 01:44 PM
Post #3


D.I.C Regular

Group Icon
Joined: 27 Jul, 2008
Posts: 373



Thanked 2 times

Dream Kudos: 50
My Contributions


QUOTE(Reverand Dave @ 9 Oct, 2008 - 12:40 PM) *


CODE


Dim fso, MyFile,  FileP, txt
FileP = "c:\My Documents\sample.txt"

txt = text1.text

   Set fso = CreateObject("Scripting.FileSystemObject")
   Set MyFile = fso.CreateTextFile(FileP, True)
   MyFile.writeLine (txt) 'This is where you enter your string for writing the file.
         'Add multiple lines for each line you want in your text file
   MyFile.show 'Or you can use .close




My bad, I should mention that for this line

CODE


   Set MyFile = fso.CreateTextFile(FileP, True)



the True is to overwrite an existing file.

I suppose you could also try using using a .open command on there as well if you don't want to overwrite the existing file.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 01:54PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month