Jump to content





Recent Status Updates

  • Photo
      16 Apr
    Kadence

    If you're reading this, you're on my profile and I know you're on my profile because I'm probably viewing yours.

    Show comments (6)
  • Photo
      10 Apr
    Poe

    Finally (and hopefully) i'm getting a team together that knows a little of this and a little of that; and maybe all my open source projects that are half written can begin to be released. :)

View All Updates
Photo
- - - - -

Cut/copy/Paste in forms


  • Please log in to reply
19 replies to this topic

#13 CommittedC0der

CommittedC0der

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,061 posts
  • Programming Language:C#
  • Learning:C#, JavaScript

Posted 10 August 2011 - 03:31 PM

^ Bingo. TextBox[] should work perfect for you. Thank you Momerath. :)

~ Committed
  • 0
There IS a war going on for your mind.
Nothing of eternal significance happens besides prayer.

#14 kemnet

kemnet

    CC Newcomer

  • Just Joined
  • PipPip
  • 13 posts

Posted 10 August 2011 - 04:31 PM

private void cutToolStripButton_Click(object sender, EventArgs e)
        {
//Control[] txtBoxArray;
            TextBox[] txtBoxArray;
          //  int o = txtBoxArray.Length;
            txtBoxArray = new TextBox[5];
            for (int i = 0; i < txtBoxArray.Length; i++)
            {
                txtBoxArray[i].Cut();<--Error line
            }
        }

so it should be?
that kinda...errors out too

Crashes when u click cut and says object instance not set to an instance of the object.

---------- Post added at 05:31 PM ---------- Previous post was at 05:01 PM ----------

Should i replace all my control[] to textbox[]?
  • 0

#15 Momerath

Momerath

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 282 posts
  • Programming Language:C, Java, C++, C#, PHP, (Visual) Basic, Python, JavaScript, Perl, Visual Basic .NET, Pascal, Ada, Assembly, Fortran, Scheme
  • Learning:Others

Posted 10 August 2011 - 05:31 PM

That's because you've created the array to hold the TextBoxes, but haven't actually assigned any TextBoxes to the array.
  • 0

#16 kemnet

kemnet

    CC Newcomer

  • Just Joined
  • PipPip
  • 13 posts

Posted 10 August 2011 - 05:33 PM

yes i did
way at the top
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           txtBoxArray = new Control[] {f_nameTextBox, m_nameTextBox, l_nameTextBox, };
        }
      
        //public TextBox[] txtBoxArray;
        public Control[] txtBoxArray;

but apprantly its null when it gets down there...
  • 0

#17 Momerath

Momerath

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 282 posts
  • Programming Language:C, Java, C++, C#, PHP, (Visual) Basic, Python, JavaScript, Perl, Visual Basic .NET, Pascal, Ada, Assembly, Fortran, Scheme
  • Learning:Others

Posted 10 August 2011 - 08:00 PM

In the code block in post #14 you declare the array there. In that code block you don't assign anything to the array. Did you not mean to declare the array there?

Also, your line should read
txtBoxArray = new TextBox[] {f_nameTextBox, m_nameTextBox, l_nameTextBox};

  • 0

#18 CommittedC0der

CommittedC0der

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,061 posts
  • Programming Language:C#
  • Learning:C#, JavaScript

Posted 10 August 2011 - 09:17 PM

First you declare the array, then you set the values on form initialization. Once thats done you can loop through the array(Some of your error's in red).
public Form1()        {
            InitializeComponent();
           txtBoxArray = new [COLOR=#ff0000]txtBoxArray[/COLOR][] {f_nameTextBox, m_nameTextBox, l_nameTextBox, }; [COLOR=#008000]//assign its values[/COLOR]
        }
      
[COLOR=#ff0000]        public TextBox[] txtBoxArray; [/COLOR][COLOR=#008000]//Create the array once.[/COLOR]

private void cutToolStripButton_Click(object sender, EventArgs e)        {
            for (int i = 0; i < txtBoxArray.Length; i++)[COLOR=#008000]//Now loop through[/COLOR]
            {
                txtBoxArray[i].Cut();
            }
        }

Your problem is you create an array, assign values, then try and recreate it, add no values, and try to reference it. On top of that when you create an array you cant say "txtBoxArray = new Control[];" because txtBoxArray, is a TextBox array, not a Control array.

~ Committed.
  • 0
There IS a war going on for your mind.
Nothing of eternal significance happens besides prayer.

#19 kemnet

kemnet

    CC Newcomer

  • Just Joined
  • PipPip
  • 13 posts

Posted 11 August 2011 - 03:14 AM

Oh you're right..i dont know why i thought i had to initialize it again to be able to access it.
Do you think you can suggest a book or site (preferably) for reading?
  • 0

#20 CommittedC0der

CommittedC0der

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,061 posts
  • Programming Language:C#
  • Learning:C#, JavaScript

Posted 11 August 2011 - 06:13 AM

This site may help you. :)
Visual C# .NET for Complete Beginners - a free programming course
~ Committed.
  • 0
There IS a war going on for your mind.
Nothing of eternal significance happens besides prayer.