Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to send data into textfile?

How to send data into textfile?

Scheduled Pinned Locked Moved Visual Basic
testingbeta-testinghelptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TeiUKei
    wrote on last edited by
    #1

    I try to do some code which receive data and write into textfile. Somehow, it didn't work. Could anyone just kindly my problem? Below is my coding. Public Class PropertyCreateFile Dim Str As ArrayList Dim Ctr As Integer Public Property Data() As ArrayList Get Return Str End Get Set(ByVal Value As ArrayList) Str = Value End Set End Property Public Property Counter() As Integer Get Return Ctr End Get Set(ByVal Value As Integer) Ctr = Value End Set End Property End Class Public Class CreateFileCTL Private CurDir As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) Public Function CreateTextFile(ByVal CreatePP As PropertyCreateFile) As String Dim sFilename As String = (CurDir & "/Testing.txt") Dim b As Integer = 0 Try Dim oFile As FileStream = New FileStream(sFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite) Dim oWriter As StreamWriter = New StreamWriter(oFile) For b = 0 To CreatePP.Counter oWriter.WriteLine(CreatePP.Data) b += 1 Next oWriter.Close() oFile.Close() Catch MsgBox("No Such File") End Try Return Nothing End Function Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim Data1 As New PropertyCreateFile Dim aa As New ArrayList aa.Add("a") aa.Add("b") aa.Add("c") Data1.Data = aa Data1.Counter = 3 aaa.CreateTextFile(Data1) End Sub

    L 1 Reply Last reply
    0
    • T TeiUKei

      I try to do some code which receive data and write into textfile. Somehow, it didn't work. Could anyone just kindly my problem? Below is my coding. Public Class PropertyCreateFile Dim Str As ArrayList Dim Ctr As Integer Public Property Data() As ArrayList Get Return Str End Get Set(ByVal Value As ArrayList) Str = Value End Set End Property Public Property Counter() As Integer Get Return Ctr End Get Set(ByVal Value As Integer) Ctr = Value End Set End Property End Class Public Class CreateFileCTL Private CurDir As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) Public Function CreateTextFile(ByVal CreatePP As PropertyCreateFile) As String Dim sFilename As String = (CurDir & "/Testing.txt") Dim b As Integer = 0 Try Dim oFile As FileStream = New FileStream(sFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite) Dim oWriter As StreamWriter = New StreamWriter(oFile) For b = 0 To CreatePP.Counter oWriter.WriteLine(CreatePP.Data) b += 1 Next oWriter.Close() oFile.Close() Catch MsgBox("No Such File") End Try Return Nothing End Function Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim Data1 As New PropertyCreateFile Dim aa As New ArrayList aa.Add("a") aa.Add("b") aa.Add("c") Data1.Data = aa Data1.Counter = 3 aaa.CreateTextFile(Data1) End Sub

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Hey, Try this: Imports System Imports System.IO Class WriteFile Private Sub WriteText() ' Create an instance of StreamWriter to write text to a file. Using sw As StreamWriter = New StreamWriter("TestFile.txt") ' Add some text to the file. sw.Write("Testing ") sw.WriteLine("writing text to a file.") sw.WriteLine("-------------------") sw.Close() End Using End Sub End Class Let me know if this works for you.

      -------------------------------- Extreme Exe

      T 1 Reply Last reply
      0
      • L Lost User

        Hey, Try this: Imports System Imports System.IO Class WriteFile Private Sub WriteText() ' Create an instance of StreamWriter to write text to a file. Using sw As StreamWriter = New StreamWriter("TestFile.txt") ' Add some text to the file. sw.Write("Testing ") sw.WriteLine("writing text to a file.") sw.WriteLine("-------------------") sw.Close() End Using End Sub End Class Let me know if this works for you.

        -------------------------------- Extreme Exe

        T Offline
        T Offline
        TeiUKei
        wrote on last edited by
        #3

        It is the same way that i am doing and it doesn't work. The data that copied into textfile is not what i want. The data shown in textfile is systam.collection.arraylist and what i want is a,b and c. Anyway, thanx for help!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups