6 Replies - 303 Views - Last Post: 02 March 2012 - 01:44 PM Rate Topic: -----

#1 supr4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 02-March 12

Saving as a Txt File

Posted 02 March 2012 - 01:22 PM

Hello,

I've created several Textboxes in which the user can input detail. I've created a button that I want to act as a "save" button. I've tried the following code but I get a wiggly blue line under the objwriter from line 3-8.

What it says is that "'objwriter' is not declared. It may be inaccessible due to its protection level"

Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        Dim objwriter As System.IO.StreamWriter(C:\Desktop)
        objwriter.Write(txtFirstName.Text)
        objwriter.Write(txtSurname.Text)
        objwriter.Write(txtAccountNumber.Text)
        objwriter.Write(txtAccountType.Text)
        objwriter.Write(txtInvestment.Text)
        objwriter.Close()
    End Sub


Any advice on how to fix this?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Saving as a Txt File

#2 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 204
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Saving as a Txt File

Posted 02 March 2012 - 01:26 PM

try this? Also import the IO namespace to your project at the beginning using the Imports keyword. So that you don't have to write the whole thing everytime

Imports System.IO
Dim objwriter As New StreamWriter


This post has been edited by nK0de: 02 March 2012 - 01:29 PM

Was This Post Helpful? 1
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8915
  • View blog
  • Posts: 33,430
  • Joined: 12-June 08

Re: Saving as a Txt File

Posted 02 March 2012 - 01:28 PM

You need to instantiate it. In this case declare it as 'new'. Also you'll run into a problem with your path not being a string (aka in quotes).
Was This Post Helpful? 1
  • +
  • -

#4 supr4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 02-March 12

Re: Saving as a Txt File

Posted 02 March 2012 - 01:29 PM

Thanks for replying

I've tried doing that, however it still comes up with the same thing.
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Saving as a Txt File

Posted 02 March 2012 - 01:34 PM

Then show us the code you wrote where you attempted this. Because that is exactly what the error is telling you.

If you did it correctly, and fixed the other problem with your path/filename as modi described, you should at least be able to test the program by running it.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8915
  • View blog
  • Posts: 33,430
  • Joined: 12-June 08

Re: Saving as a Txt File

Posted 02 March 2012 - 01:35 PM

Let's see it.
Was This Post Helpful? 0
  • +
  • -

#7 supr4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 02-March 12

Re: Saving as a Txt File

Posted 02 March 2012 - 01:44 PM

I've changed the code slightly, but it works fine now. Thanks for the input

rivate Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        Dim FILE_NAME As String = "C:\Desktop\test2.txt"
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
            objWriter.Write(txtFirstName.Text)
            objWriter.Write(txtSurname.Text)
            objWriter.Write(txtAccountNumber.Text)
            objWriter.Write(txtAccountType.Text)
            objWriter.Write(txtInvestment.Text)
            objWriter.Close()
            End Sub

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1