Too many lines of code causing linking errors...

Quantum7 21 Reputation points
2021-03-07T06:32:35.11+00:00

I'm running visual studio 2017 with visual c++ CLR. There seems to be a lot of code in my form1.h header file, to the point of causing linking errors. I was thinking that I might be able to store code in cpp files and write to the form1.h file from the cpp files. How do I write to the h file from cpp files?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,542 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 9,181 Reputation points Microsoft Vendor
    2021-03-09T07:27:30.403+00:00

    Hi,

    Too many lines of code causing linking errors...

    I have tried the code you provided, and there was no link error. Could you please provide more details about the link error message?

    And while testing your code, I found the following problems.

    1,Like I said in the other two threads you posted, When you add controls to the form, vs will automatically instantiate the object, and you couldn't need to repeat by yourself.

    2,As far as I'm concerned, the assignment logic of your text box inputs is reversed. You should try to use in1 = textBox1->Text; instead of textBox1->Text = in1;

    I suggest you could refer to the following code:

    String^ in1;  
    //System::Windows::Forms::TextBox^ textBox1;  
    //textBox1->Text = in1;  
    in1 = textBox1->Text;  
    
    String^ in2;  
    //System::Windows::Forms::TextBox^ textBox2;  
    //textBox2->Text = in2;  
    in2 = textBox2->Text;  
    
    String^ in3;  
    //System::Windows::Forms::TextBox^ textBox3;  
    //textBox3->Text = in3;  
    in3 = textBox3->Text;  
    
    String^ in4;  
    //System::Windows::Forms::TextBox^ textBox4;  
    //textBox4->Text = in4;  
    in4 = textBox4->Text;  
    
    String^ in5;  
    //System::Windows::Forms::TextBox^ textBox5;  
    //textBox5->Text = in5;  
    in5 = textBox5->Text;  
    
    
    
    
    
    
    
    modulator^oInst = gcnew modulator();  
    double etresult = oInst->main(element_total);  
    String^ out1 = Convert::ToString(etresult);  
    //System::Windows::Forms::TextBox^ textBox6;  
    textBox6->Text = out1;  
    
    modulator ^oInst1 = gcnew modulator();  
    double cresult = oInst1->main(c_nmw);  
    modulator ^oInst2 = gcnew modulator();  
    double hresult = oInst2->main(h_nmw);  
    modulator ^oInst3 = gcnew modulator();  
    double nresult = oInst3->main(n_nmw);  
    modulator ^oInst4 = gcnew modulator();  
    double oresult = oInst4->main(o_nmw);  
    modulator ^oInst5 = gcnew modulator();  
    double presult = oInst5->main(p_nmw);  
    double long color_result = cresult + hresult + nresult + oresult + presult;  
    modulator ^oInst6 = gcnew modulator();  
    double c_result = oInst6->main(color_result);  
    String^ out2 = Convert::ToString(c_result);  
    //System::Windows::Forms::TextBox^ textBox7;  
    textBox7->Text = out2;  
    
    double long mix_result = etresult + c_result;  
    modulator ^oInst7 = gcnew modulator();  
    double m_result = oInst7->main(mix_result);  
    String^ out3 = Convert::ToString(m_result);  
    //System::Windows::Forms::TextBox^ textBox8;  
    textBox8->Text = out3;  
    

    3,In mod1.h, there is a problem with your loop logic. When modinput is greater than 780.9 * 2, modinput must also be greater than 780.9,and so on... And the return value is outside the while loop, so there is no way to jump out of the loop and cause the program to not respond. I suggest that you could compare in segments, such as 780.9~780.9*2,780.9*2~780.9*4, and so on... and you could add the return value in each if statement.

    I suggest you could refer to the following code:

    if (780.9<modinput <= 780.9*2) {  
    modpass = modinput / 2;  
    return modpass;  
    };  
    if (780.9*2 < modinput <= 780.9 * 4) {  
    modpass = modinput / 4;  
    return modpass;  
    };  
    ……  
    

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments