4 Replies - 20104 Views - Last Post: 10 February 2013 - 10:48 AM Rate Topic: -----

#1 smcmanus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 09-October 08

open text file and dump text into textbox

Post icon  Posted 09 October 2008 - 09:34 AM

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:
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:

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.

Is This A Good Question/Topic? 0
  • +

Replies To: open text file and dump text into textbox

#2 Reverand Dave  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 375
  • Joined: 27-July 08

Re: open text file and dump text into textbox

Posted 09 October 2008 - 12:40 PM

Try something like this


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
Was This Post Helpful? 0
  • +
  • -

#3 Reverand Dave  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 375
  • Joined: 27-July 08

Re: open text file and dump text into textbox

Posted 09 October 2008 - 02:44 PM

View PostReverand Dave, on 9 Oct, 2008 - 12:40 PM, said:


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


   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.
Was This Post Helpful? 0
  • +
  • -

#4 TRANERAECK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-August 12

Re: open text file and dump text into textbox

Posted 08 February 2013 - 03:13 PM

Here is how I have filled a textbox with any file:
Private Sub OKButton_Click()
    Dim NEWOPEN As String
    Dim Handle As Integer
    
    If answer = 6 Then
        NEWOPEN = File1.Path + "\" + File1.FileName
    End If
    Handle = FreeFile()
    Open NEWOPEN For Input As #Handle
        While Not EOF(Handle)
            If Not EOF(Handle) Then
                MainForm.Text1.Text = MainForm.Text1.Text + Input$(1, #Handle)
            End If
        Wend
    Close #Handle
    MainForm.Text1.Refresh
    Unload Me
End Sub


Hope this helps!!!!!
Was This Post Helpful? 0
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: open text file and dump text into textbox

Posted 10 February 2013 - 10:48 AM

Since smcmcmanus hasn't posted anything here in four years, I doubt it will help him, but it might help one of the 13,000 viewers of this thread. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1