CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Aug 2011
    Posts
    80

    Windows form < Use texbox values for system commands

    Hi all,

    i just started playing with gui apps. My first test is a small ping app.

    I've created a new project (windows forms) containing:

    1: image
    2: textbox
    3: 2 x button (1 exit, 1 ping)

    Now when i click on exit, the app extits... "really "

    When i click on ping, i''m getting a popup with the information from the textfield. This is cool, but i want to run the system command ping with the textbox value.

    This is what i have:

    Code:
    #pragma endregion
    	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    				 Application::Exit();
    			 }
    	
    	private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    				 
    				 String^ result = textBox1->Text;
    				 MessageBox::Show( result );
    ////////////// When i comment the messagebox and try:
                                     system("ping -n 2 " + result + " > C:\\pingtest.txt");
    ////////////// i get errors (shown below)
    			 }
    	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    			 
    			 }
    };
    ERROR:
    Code:
    error C2664: 'system' : cannot convert parameter 1 from 'System::String ^' to 'const char *'
    Only with:

    Code:
     
    private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    	 system("ping -n 2 www.google.nl > C:\\pingtest.txt");
    }
    it does work, but i can't use the textbox value.

    So i need to convert "result" i think, but i don't know how to do this correctly and let ping run with the result as parameter

    Any ideas ?
    Last edited by peewster; June 28th, 2012 at 02:48 AM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured