Closed Thread
Results 1 to 2 of 2

Thread: unaccessible due to its protection level

  1. #1
    dropper166 is offline Newbie
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Smile unaccessible due to its protection level

    Code:
    Code:
    using System;
    using System.Windows.Forms;
    
    namespace WindowsApplication2
    {
        public partial class Form1 : Form
        {
           protected int TextBoxCount = 5; // number of TextBoxes on Form
    
            //enumeration constants specify textbox indices
            public enum TextBoxIndices
            {
                VIDEOAUDIO,
                TITLE,
                CATEGORY,
                CERTIFICATION,
                COPIES
            }
    
            //parameterless constructor
            public Form1()
            {
                InitializeComponent();
            }
            //end constructor
    
            //clear all TExtBoxes
            public void ClearTextBoxes()
            {
                //iterate through every control on form
                for (int i = 0; i < Controls.Count; i++)
                {
                    Control myControl = Controls[i]; // get control
    
                    //determine wheterh control is textbox
                    if (myControl is TextBox)
                    {
                        //clear text property (set to empty string )
                        myControl.Text = "";
                    }//end if
                }//end for
            }//end method ClearTextBoxes
    
            //set text box values to string array values
            public void SetTextBoxValues(string[] values)
            {
                //determine wethere string array has correct lenght
                if (values.Length != TextBoxCount)
                {
                    //throw exception if not correct length
                    throw (new ApplicationException(" There must be " +
                        (TextBoxCount + 1) + " string in the array"));
                }//end if
    
    
                //set array values if array has correct lenght
                else
                {
                    //seet array values to text box values
                    videoaudiocodeTextBox.Text = values[(int)TextBoxIndices.VIDEOAUDIO];
                    titleTextBox.Text = values[(int)TextBoxIndices.TITLE];
                    categoryTextBox.Text = values[(int)TextBoxIndices.CATEGORY];
                    certificationTextBox.Text = values[(int)TextBoxIndices.CERTIFICATION];
                    copiesTextBox.Text = values[(int)TextBoxIndices.COPIES];
                }//end else
            }//end method SetTExtValues
    
            //return text box values as string array
            public string[] GetTextBoxValues()
            {
                string[] values = new string[TextBoxCount];
    
                //copy text box fields to string array
                values[(int)TextBoxIndices.VIDEOAUDIO] = videoaudiocodeTextBox.Text;
                values[(int)TextBoxIndices.TITLE] = titleTextBox.Text;
                values[(int)TextBoxIndices.CATEGORY] = categoryTextBox.Text;
                values[(int)TextBoxIndices.CERTIFICATION] = certificationTextBox.Text;
                values[(int)TextBoxIndices.COPIES] = copiesTextBox.Text;
    
                return values;
            }
    
          
           
            }//end method
        }//end class



    Code:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace WindowsApplication2
    {
       public class Class1
       {
          private int videoandaudio;
          private string title;
          private string category;
          private string certification;
          private int copies;
    
          //parameterless constructor sets members to default values
          public Class1()
             : this(0, "", "", "", 0)
          {
          }//end constructor
    
          //overloaded constructor sets members to parameter values 
          public Class1(int videoandaudioValue, string titleValue, string categoryValue,
              string certificationValue, int copiesValue)
          {
             Videoandaudio = videoandaudioValue;
             Title = titleValue;
             Category = categoryValue;
             Certification = certificationValue;
             Copies = copiesValue;
          }//end constructor
    
          //property that gets and sets account
          public int Videoandaudio
          {
             get
             {
                return videoandaudio;
             }//end get
    
             set
             {
                videoandaudio = value;
             }//endset
          }//end property Videoandaudio
    
          //property that gets and sets title
          public string Title
          {
             get
             {
                return title;
             }//end get
    
             set
             {
                title = value;
             }//endset
          }//end property title
    
          //property that gets and sets category
          public string Category
          {
             get
             {
                return category;
             }//end get
    
             set
             {
                category = value;
             }//endset
          }//end property category
    
          //property that gets and sets certification
          public string Certification
          {
             get
             {
                return certification;
             }//end get
    
             set
             {
                certification = value;
             }//endset
          }//end property certification
    
          //property that gets and sets coopies
          public int Copies
          {
             get
             {
                return copies;
             }//end get
    
             set
             {
                copies = value;
             }//endset
          }//end property copies
    
    
    
    
          }//end class
       }
    Code:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    
    namespace WindowsApplication2
    {
       public partial class Class2 : Form1
       {
          private StreamWriter fileWriter; // writes datea to text file
          private FileStream output; // maintains connection  to file
    
            //pramaterless constructor
            public  Class2()
            {
                InitializeComponent();                 ----this has protection level      
                                                                                                         error       
            }//end constructor
    
            //event handelr for Save button
            private void saveButton_Click(object sender, EventArgs e)
            {
                //create dialog box enabling uer to save file
                SaveFileDialog fileChooser = new SaveFileDialog();
                DialogResult result = fileChooser.ShowDialog();
                string fileName; // name of file to save data
    
                fileChooser.CheckFileExists = false; // allow user to create file
    
                //exit event handler if user clicked "Cancel"
                if (result == DialogResult.Cancel)
                    return;
    
                fileName = fileChooser.FileName; // get specified file name
    
                //show error if user specified invalid file
                if (fileName == "" || fileName == null)
                    MessageBox.Show(" Invalid File Name", "Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                else
                {
                    //save file via filestream if user specified valid file
                    try
                    {
                        //open ifle with write access
                        output = new FileStream(fileName,
                            FileMode.OpenOrCreate, FileAccess.Write);
    
                        //sets file to where data is written
                        fileWriter = new StreamWriter(output);
    
                        //disable save button and enable enter button
                        saveButton.Enabled = false;
                        enterButton.Enabled = true;                 ---these two have protection
                                                                                                                 error too
                    }//end try
    
                    //handle exception if ther is a problem opening the file
                    catch (IOException)
                    {
                        //notify user if file doesnot exist
                        MessageBox.Show("Error opening file", "error",
                          MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }//end catch
                }//end else
            }//end method saveButton_click
    
            //handler for enterButton_click
            private void enterButton_Click(object sender, EventArgs e)
            {
                //store Textbox values string array
                string[] values = GetTextBoxValues();
    
                //record containg textbox values to serialize
                Class1 class1 = new Class1();
    
                //determine whether textbox account field is empty
                if ( values [ ( int ) TextBoxIndices.VIDEOAUDIO ] != "" )
                {
                    // store textbox values in record and serialize record
                    try
                    {
                        // get video and audio code value from textbox
                        int videoandaudioCode = Int32.Parse( values[ ( int ) TextBoxIndices.VIDEOAUDIO ] );
    
                        //determine wheterh videoandaudioCode is valid
                        if ( videoandaudioCode > 0 )
                        {
                            //store textbox fields in record
                            class1.Videoandaudio = videoandaudioCode;
                            class1.Title = values[ ( int ) TextBoxIndices.TITLE ];
                            class1.Category = values[ ( int ) TextBoxIndices.CATEGORY ];
                            class1.Certification = values[ ( int ) TextBoxIndices.CERTIFICATION ];
                            class1.Copies = Int32.Parse( values[ ( int ) TextBoxIndices.COPIES ]);
                        }//end if
                        else{
                            //notify user if invalid video and audio code
                            MessageBox.Show( " invalid code ", "error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error ) ;
                        }//end else
                    }//endtry
                    //notify user if error occurs in seialization
                    catch ( IOException )
                    {
                        MessageBox.Show( "error writing to file" , "error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error );
                    }//end catch
                    //notify user if eror occurs regarding parameter format
                    catch ( FormatException ) 
                    {
                        MessageBox.Show( "invalid format", "error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error );
                    }//end catch
                }//end if
    
                ClearTextBoxes(); //clear textbox values
            }//end method enter button_ click
    
            //handler for exitButton Click
            private void exitButton_Click(object sender, EventArgs e)
            {
                //dtermine wheteher file exists
                if (output != null)
                {
                    try
                    {
                        fileWriter.Close(); //close streamwriter
                        output.Close(); //close file
    
                    }// end try
                    //notify user of error closing file
                    catch (IOException)
                    {
                        MessageBox.Show(" cannot close file", "error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }//end catch
                }//end if
    
                Application.Exit();
            }//end method
        }// end class
    }




    i based this code from my book for my project theyre pretty the same except for the names...now before i put the code for the class2 this program were running good...on the class2 there are errors saying "unaccessible due to protection level"
    and the underlined words are InitializeComponent(); ,saveButton.Enabled = false; and
    enterButton.Enabled



    Code:
    Code:
    ............. public  Class2()
            {
                InitializeComponent();                 ----this has protection level      
                                                                                                         error       
            }//end constructor
    
            //event handelr for Save button
            private void saveButton_Click(object sender, EventArgs e)
            {
                //create dialog box enabling uer to save file
                SaveFileDialog fileChooser = new SaveFileDialog();
                DialogResult result = fileChooser.ShowDialog();
                string fileName; // name of file to save data
    
                fileChooser.CheckFileExists = false; // allow user to create file
    
                //exit event handler if user clicked "Cancel"
                if (result == DialogResult.Cancel)
                    return;
    
                fileName = fileChooser.FileName; // get specified file name
    
                //show error if user specified invalid file
                if (fileName == "" || fileName == null)
                    MessageBox.Show(" Invalid File Name", "Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                else
                {
                    //save file via filestream if user specified valid file
                    try
                    {
                        //open ifle with write access
                        output = new FileStream(fileName,
                            FileMode.OpenOrCreate, FileAccess.Write);
    
                        //sets file to where data is written
                        fileWriter = new StreamWriter(output);
    
                        //disable save button and enable enter button
                        saveButton.Enabled = false;
                        enterButton.Enabled = true;                 ---these two have protection
                                                                                                                 error too
                    }//end try
    
    
    .................

    i think form1 has something to do with this with the word "protective int"
    iam not sure
    can someone explain why is this happen
    thx
    Last edited by WingedPanther; 03-31-2009 at 08:48 AM. Reason: add code tags (the # button)

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    njr1489's Avatar
    njr1489 is offline Learning Programmer
    Join Date
    Mar 2008
    Posts
    70
    Rep Power
    0

    Re: unaccessible due to its protection level

    I didn't proofread your code, but you are asking on how the protected keyword is stopping your program. I believe anything under protected can only be reached within its class and its inherited members.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 9
    Last Post: 07-16-2010, 05:12 PM
  2. Forum is UNACCESSIBLE to members! Help!
    By ArekBulski in forum The Lounge
    Replies: 4
    Last Post: 09-01-2009, 09:54 PM
  3. Virus protection
    By Jaan in forum The Lounge
    Replies: 26
    Last Post: 04-19-2009, 06:00 AM
  4. software protection
    By rebecca009 in forum Software Security
    Replies: 3
    Last Post: 09-27-2008, 09:51 AM
  5. Replies: 15
    Last Post: 06-06-2008, 10:43 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts