Visual Basic > Files Directories Drives
Working with textfiles (Open etc)
Working with textfiles (Open etc) 'open a textfile on disk into a textbox 'make a Form with a TextBox (multiline = True) 'and two commandbuttons 'put the next code on the appropiate places Sub Command1_Click() Call GetFile("c:\autoexec.bat") End Sub Private sub GetFile(FileName$) Dim nFilenumber% Dim tmpLine$ Text1.Text = "" nFilenumber = FreeFile Open FileName$ For input as #nFilenumber Do While Not EOF(nFileNumber) Input #nFileNumber, tmpLine Text1.Text = Text1.Text & tmpline Loop Close #nFileNumber End Sub 'save the content of a textbox into a file on disk Sub Command2_Click() Dim answer$ answer$ = InputBox("Which name will you give the file?") If answer$="" then Exit Sub Call SaveFile(answer$) End Sub Private sub SaveFile(FileName$) Dim nFilenumber% nFilenumber = FreeFile Open FileName$ For Output as #nFilenumber Print #nFileNumber, Text1.Text Close #nFileNumber End Sub Return
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows