Transformation Error. I can not output a variable in TextBox Read more: http://forum
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Transformation Error. I can not output a variable in TextBox Read more: http://forum

  1. #1
    Join Date
    Aug 2012
    Location
    Ukraine, Odessa
    Posts
    19

    Transformation Error. I can not output a variable in TextBox Read more: http://forum

    Hi, all. Please, Help me. Its very important for me. I try to output a variable, type string, in TextBox. I tried everything that I could. But always the mistake. And i show you a file Form1.h in which i have got a problem.

    That's my project

    Code:
    private: System::Void button20_Click(System::Object^  sender, System::EventArgs^  e)
            {
            adding();
            textBox1->Text = b.ToString();
      
    
            }
    
    Read more: http://forum.codecall.net/topic/73059-transformation-error-i-can-not-output-a-variable-in-textbox/#ixzz2DEsO7nNe
    Code:
    void adding()
    {
      b = (textBox1.Text).ToString();
    // b = (richTextBox1->Text).ToString();
    
    /*CLargeNumber oLN1 = CLargeNumber(1000000);
    oLN1 -= CLargeNumber(2000000);
    cout << "Answer " << cout << oLN1.ToString() << endl;
    system("pause");*/
     
    //Testing the LargeNumber class
    CLargeNumber oLN1(a);
    CLargeNumber oLN2(B);
    b=(oLN1+oLN2).ToString();
    }
    
    Read more: http://forum.codecall.net/topic/73059-transformation-error-i-can-not-output-a-variable-in-textbox/#ixzz2DEsUjXhv

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,352

    Re: Transformation Error. I can not output a variable in TextBox Read more: http://f

    Dear Pahanuch,
    unfortunately your code has nothig to do with VC++ not is it a native C++ code.
    What you showed us looks like managed C++ code that is discussed in a corresponding Managed C++ and C++/CLI forum.
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2012
    Location
    Ukraine, Odessa
    Posts
    19

    Re: Transformation Error. I can not output a variable in TextBox

    Thank U. I decided this problem

    Code:
    std::string str;
     
                     const char* temp = (const char*)(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(textBox1->Text)).ToPointer();
                     str = temp;
                     System::Runtime::InteropServices::Marshal::FreeHGlobal(IntPtr((void*)temp));
     
                     textBox2->Text = gcnew String(str.c_str() );

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Thumbs down Re: Transformation Error. I can not output a variable in TextBox

    Quote Originally Posted by Pahanuch View Post
    Thank U. I decided this problem

    Code:
    std::string str;
     
                     const char* temp = (const char*)(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(textBox1->Text)).ToPointer();
                     str = temp;
                     System::Runtime::InteropServices::Marshal::FreeHGlobal(IntPtr((void*)temp));
     
                     textBox2->Text = gcnew String(str.c_str() );
    (sorry for the smiley overkill... )

    This crude mix of managed and native code is by far the creepiest example of that "technique" I've ever seen!

    And it's functionally exactly equivalent to this:

    Code:
    textBox2->Text = textBox1->Text;
    You'd probably have been much quicker simply looking up the correct C++/CLI syntax for working with reference types like System::String than digging out all that (in this context absolutely counter-productive) interop stuff.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Transformation Error. I can not output a variable in TextBox Read more: http://f

    [ redirected ]

    I don't know what exactly you're trying to do, but this looks seriously bad. Can you explain in details what do you want to store in the textbox?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    Aug 2012
    Location
    Ukraine, Odessa
    Posts
    19

    Re: Transformation Error. I can not output a variable in TextBox Read more: http://f

    Eri523, it was just an example. I don't need to equate
    Code:
    textBox2->Text = textBox1->Text;
    First. I need to convert a variable, type string. And output it in a richTextBox1.
    Second. And I need to get value from TextBox1 and TextBox2 to variables, type string.
    Last edited by Pahanuch; November 27th, 2012 at 07:15 PM.

  7. #7
    Join Date
    Aug 2012
    Location
    Ukraine, Odessa
    Posts
    19

    Re: Transformation Error. I can not output a variable in TextBox Read more: http://f

    cilu , I want to do calculator for very large numbers. textBox1 - for first number. textBox2 - for second number. And richTextBox1 for output answer.

  8. #8
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: Transformation Error. I can not output a variable in TextBox Read more: http://f

    Quote Originally Posted by Pahanuch View Post
    First. I need to convert a variable, type string. And output it in a richTextBox1.
    Second. And I need to get value from TextBox1 and TextBox2 to variables, type string.
    You don't actually need to do any conversion between text boxes and variables of type System::String. The text box' Text property is of the very same type System::String so you can freely do assignments back and forth between the two.

    Quote Originally Posted by Pahanuch View Post
    [...] I want to do calculator for very large numbers. textBox1 - for first number. textBox2 - for second number. And richTextBox1 for output answer.
    For this you actually would need to do some conversion. Unless you're going to write your own bignum class (what I somewhat doubt), you'd probably use the BigInteger class. It features the Parse() and TryParse() methods supported by most numeric types to convert from a string and ToString() to convert to a string. (Actually, ToString() is supported by literally all .NET types, but for many types it doesnt return a really useful result.)
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  9. #9
    Join Date
    Aug 2012
    Location
    Ukraine, Odessa
    Posts
    19

    Re: Transformation Error. I can not output a variable in TextBox

    Eri523 Thank U very mush. For my program I used this class.

    I was trying Parse(), TryParse() and ToString(). The compiler gave out a mistake(

  10. #10
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: Transformation Error. I can not output a variable in TextBox

    Quote Originally Posted by Pahanuch View Post
    [...] For my program I used this class.
    This class is native C++, and although it can be done in C++/CLI, managed and native code shouldn't be mixed without a really good reason to do so. If done by people who don't know exactly what they're doing, it may lead to weird code like that in post #3.

    I was trying Parse(), TryParse() and ToString(). The compiler gave out a mistake(
    Getting plain error messages when trying to use the correct language/library features is not a good reason to use questionable (in this context) techniques instead. The error messages are there to tell you there's something wrong with your code, so you have the opportunity to fix it. Once you have fixed it, you have a solid .NET program, and when something goes wrong with that at runtime, the exceptions thrown by .NET code usually carry some information that are quite helpful in diagnosing the problem. OTOH, interop, when done wrong, may not cause compiler or linker errors, but later lead to a malfunctioning program at runtime. And this sort of problem often is pretty hard to find...

    So I suggest you post the .NET-based code you can't get to compile, preferably along with the error messages you get, and we try to fix it together.
    Last edited by Eri523; November 28th, 2012 at 04:13 AM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center