2 Replies - 138 Views - Last Post: 31 December 2017 - 10:20 AM Rate Topic: -----

#1 BloodySandwich  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-December 17

Writing string into specifc index in already exisiting file

Posted 31 December 2017 - 09:57 AM

Hello, I'm trying insert the value from combo box to specific index in already existing text file by using stream reader and stream writer. First read the entire file and then write to specific index.
The format of text file: abc|1234|value from combo box
Can someone give an idea how I should do this, Thanks

My code:

Using reader As StreamReader = New StreamReader("..\..\TextFile\users.txt", True)
            Dim amount As String = cboTop.SelectedItem

            While Not reader.EndOfStream
                Dim AmountTop As String() = reader.ReadLine.Split("|")
                amount = AmountTop(2)


            End While

        End Using

        Using writerTopUp As StreamWriter = New StreamWriter("..\..\TextFile\users.txt", True)
            If cboTop.SelectedItem IsNot Nothing Then
                writerTopUp.Write(cboTop.SelectedItem)
            Else
                MessageBox.Show("Please select the amount you want to top up.")
            End If
            writerTopUp.Close()
        End Using
:code:

This post has been edited by modi123_1: 31 December 2017 - 10:00 AM
Reason for edit:: In the future, please use the [code] tag button in the editor..


Is This A Good Question/Topic? 0
  • +

Replies To: Writing string into specifc index in already exisiting file

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13665
  • View blog
  • Posts: 54,541
  • Joined: 12-June 08

Re: Writing string into specifc index in already exisiting file

Posted 31 December 2017 - 10:01 AM

What is your issue?

Perhaps read the file into a collection of strings to better impose the concept of 'index' to it.
Was This Post Helpful? 0
  • +
  • -

#3 BloodySandwich  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-December 17

Re: Writing string into specifc index in already exisiting file

Posted 31 December 2017 - 10:20 AM

Well my issue is that when press button it doesn't write to the text file at all. What do you mean collection of strings?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1