Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> How Do I Save Files To .txt In Vb.net
foto51
post Feb 14 2007, 03:50 AM
Post #1


Newbie
*

Group: Members
Posts: 1
Joined: 14-February 07
Member No.: 38,683



Hello, I have a project that I am doing. I have a list box that you can enter data in, and I need it to have the ability to save that list into a text file (Names.txt). The txt file should have each entry on it's own line. Any help would be appreciated.
Go to the top of the page
 
+Quote Post
Galahad
post Feb 17 2007, 05:59 PM
Post #2


Neurotical Squirrel
*********

Group: [HOSTED]
Posts: 585
Joined: 4-November 04
From: Novi Sad, Vojvodina
Member No.: 2,127



I'm not sure about Vb.Net, I haven't touched it in couple of years, but I can give you code, how it would look in VB6, and you can go from there:

CODE

Dim i As Long

Open "Names.txt" For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next i
Close #1


And that's it... I believe it should be fairly simple in Vb.Net too... Probably very similar...
Go to the top of the page
 
+Quote Post
Galahad
post Mar 26 2007, 10:23 AM
Post #3


Neurotical Squirrel
*********

Group: [HOSTED]
Posts: 585
Joined: 4-November 04
From: Novi Sad, Vojvodina
Member No.: 2,127



OK, I'm sure you already found what you were looking for, but I'll post an example code, of how to write text files in VB.NET... Maybe someone in the future would find it usefull:

CODE
Imports System
Imports System.IO

Public Class Form1
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim f As StreamWriter, i As Long, obj As Object
    For i = 1 To 10
      ListBox1.Items.Add("Item " & i.ToString)
    Next i
    f = New StreamWriter("C:\Test.txt")
    For i = 0 To ListBox1.Items.Count - 1
      f.WriteLine(ListBox1.Items.Item(i).ToString)
    Next i
    f.Close()
  End Sub
End Class


That's the full working code, just copy and paste it in your project, and voila... Hope it helped a bit smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Converting Video Files From One Format To Another(6)
  2. Getting List Of Directories And Files Using Php(6)
  3. Defragment: Cannot Defrag All Fragmented Files(9)
  4. Does Anyone Know How To Make Exe Files(17)
  5. Xbox-save-games(11)
  6. Css And Javascript Combined For Dynamic Layout(9)
  7. Need 4 Speed Underground 2(3)
  8. How To Save *.swf From A Web Site?(29)
  9. The Icons Of Zip Files Are Wrong Everytime!(3)
  10. Files With Mdf Extension(6)
  11. Linux Question: Amarok And File Permissions(4)
  12. Strange .log Files On My Desktop(10)
  13. Flatfile User Login/signup(24)
  14. Informix To Sql Server (or How To Open .unl Files)(2)
  15. How To Disable "show Hidden Files And Folders" In Folder Option(11)
  1. How To Save Yourself From A Rape Situation?(13)
  2. Decoration(1)
  3. Save Youtube Files(21)
  4. Deleted Some Important Files In Your Usb/ Mem Stick?(1)
  5. Search For Video Files And Display Them(0)
  6. Converting Audio Files In Vista(7)
  7. Mysql(2)
  8. Save Me!(0)
  9. Debug Exe Files(4)
  10. 1350 Great Free Logos (jpg + Psd)(7)
  11. Best Way To Transfer Files(6)
  12. Jar Executable Files(1)
  13. Audio Files?(3)


 



- Lo-Fi Version Time is now: 25th July 2008 - 10:25 AM