1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Global variable

Discussion in 'C++' started by iliyan_84, Sep 2, 2010.

  1. iliyan_84

    iliyan_84 New Member

    Joined:
    Sep 2, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    I will explain my problem in short. I make a window form application and add 3 buttons. When a press button 1. I want to create 8 or 16 or 32 combobox and i make this with follow code:
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    golfunctions=32;
    array^ pcom = gcnew array(golfunctions);
    Code:
    			
    			 	x=28; y=106; j=0;
    			 for(i=0;iSuspendLayout();			
    				pcom[i]->FormattingEnabled = true;
    				pcom[i]->Items->AddRange(gcnew cli::array< System::Object^  >(3) {L"0", L"1", L"x"});
    				pcom[i]->Location = System::Drawing::Point(x, (y+20));
    				pcom[i]->Size = System::Drawing::Size(35, 20);
    				pcom[i]->TabIndex = 36;
    	
    			Controls->Add(pcom[i]);
    		
    
    				x+=35;
    				if((i==15)&&(j==0))
    				{
    					x=28;
    					j++;
    					y+=40;
    				}
    			
    				
    				
    			}
    
    This work fine! After that i want to take the choosen value ot each combobox when i press button 2 but
    private: System::Void Add_Click(System::Object^ sender, System::EventArgs^ e) {


    for(i=0;iSelectedItem);
    .....
    //if(pcom->SelectedItem

    }
    }
    i compile program and work to the moment when i press button 2 and
    show error. i start the program in debbuge mode: at row
    temp=System::Convert::ToChar(pcom->SelectedItem);
    show -pcom
    pcom error: index 'i' out of bound for pointer/array 'pcom'
    My supposition it that i make pcom local variable and can`t use in range of button2
    any i ideas who to make that ot how to find decision of this problem
     

Share This Page