5 Replies - 13902 Views - Last Post: 13 March 2012 - 12:17 PM Rate Topic: -----

#1 supr4  Icon User is offline

  • New D.I.C Head

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

' ' is not declared.It may be inaccessible due to its protecti

Posted 13 March 2012 - 11:51 AM

I'm getting the error ' ' is not declared.It may be inaccessible due to its protection level with the following code.
The error is given for these following:
txtFirstName
txtSurname
txtAccountNumber
txtAccountType
txtInvestment
txtInterestAmount



Imports System.Windows.Forms.TextBox
Public Class ClickSave
    Public Sub cmdSave_Click()
        Dim FILE_NAME As String = "F:\Investors.txt"
        Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
        objWriter.WriteLine(txtFirstName.Text)
        objWriter.WriteLine(txtSurname.Text)
        objWriter.WriteLine(txtAccountNumber.Text)
        objWriter.WriteLine(txtAccountType.Text)
        objWriter.WriteLine(txtInvestment.Text)
        objWriter.WriteLine(txtInterestAmount.Text)
        objWriter.Close()
        MsgBox("The file has been saved")
    End Sub
End Class



I tried changing from private sub to Public and adding Imports System.Windows.Forms.TextBox but that didn't fix my problem.

Any ideas on what I can do?

This post has been edited by supr4: 13 March 2012 - 11:52 AM


Is This A Good Question/Topic? 0
  • +

Replies To: ' ' is not declared.It may be inaccessible due to its protecti

#2 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

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

Re: ' ' is not declared.It may be inaccessible due to its protecti

Posted 13 March 2012 - 12:05 PM

everything seems to be okay in this piece of code. Are those Textboxes in the same form where you have this code?
Was This Post Helpful? 1
  • +
  • -

#3 supr4  Icon User is offline

  • New D.I.C Head

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

Re: ' ' is not declared.It may be inaccessible due to its protecti

Posted 13 March 2012 - 12:08 PM

I put this code within a class, when its on the code for the form like this

 Public Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        Dim FILE_NAME As String = "F:\Investors.txt"
        Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
        objWriter.WriteLine(txtFirstName.Text)
        objWriter.WriteLine(txtSurname.Text)
        objWriter.WriteLine(txtAccountNumber.Text)
        objWriter.WriteLine(txtAccountType.Text)
        objWriter.WriteLine(txtInvestment.Text)
        objWriter.WriteLine(txtInterestAmount.Text)
        objWriter.Close()
        MsgBox("The file has been saved")
    End Sub


it works fine, but in the class it gives me that error of not being declared/protection level
Was This Post Helpful? 0
  • +
  • -

#4 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

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

Re: ' ' is not declared.It may be inaccessible due to its protecti

Posted 13 March 2012 - 12:12 PM

try appending the form name to the textboxes?

objWriter.WriteLine(frmName.txtFirstName.Text)

Was This Post Helpful? 1
  • +
  • -

#5 supr4  Icon User is offline

  • New D.I.C Head

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

Re: ' ' is not declared.It may be inaccessible due to its protecti

Posted 13 March 2012 - 12:13 PM

That did the trick, I appreciate the help nK0de :)
Was This Post Helpful? 0
  • +
  • -

#6 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

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

Re: ' ' is not declared.It may be inaccessible due to its protecti

Posted 13 March 2012 - 12:17 PM

glad to help :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1