Code Snippets

  

Visual Basic Source Code


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

Join 99,787 VB Programmers for FREE! Ask your question and get quick answers from experts. There are 1,586 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!




Open & Saving .txt files

how to open and save text files

Submitted By: pal121
Actions:
Rating:
Views: 24,155

Language: Visual Basic

Last Modified: February 10, 2006
Instructions: copy & paste & add Microsoft Common Dialog Control 6.0

you need a button and a textbox

Snippet


  1. Private Sub cmdsave_Click()
  2.  
  3. Dim filelocation As String
  4.  
  5. ' loads save as box
  6.     commondialog1.ShowSave
  7.    
  8.     filelocation = commondialog1.FileName
  9.    
  10. ' append saves over file if it assists
  11.     Open filelocation For Append As #1
  12.         Print #1, text1.text
  13.     Close #1
  14.  
  15. End Sub
  16.  
  17. Private Sub cmdopen_Click()
  18.  
  19. Dim filelocation As String
  20.  
  21. ' show open box
  22.     commondialog1.ShowOpen
  23.    
  24.     filelocation = commondialog1.FileName
  25.  
  26. ' input files into text1.text   
  27.     Open filelocation For Input As #1
  28.    
  29. Do Until EOF(1)
  30.  
  31.         Input #1, Data
  32.         text1.text = text1.text + Data + vbNewLine
  33.     EOF (1)
  34.     Loop
  35.     Close #1
  36.    
  37. End Sub
  38.  
  39.  
  40.  

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





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