where to place array initialization?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Cox

    where to place array initialization?

    Hello,

    I am trying to get a grip on where to place the initialization of two
    arrays in the code below which was created using Visual C++ 2005
    Express Beta 2...

    private: static array<String^>^ LHSquestions = gcnew array<String^>
    {"question 1","question 2"};
    private: static array<String^>^ RHSquestions = gcnew array<String^>
    {"question 1",
    "question 2"};

    I had assumed that I would add them after the other private lines
    below? Any suggestions for a beginner's Internet tutorial or book on
    using C++ Express language?

    Cheers

    Geoff


    !

    #pragma once


    namespace trackbar1
    {
    using namespace System;
    using namespace System::Compone ntModel;
    using namespace System::Collect ions;
    using namespace System::Windows ::Forms;
    using namespace System::Data;
    using namespace System::Drawing ;

    /// <summary>
    /// Summary for Form1
    ///
    /// WARNING: If you change the name of this class, you will
    need to change the
    /// 'Resource File Name' property for the managed
    resource compiler tool
    /// associated with all .resx files this class
    depends on. Otherwise,
    /// the designers will not be able to interact
    properly with localized
    /// resources associated with this form.
    /// </summary>
    public ref class Form1 : public System::Windows ::Forms::Form
    {
    public:
    Form1(void)
    {
    InitializeCompo nent();
    //
    //TODO: Add the constructor code here
    //
    }

    protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing ">"descript ion of the
    parameter"</param>
    virtual void Dispose(Boolean disposing) override
    {
    if (disposing && components)
    {
    delete components;
    }
    __super::Dispos e(disposing);
    }
    private: System::Windows ::Forms::TrackB ar^ trackBar1;
    protected:
    private: System::Windows ::Forms::Pictur eBox^ pictureBox1;
    private: System::Windows ::Forms::Label^ label1;
    private: System::Windows ::Forms::Label^ label2;
    private: System::Windows ::Forms::Button ^ button1;

    private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::Compone ntModel::Contai ner ^components;

    #pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not
    modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeCompo nent(void)
    {

    System::Compone ntModel::Compon entResourceMana ger^ resources = (gcnew
    System::Compone ntModel::Compon entResourceMana ger(Form1::type id));
    this->trackBar1 = (gcnew
    System::Windows ::Forms::TrackB ar());
    this->pictureBox1 = (gcnew
    System::Windows ::Forms::Pictur eBox());
    this->label1 = (gcnew
    System::Windows ::Forms::Label( ));
    this->label2 = (gcnew
    System::Windows ::Forms::Label( ));
    this->button1 = (gcnew
    System::Windows ::Forms::Button ());

    (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=blue]
    >(this->trackBar1))->BeginInit();[/color]

    (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=blue]
    >(this->pictureBox1) )->BeginInit();[/color]
    this->SuspendLayout( );
    //
    // trackBar1
    //
    this->trackBar1->Location =
    System::Drawing ::Point(90, 168);
    this->trackBar1->Name = L"trackBar1" ;
    this->trackBar1->Size =
    System::Drawing ::Size(104, 45);
    this->trackBar1->TabIndex = 0;
    //
    // pictureBox1
    //
    this->pictureBox1->Image =
    (cli::safe_cast <System::Drawin g::Image^[color=blue]
    >(resources->GetObject(L"pi ctureBox1.Image ")));[/color]
    this->pictureBox1->Location =
    System::Drawing ::Point(37, 13);
    this->pictureBox1->Name = L"pictureBox 1";
    this->pictureBox1->Size =
    System::Drawing ::Size(212, 134);
    this->pictureBox1->TabIndex = 1;
    this->pictureBox1->TabStop = false;
    //
    // label1
    //
    this->label1->AutoSize = true;
    this->label1->Location =
    System::Drawing ::Point(27, 182);
    this->label1->Name = L"label1";
    this->label1->Size = System::Drawing ::Size(31,
    13);
    this->label1->TabIndex = 2;
    this->label1->Text = L"label1";
    //
    // label2
    //
    this->label2->AutoSize = true;
    this->label2->Location =
    System::Drawing ::Point(230, 182);
    this->label2->Name = L"label2";
    this->label2->Size = System::Drawing ::Size(31,
    13);
    this->label2->TabIndex = 3;
    this->label2->Text = L"label2";
    //
    // button1
    //
    this->button1->Location =
    System::Drawing ::Point(100, 219);
    this->button1->Name = L"button1";
    this->button1->Size =
    System::Drawing ::Size(75, 23);
    this->button1->TabIndex = 4;
    this->button1->Text = L"NEXT";
    //
    // Form1
    //
    this->AutoScaleDimen sions =
    System::Drawing ::SizeF(6, 13);
    this->AutoScaleMod e =
    System::Windows ::Forms::AutoSc aleMode::Font;
    this->ClientSize = System::Drawing ::Size(292,
    266);
    this->Controls->Add(this->button1);
    this->Controls->Add(this->label2);
    this->Controls->Add(this->label1);
    this->Controls->Add(this->pictureBox1) ;
    this->Controls->Add(this->trackBar1);
    this->Name = L"Form1";
    this->Text = L"Form1";

    (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=blue]
    >(this->trackBar1))->EndInit();[/color]

    (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=blue]
    >(this->pictureBox1) )->EndInit();[/color]
    this->ResumeLayout(f alse);
    this->PerformLayout( );

    }
    #pragma endregion
    };
    }



  • Nishant Sivakumar

    #2
    Re: where to place array initialization?

    It's a matter of style I guess.
    One option - You could put all your static array members together.

    Also note that you don't need to specify "private" for each declaration. One
    would do.

    private:
    static array<String^>^ LHSquestions = gcnew array<String^>{ "question
    1","question 2"};
    static array<String^>^ RHSquestions = gcnew array<String^>{ "question
    1","question 2"};

    --
    Regards,
    Nish [VC++ MVP]
    Nish’s thoughts on technology leadership, cloud architecture, and APIs, among other things




    <Geoff Cox> wrote in message
    news:luo5g15rec 8gab5hr2vp97tjc k4nsnqtq6@4ax.c om...[color=blue]
    > Hello,
    >
    > I am trying to get a grip on where to place the initialization of two
    > arrays in the code below which was created using Visual C++ 2005
    > Express Beta 2...
    >
    > private: static array<String^>^ LHSquestions = gcnew array<String^>
    > {"question 1","question 2"};
    > private: static array<String^>^ RHSquestions = gcnew array<String^>
    > {"question 1",
    > "question 2"};
    >
    > I had assumed that I would add them after the other private lines
    > below? Any suggestions for a beginner's Internet tutorial or book on
    > using C++ Express language?
    >
    > Cheers
    >
    > Geoff
    >
    >
    > !
    >
    > #pragma once
    >
    >
    > namespace trackbar1
    > {
    > using namespace System;
    > using namespace System::Compone ntModel;
    > using namespace System::Collect ions;
    > using namespace System::Windows ::Forms;
    > using namespace System::Data;
    > using namespace System::Drawing ;
    >
    > /// <summary>
    > /// Summary for Form1
    > ///
    > /// WARNING: If you change the name of this class, you will
    > need to change the
    > /// 'Resource File Name' property for the managed
    > resource compiler tool
    > /// associated with all .resx files this class
    > depends on. Otherwise,
    > /// the designers will not be able to interact
    > properly with localized
    > /// resources associated with this form.
    > /// </summary>
    > public ref class Form1 : public System::Windows ::Forms::Form
    > {
    > public:
    > Form1(void)
    > {
    > InitializeCompo nent();
    > //
    > //TODO: Add the constructor code here
    > //
    > }
    >
    > protected:
    > /// <summary>
    > /// Clean up any resources being used.
    > /// </summary>
    > /// <param name="disposing ">"descript ion of the
    > parameter"</param>
    > virtual void Dispose(Boolean disposing) override
    > {
    > if (disposing && components)
    > {
    > delete components;
    > }
    > __super::Dispos e(disposing);
    > }
    > private: System::Windows ::Forms::TrackB ar^ trackBar1;
    > protected:
    > private: System::Windows ::Forms::Pictur eBox^ pictureBox1;
    > private: System::Windows ::Forms::Label^ label1;
    > private: System::Windows ::Forms::Label^ label2;
    > private: System::Windows ::Forms::Button ^ button1;
    >
    > private:
    > /// <summary>
    > /// Required designer variable.
    > /// </summary>
    > System::Compone ntModel::Contai ner ^components;
    >
    > #pragma region Windows Form Designer generated code
    > /// <summary>
    > /// Required method for Designer support - do not
    > modify
    > /// the contents of this method with the code editor.
    > /// </summary>
    > void InitializeCompo nent(void)
    > {
    >
    > System::Compone ntModel::Compon entResourceMana ger^ resources = (gcnew
    > System::Compone ntModel::Compon entResourceMana ger(Form1::type id));
    > this->trackBar1 = (gcnew
    > System::Windows ::Forms::TrackB ar());
    > this->pictureBox1 = (gcnew
    > System::Windows ::Forms::Pictur eBox());
    > this->label1 = (gcnew
    > System::Windows ::Forms::Label( ));
    > this->label2 = (gcnew
    > System::Windows ::Forms::Label( ));
    > this->button1 = (gcnew
    > System::Windows ::Forms::Button ());
    >
    > (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=green]
    >>(this->trackBar1))->BeginInit();[/color]
    >
    > (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=green]
    >>(this->pictureBox1) )->BeginInit();[/color]
    > this->SuspendLayout( );
    > //
    > // trackBar1
    > //
    > this->trackBar1->Location =
    > System::Drawing ::Point(90, 168);
    > this->trackBar1->Name = L"trackBar1" ;
    > this->trackBar1->Size =
    > System::Drawing ::Size(104, 45);
    > this->trackBar1->TabIndex = 0;
    > //
    > // pictureBox1
    > //
    > this->pictureBox1->Image =
    > (cli::safe_cast <System::Drawin g::Image^[color=green]
    >>(resources->GetObject(L"pi ctureBox1.Image ")));[/color]
    > this->pictureBox1->Location =
    > System::Drawing ::Point(37, 13);
    > this->pictureBox1->Name = L"pictureBox 1";
    > this->pictureBox1->Size =
    > System::Drawing ::Size(212, 134);
    > this->pictureBox1->TabIndex = 1;
    > this->pictureBox1->TabStop = false;
    > //
    > // label1
    > //
    > this->label1->AutoSize = true;
    > this->label1->Location =
    > System::Drawing ::Point(27, 182);
    > this->label1->Name = L"label1";
    > this->label1->Size = System::Drawing ::Size(31,
    > 13);
    > this->label1->TabIndex = 2;
    > this->label1->Text = L"label1";
    > //
    > // label2
    > //
    > this->label2->AutoSize = true;
    > this->label2->Location =
    > System::Drawing ::Point(230, 182);
    > this->label2->Name = L"label2";
    > this->label2->Size = System::Drawing ::Size(31,
    > 13);
    > this->label2->TabIndex = 3;
    > this->label2->Text = L"label2";
    > //
    > // button1
    > //
    > this->button1->Location =
    > System::Drawing ::Point(100, 219);
    > this->button1->Name = L"button1";
    > this->button1->Size =
    > System::Drawing ::Size(75, 23);
    > this->button1->TabIndex = 4;
    > this->button1->Text = L"NEXT";
    > //
    > // Form1
    > //
    > this->AutoScaleDimen sions =
    > System::Drawing ::SizeF(6, 13);
    > this->AutoScaleMod e =
    > System::Windows ::Forms::AutoSc aleMode::Font;
    > this->ClientSize = System::Drawing ::Size(292,
    > 266);
    > this->Controls->Add(this->button1);
    > this->Controls->Add(this->label2);
    > this->Controls->Add(this->label1);
    > this->Controls->Add(this->pictureBox1) ;
    > this->Controls->Add(this->trackBar1);
    > this->Name = L"Form1";
    > this->Text = L"Form1";
    >
    > (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=green]
    >>(this->trackBar1))->EndInit();[/color]
    >
    > (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=green]
    >>(this->pictureBox1) )->EndInit();[/color]
    > this->ResumeLayout(f alse);
    > this->PerformLayout( );
    >
    > }
    > #pragma endregion
    > };
    > }
    >
    >
    >[/color]


    Comment

    • Geoff Cox

      #3
      Re: where to place array initialization?

      On Wed, 17 Aug 2005 14:31:06 +0530, "Nishant Sivakumar"
      <nish@nospam.as ianetindia.com> wrote:
      [color=blue]
      >It's a matter of style I guess.[/color]

      Nish,

      Not if you are as much of a C++ beginner as I am! I have found that if
      I put them as below the build works. I cannot workout how to
      declare/initialize an int called qnumber so that I can have

      LHSquestions[qnumber]

      How do I do this? Where would I put something like

      private: int qnumber = 0;

      Cheers

      Geoff

      #pragma once


      namespace trackbar1
      {
      using namespace System;
      using namespace System::Compone ntModel;
      using namespace System::Collect ions;
      using namespace System::Windows ::Forms;
      using namespace System::Data;
      using namespace System::Drawing ;

      /// <summary>
      /// Summary for Form1
      ///
      /// WARNING: If you change the name of this class, you will
      need to change the
      /// 'Resource File Name' property for the managed
      resource compiler tool
      /// associated with all .resx files this class
      depends on. Otherwise,
      /// the designers will not be able to interact
      properly with localized
      /// resources associated with this form.
      /// </summary>
      public ref class Form1 : public System::Windows ::Forms::Form
      {
      public:
      Form1(void)
      {


      InitializeCompo nent();
      //
      //TODO: Add the constructor code here
      //

      this->label1->Text = LHSquestions[qnumber];
      this->label2->Text = RHSquestions[qnumber];


      }

      protected:
      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      /// <param name="disposing ">"descript ion of the
      parameter"</param>
      virtual void Dispose(Boolean disposing) override
      {
      if (disposing && components)
      {
      delete components;
      }
      __super::Dispos e(disposing);
      }
      private: System::Windows ::Forms::TrackB ar^ trackBar1;
      protected:
      private: System::Windows ::Forms::Pictur eBox^ pictureBox1;
      private: System::Windows ::Forms::Label^ label1;
      private: System::Windows ::Forms::Label^ label2;
      private: System::Windows ::Forms::Button ^ button1;

      private: static array<String^>^ LHSquestions = gcnew
      array<String^> {"question 1", "question 2"};
      private: static array<String^>^ RHSquestions = gcnew
      array<String^> {"question 1", "question 2"};



      private:
      /// <summary>
      /// Required designer variable.
      /// </summary>
      System::Compone ntModel::Contai ner ^components;

      #pragma region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not
      modify
      /// the contents of this method with the code editor.
      /// </summary>
      void InitializeCompo nent(void)
      {

      System::Compone ntModel::Compon entResourceMana ger^ resources = (gcnew
      System::Compone ntModel::Compon entResourceMana ger(Form1::type id));
      this->trackBar1 = (gcnew
      System::Windows ::Forms::TrackB ar());
      this->pictureBox1 = (gcnew
      System::Windows ::Forms::Pictur eBox());
      this->label1 = (gcnew
      System::Windows ::Forms::Label( ));
      this->label2 = (gcnew
      System::Windows ::Forms::Label( ));
      this->button1 = (gcnew
      System::Windows ::Forms::Button ());

      (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=blue]
      >(this->trackBar1))->BeginInit();[/color]

      (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=blue]
      >(this->pictureBox1) )->BeginInit();[/color]
      this->SuspendLayout( );
      //
      // trackBar1
      //
      this->trackBar1->Location =
      System::Drawing ::Point(90, 168);
      this->trackBar1->Name = L"trackBar1" ;
      this->trackBar1->Size =
      System::Drawing ::Size(104, 45);
      this->trackBar1->TabIndex = 0;
      this->trackBar1->Scroll += gcnew
      System::EventHa ndler(this, &Form1::trackBa r1_Scroll);
      //
      // pictureBox1
      //
      this->pictureBox1->Image =
      (cli::safe_cast <System::Drawin g::Image^[color=blue]
      >(resources->GetObject(L"pi ctureBox1.Image ")));[/color]
      this->pictureBox1->Location =
      System::Drawing ::Point(37, 13);
      this->pictureBox1->Name = L"pictureBox 1";
      this->pictureBox1->Size =
      System::Drawing ::Size(212, 134);
      this->pictureBox1->TabIndex = 1;
      this->pictureBox1->TabStop = false;
      //
      // label1
      //
      this->label1->AutoSize = true;
      this->label1->Location =
      System::Drawing ::Point(27, 182);
      this->label1->Name = L"label1";
      this->label1->Size = System::Drawing ::Size(31,
      13);
      this->label1->TabIndex = 2;
      this->label1->Text = L"label1";
      //
      // label2
      //
      this->label2->AutoSize = true;
      this->label2->Location =
      System::Drawing ::Point(230, 182);
      this->label2->Name = L"label2";
      this->label2->Size = System::Drawing ::Size(31,
      13);
      this->label2->TabIndex = 3;
      this->label2->Text = L"label2";
      //
      // button1
      //
      this->button1->Location =
      System::Drawing ::Point(100, 219);
      this->button1->Name = L"button1";
      this->button1->Size =
      System::Drawing ::Size(75, 23);
      this->button1->TabIndex = 4;
      this->button1->Text = L"NEXT";
      this->button1->Click += gcnew
      System::EventHa ndler(this, &Form1::button1 _Click);
      //
      // Form1
      //
      this->AutoScaleDimen sions =
      System::Drawing ::SizeF(6, 13);
      this->AutoScaleMod e =
      System::Windows ::Forms::AutoSc aleMode::Font;
      this->ClientSize = System::Drawing ::Size(292,
      266);
      this->Controls->Add(this->button1);
      this->Controls->Add(this->label2);
      this->Controls->Add(this->label1);
      this->Controls->Add(this->pictureBox1) ;
      this->Controls->Add(this->trackBar1);
      this->Name = L"Form1";
      this->Text = L"Form1";
      this->Load += gcnew System::EventHa ndler(this,
      &Form1::Form1_L oad);

      (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=blue]
      >(this->trackBar1))->EndInit();[/color]

      (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=blue]
      >(this->pictureBox1) )->EndInit();[/color]
      this->ResumeLayout(f alse);
      this->PerformLayout( );

      }
      #pragma endregion
      private: System::Void button1_Click(S ystem::Object^ sender,
      System::EventAr gs^ e) {
      ++qnumber;
      this->label1->Text = LHSquestions[qnumber];
      this->label2->Text = RHSquestions[qnumber];
      }
      private: System::Void trackBar1_Scrol l(System::Objec t^ sender,
      System::EventAr gs^ e) {
      }

      private: System::Void Form1_Load(Syst em::Object^ sender,
      System::EventAr gs^ e) {
      }
      };
      }






      [color=blue]
      >One option - You could put all your static array members together.
      >
      >Also note that you don't need to specify "private" for each declaration. One
      >would do.
      >
      >private:
      >static array<String^>^ LHSquestions = gcnew array<String^>{ "question
      >1","question 2"};
      >static array<String^>^ RHSquestions = gcnew array<String^>{ "question
      >1","question 2"};[/color]

      Comment

      • Nishant Sivakumar

        #4
        Re: where to place array initialization?

        > Not if you are as much of a C++ beginner as I am! I have found that if[color=blue]
        > I put them as below the build works. I cannot workout how to
        > declare/initialize an int called qnumber so that I can have
        >
        > LHSquestions[qnumber]
        >
        > How do I do this? Where would I put something like
        >
        > private: int qnumber = 0;[/color]

        You cannot initialize a non-static member. Either make it static (if it
        suites your purpose) or use an initialization list.
        E.g. :-

        ref class Test
        {
        private:
        static int count = 10;
        int x;
        public:
        Test():x(10)
        {
        }
        };

        --
        Regards,
        Nish [VC++ MVP]
        Nish’s thoughts on technology leadership, cloud architecture, and APIs, among other things




        <Geoff Cox> wrote in message
        news:lov5g15i56 9c20k4jjc4qjgdb f5t665ufi@4ax.c om...[color=blue]
        > On Wed, 17 Aug 2005 14:31:06 +0530, "Nishant Sivakumar"
        > <nish@nospam.as ianetindia.com> wrote:
        >[color=green]
        >>It's a matter of style I guess.[/color]
        >
        > Nish,
        >
        > Not if you are as much of a C++ beginner as I am! I have found that if
        > I put them as below the build works. I cannot workout how to
        > declare/initialize an int called qnumber so that I can have
        >
        > LHSquestions[qnumber]
        >
        > How do I do this? Where would I put something like
        >
        > private: int qnumber = 0;
        >
        > Cheers
        >
        > Geoff
        >
        > #pragma once
        >
        >
        > namespace trackbar1
        > {
        > using namespace System;
        > using namespace System::Compone ntModel;
        > using namespace System::Collect ions;
        > using namespace System::Windows ::Forms;
        > using namespace System::Data;
        > using namespace System::Drawing ;
        >
        > /// <summary>
        > /// Summary for Form1
        > ///
        > /// WARNING: If you change the name of this class, you will
        > need to change the
        > /// 'Resource File Name' property for the managed
        > resource compiler tool
        > /// associated with all .resx files this class
        > depends on. Otherwise,
        > /// the designers will not be able to interact
        > properly with localized
        > /// resources associated with this form.
        > /// </summary>
        > public ref class Form1 : public System::Windows ::Forms::Form
        > {
        > public:
        > Form1(void)
        > {
        >
        >
        > InitializeCompo nent();
        > //
        > //TODO: Add the constructor code here
        > //
        >
        > this->label1->Text = LHSquestions[qnumber];
        > this->label2->Text = RHSquestions[qnumber];
        >
        >
        > }
        >
        > protected:
        > /// <summary>
        > /// Clean up any resources being used.
        > /// </summary>
        > /// <param name="disposing ">"descript ion of the
        > parameter"</param>
        > virtual void Dispose(Boolean disposing) override
        > {
        > if (disposing && components)
        > {
        > delete components;
        > }
        > __super::Dispos e(disposing);
        > }
        > private: System::Windows ::Forms::TrackB ar^ trackBar1;
        > protected:
        > private: System::Windows ::Forms::Pictur eBox^ pictureBox1;
        > private: System::Windows ::Forms::Label^ label1;
        > private: System::Windows ::Forms::Label^ label2;
        > private: System::Windows ::Forms::Button ^ button1;
        >
        > private: static array<String^>^ LHSquestions = gcnew
        > array<String^> {"question 1", "question 2"};
        > private: static array<String^>^ RHSquestions = gcnew
        > array<String^> {"question 1", "question 2"};
        >
        >
        >
        > private:
        > /// <summary>
        > /// Required designer variable.
        > /// </summary>
        > System::Compone ntModel::Contai ner ^components;
        >
        > #pragma region Windows Form Designer generated code
        > /// <summary>
        > /// Required method for Designer support - do not
        > modify
        > /// the contents of this method with the code editor.
        > /// </summary>
        > void InitializeCompo nent(void)
        > {
        >
        > System::Compone ntModel::Compon entResourceMana ger^ resources = (gcnew
        > System::Compone ntModel::Compon entResourceMana ger(Form1::type id));
        > this->trackBar1 = (gcnew
        > System::Windows ::Forms::TrackB ar());
        > this->pictureBox1 = (gcnew
        > System::Windows ::Forms::Pictur eBox());
        > this->label1 = (gcnew
        > System::Windows ::Forms::Label( ));
        > this->label2 = (gcnew
        > System::Windows ::Forms::Label( ));
        > this->button1 = (gcnew
        > System::Windows ::Forms::Button ());
        >
        > (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=green]
        >>(this->trackBar1))->BeginInit();[/color]
        >
        > (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=green]
        >>(this->pictureBox1) )->BeginInit();[/color]
        > this->SuspendLayout( );
        > //
        > // trackBar1
        > //
        > this->trackBar1->Location =
        > System::Drawing ::Point(90, 168);
        > this->trackBar1->Name = L"trackBar1" ;
        > this->trackBar1->Size =
        > System::Drawing ::Size(104, 45);
        > this->trackBar1->TabIndex = 0;
        > this->trackBar1->Scroll += gcnew
        > System::EventHa ndler(this, &Form1::trackBa r1_Scroll);
        > //
        > // pictureBox1
        > //
        > this->pictureBox1->Image =
        > (cli::safe_cast <System::Drawin g::Image^[color=green]
        >>(resources->GetObject(L"pi ctureBox1.Image ")));[/color]
        > this->pictureBox1->Location =
        > System::Drawing ::Point(37, 13);
        > this->pictureBox1->Name = L"pictureBox 1";
        > this->pictureBox1->Size =
        > System::Drawing ::Size(212, 134);
        > this->pictureBox1->TabIndex = 1;
        > this->pictureBox1->TabStop = false;
        > //
        > // label1
        > //
        > this->label1->AutoSize = true;
        > this->label1->Location =
        > System::Drawing ::Point(27, 182);
        > this->label1->Name = L"label1";
        > this->label1->Size = System::Drawing ::Size(31,
        > 13);
        > this->label1->TabIndex = 2;
        > this->label1->Text = L"label1";
        > //
        > // label2
        > //
        > this->label2->AutoSize = true;
        > this->label2->Location =
        > System::Drawing ::Point(230, 182);
        > this->label2->Name = L"label2";
        > this->label2->Size = System::Drawing ::Size(31,
        > 13);
        > this->label2->TabIndex = 3;
        > this->label2->Text = L"label2";
        > //
        > // button1
        > //
        > this->button1->Location =
        > System::Drawing ::Point(100, 219);
        > this->button1->Name = L"button1";
        > this->button1->Size =
        > System::Drawing ::Size(75, 23);
        > this->button1->TabIndex = 4;
        > this->button1->Text = L"NEXT";
        > this->button1->Click += gcnew
        > System::EventHa ndler(this, &Form1::button1 _Click);
        > //
        > // Form1
        > //
        > this->AutoScaleDimen sions =
        > System::Drawing ::SizeF(6, 13);
        > this->AutoScaleMod e =
        > System::Windows ::Forms::AutoSc aleMode::Font;
        > this->ClientSize = System::Drawing ::Size(292,
        > 266);
        > this->Controls->Add(this->button1);
        > this->Controls->Add(this->label2);
        > this->Controls->Add(this->label1);
        > this->Controls->Add(this->pictureBox1) ;
        > this->Controls->Add(this->trackBar1);
        > this->Name = L"Form1";
        > this->Text = L"Form1";
        > this->Load += gcnew System::EventHa ndler(this,
        > &Form1::Form1_L oad);
        >
        > (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=green]
        >>(this->trackBar1))->EndInit();[/color]
        >
        > (cli::safe_cast <System::Compon entModel::ISupp ortInitialize^[color=green]
        >>(this->pictureBox1) )->EndInit();[/color]
        > this->ResumeLayout(f alse);
        > this->PerformLayout( );
        >
        > }
        > #pragma endregion
        > private: System::Void button1_Click(S ystem::Object^ sender,
        > System::EventAr gs^ e) {
        > ++qnumber;
        > this->label1->Text = LHSquestions[qnumber];
        > this->label2->Text = RHSquestions[qnumber];
        > }
        > private: System::Void trackBar1_Scrol l(System::Objec t^ sender,
        > System::EventAr gs^ e) {
        > }
        >
        > private: System::Void Form1_Load(Syst em::Object^ sender,
        > System::EventAr gs^ e) {
        > }
        > };
        > }
        >
        >
        >
        >
        >
        >
        >[color=green]
        >>One option - You could put all your static array members together.
        >>
        >>Also note that you don't need to specify "private" for each declaration.
        >>One
        >>would do.
        >>
        >>private:
        >>static array<String^>^ LHSquestions = gcnew array<String^>{ "question
        >>1","questio n 2"};
        >>static array<String^>^ RHSquestions = gcnew array<String^>{ "question
        >>1","questio n 2"};[/color]
        >[/color]


        Comment

        • Geoff Cox

          #5
          Re: where to place array initialization?

          On Wed, 17 Aug 2005 15:06:36 +0530, "Nishant Sivakumar"
          <nish@nospam.as ianetindia.com> wrote:
          [color=blue]
          >You cannot initialize a non-static member. Either make it static (if it
          >suites your purpose) or use an initialization list.[/color]

          Nish,

          Sorry - do not follow. I wish to use the qnumber as the index for the
          array so I assume it cannot be static? Some how I need to declare and
          initialize the int qnumber - but how?

          int qnumber = 0;
          LHSquestions[qnumber]

          Cheers

          Geoff





          [color=blue]
          >E.g. :-
          >
          >ref class Test
          >{
          >private:
          > static int count = 10;
          > int x;
          >public:
          > Test():x(10)
          > {
          > }
          >};[/color]

          Comment

          • Tamas Demjen

            #6
            Re: where to place array initialization?

            Geoff Cox wrote:[color=blue]
            > Sorry - do not follow. I wish to use the qnumber as the index for the
            > array so I assume it cannot be static?[/color]

            Only you know that, it's an important design decision. A static member
            variable is shared between all instances of the class. If you declare
            your variable static, it means every single object will share the same
            variable. A have no idea what qnumber is, and whether it should be
            shared or not. Technically a static member is not owned by the object
            but the class (all objects ever created within the same .exe or .dll).
            [color=blue]
            > Some how I need to declare and initialize the int qnumber - but how?[/color]

            As Nishant has pointed it out before:

            ref class Test
            {
            private:
            int qnumber;
            public:
            Test();
            };

            Test::Test
            : qnumber(0)
            {
            //[...]
            LHSquestions[qnumber]
            //[...]
            }

            Tom

            Comment

            • Geoff Cox

              #7
              Re: where to place array initialization?

              On Wed, 17 Aug 2005 16:14:53 -0700, Tamas Demjen <tdemjen@yahoo. com>
              wrote:
              [color=blue]
              >Only you know that, it's an important design decision. A static member
              >variable is shared between all instances of the class. If you declare
              >your variable static, it means every single object will share the same
              >variable.[/color]

              Tamas,

              Thanks for above - I had misunderstood static ... incidentally I
              thought I had found 2 books on Visual C++ 2005 Express but they are
              not due out until October/November - can you suggest any good sites
              for Visual C++ 2005 Express language for beginners? So far I have
              found C# quite a bit easier to understand but I understand that the
              combination of Visual C++ 2005 Express and the Windows SDK allows the
              creation of Win32 apps .. so that would be interesting. Back to the
              error messages ..

              I seem to have the correct code for qnumber, the index for the results
              array but am getting a couple of errors which you might underatnd!

              line 155 error C2227 left of '->ToString' must point to
              class/struct/union/generic type
              line 181 error C2228 left of '.Close' must have class/struct/union

              I have following for initialization which I think is OK.


              private: static array<String^>^ LHSquestions = gcnew array<String^>
              {"question 1", "question 2"};

              private: static array<String^>^ RHSquestions = gcnew array<String^>
              {"question 1", "question 2"};

              private: static int qnumber = 0;

              private: static array<String^>^ results = gcnew array<String^>
              [LHSquestions->Length];



              the first error message comes for next line

              this->results[qnumber] = trackBar1->Value->ToString(); // line 155



              and the second error message for line 188 below

              TextWriter^ outfile = gcnew StreamWriter("h :\\a-temp1\\data.txt ");

              for (int i=0; i < LHSquestions->Length; i++) {


              outfile->WriteLine(resu lts[i]);

              }

              outfile.Close() ; // line 188



              Cheers

              Geoff













              A have no idea what qnumber is, and whether it should be[color=blue]
              >shared or not. Technically a static member is not owned by the object
              >but the class (all objects ever created within the same .exe or .dll).
              >[color=green]
              >> Some how I need to declare and initialize the int qnumber - but how?[/color]
              >
              >As Nishant has pointed it out before:
              >
              >ref class Test
              >{
              >private:
              > int qnumber;
              >public:
              > Test();
              >};
              >
              >Test::Test
              > : qnumber(0)
              >{
              > //[...]
              > LHSquestions[qnumber]
              > //[...]
              >}
              >
              >Tom[/color]

              Comment

              • Geoff Cox

                #8
                Re: where to place array initialization?

                On Wed, 17 Aug 2005 16:14:53 -0700, Tamas Demjen <tdemjen@yahoo. com>
                wrote:

                Tam

                re my message with the 2 errors - have found the cause of the 2nd one
                - I had outfile.Close() instead of outfile->Close()

                also found error in the other code but still get 2 similar error
                messages

                results[qnumber] = trackBar1_Scrol l->Value->ToString();

                (I had trackBar1 not trackBar1_Scrol l)

                error messages re above

                error C2227: left of '->Value' must point to
                class/struct/union/generic type
                error C2227: left of '->ToString' must point to
                class/struct/union/generic type

                thoughts?

                Cheers

                Geoff


                Comment

                • Tamas Demjen

                  #9
                  Re: where to place array initialization?

                  Geoff Cox wrote:
                  [color=blue]
                  > Thanks for above - I had misunderstood static ... incidentally I
                  > thought I had found 2 books on Visual C++ 2005 Express but they are
                  > not due out until October/November - can you suggest any good sites
                  > for Visual C++ 2005 Express language for beginners?[/color]

                  I'm waiting for this book to be published (I don't know when it will be
                  available):

                  (or)


                  The problem is that your questions are not strictly C++/CLI related.
                  You're trying to learn C++/CLI without a strong C++ background. I don't
                  know C++/CLI as extensively as C++ -- few people know it inside out,
                  other than Microsoft engineers. But knowing C++ well certainly helps a
                  lot. I'm not saying you'll absolutely have to learn C++ before you can
                  learn C++/CLI, but given the fact that there are no C++/CLI books
                  available yet, your best bet at this moment is to rely on existing
                  resources and the draft standard.
                  [color=blue]
                  > So far I have
                  > found C# quite a bit easier to understand[/color]

                  Difficult problems sometimes can not be addressed efficinetly in a
                  flexible ways with simple tools. But with .NET you have the advantage of
                  mixing languages. For example, you may prefer designing the GUI in C#
                  while writing lower level libraries in C++.
                  [color=blue]
                  > line 155 error C2227 left of '->ToString' must point to
                  > class/struct/union/generic type
                  > line 181 error C2228 left of '.Close' must have class/struct/union[/color]

                  try
                  ..ToString()
                  ->Close()

                  You use -> for pointers and handles. You use . otherwise (value types,
                  references). I know it may seem confusing first for people coming from
                  VC, C#, Delphi and similar languages where . applies to handles as well
                  as value types. In C++ there is a big difference. In fact, with smart
                  pointers .get() and ->get() have entirely different meaning, you can't
                  mix them.

                  Tom

                  Comment

                  • Tamas Demjen

                    #10
                    Re: where to place array initialization?

                    Tamas Demjen wrote:[color=blue]
                    > I know it may seem confusing first for people coming from
                    > VC, ...[/color]

                    I meant VB not VC.

                    Tom

                    Comment

                    • Geoff Cox

                      #11
                      Re: where to place array initialization?

                      On Thu, 18 Aug 2005 10:11:27 -0700, Tamas Demjen <tdemjen@yahoo. com>
                      wrote:

                      Tamas

                      Thanks for your rhoughts. I have made a couple of steps forward in
                      that I can now create an array with the same number of elements as
                      there are in another array!

                      private: static array<String^>^ results = gcnew
                      array<String^>( otherArray->Length);

                      although I do not understand the use of the ^ yet!

                      Also, have been able to access the Scroll value of the trackbar

                      trackBar1->Value

                      Another odd one (to me!) in that the entry to the right of the Scroll
                      Event in Visual C++ 2005 Express Beta 2 is trackBar1_Scrol l so I
                      thought the value would be

                      trackBar1_Scrol l->Value

                      One I have not solved yet is making a button invisible - I thought it
                      would be

                      button1->Visible(false) ;

                      but this does not work! Any ideas?

                      Cheers

                      Geoff


                      [color=blue]
                      >I'm waiting for this book to be published (I don't know when it will be
                      >available):
                      >http://www.amazon.com/exec/obidos/tg...books&n=507846
                      >(or)
                      >http://tinyurl.com/b4c3c
                      >
                      >The problem is that your questions are not strictly C++/CLI related.
                      >You're trying to learn C++/CLI without a strong C++ background. I don't
                      >know C++/CLI as extensively as C++ -- few people know it inside out,
                      >other than Microsoft engineers. But knowing C++ well certainly helps a
                      >lot. I'm not saying you'll absolutely have to learn C++ before you can
                      >learn C++/CLI, but given the fact that there are no C++/CLI books
                      >available yet, your best bet at this moment is to rely on existing
                      >resources and the draft standard.
                      >[color=green]
                      >> So far I have
                      >> found C# quite a bit easier to understand[/color]
                      >
                      >Difficult problems sometimes can not be addressed efficinetly in a
                      >flexible ways with simple tools. But with .NET you have the advantage of
                      >mixing languages. For example, you may prefer designing the GUI in C#
                      >while writing lower level libraries in C++.
                      >[color=green]
                      >> line 155 error C2227 left of '->ToString' must point to
                      >> class/struct/union/generic type
                      >> line 181 error C2228 left of '.Close' must have class/struct/union[/color]
                      >
                      >try
                      >.ToString()
                      >->Close()
                      >
                      >You use -> for pointers and handles. You use . otherwise (value types,
                      >references). I know it may seem confusing first for people coming from
                      >VC, C#, Delphi and similar languages where . applies to handles as well
                      >as value types. In C++ there is a big difference. In fact, with smart
                      >pointers .get() and ->get() have entirely different meaning, you can't
                      >mix them.
                      >
                      >Tom[/color]

                      Comment

                      • Geoff Cox

                        #12
                        Re: where to place array initialization?

                        On Thu, 18 Aug 2005 08:49:46 +0100, Geoff Cox <> wrote:

                        [color=blue]
                        >results[qnumber] = trackBar1_Scrol l->Value->ToString();[/color]

                        Sorted - it should have been

                        results[qnumber] = trackBar1->Value.ToString ();

                        Cheers

                        Geoff


                        Comment

                        Working...