Thread: simple vc++ question about textbox

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    89

    simple vc++ question about textbox

    why doesnt this work in VC++?

    Code:
     std::string un, pw;
     un = fUsername->Text;
     pw = fPassword->Text;
    I am guessing it has to do with the fact that Text is some different datatype than string but I have no idea what it might be.
    Last edited by Ken Fitlike; 07-07-2006 at 03:05 PM. Reason: fixed code tags

  2. #2
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Uhm, what is fUsername or fPassword for that matter?

    You need to give some more info on what they are...

    Are they edit controls?

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    89
    sorry. yes they are text fields where the user can enter information.

  4. #4
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Are they pointers? References?

    We need more information.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    89
    sorry this is my first time with vc++ so I guess I am taking the different capablities for granted. This is so simple that I kind of overlooked how it could have been interpreted. Here are all the pieces of code associated with fUsername to give some more insight. fPassword is pretty much the exact same.

    Code:
    void InitializeComponent(void)
    		{
    			this->fUsername = (gcnew System::Windows::Forms::TextBox());
    
    //.....skip some code
    
    			// fUsername
    			// 
    			this->fUsername->Location = System::Drawing::Point(70, 7);
    			this->fUsername->Name = L"fUsername";
    			this->fUsername->Size = System::Drawing::Size(80, 20);
    			this->fUsername->TabIndex = 0;
    			this->fUsername->Text = L"username here";
    
    //.... skip some code
    
    this->Controls->Add(this->fUsername);
    here is the code attached to my button:
    Code:
    private: System::Void bConnect_Click(System::Object^  sender, System::EventArgs^  e) {
    				 std::string un, pw, params, path;
    				 un = fUsername->Text;
    				 pw = fPassword->Text;
    				 path = "C:\\plink.exe";
    				 params = L" -ssh ";
    				 params += un;
    				 params += L"@server.xxx.xxx.xxx";
    				 int r = ExecuteProcess(path, params, 0);
    				 if (r != 0){
    					 MessageBox::Show("Error executing process", "OPTIM-App",
    					 MessageBoxButtons::OK, MessageBoxIcon::Asterisk);
    				 }
    			 }
    This is my first time using visual c++, first time creating any GUI c++ app for that matter. I didnt think grabbing some text from 2 fields would give me such a headache, would have taken 2 seconds with a command line app haha. Anyway I was just following syntax I had seen in other examples but I apparently understood it wrong.
    thanks

  6. #6
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Everything I am seeing there looks like c# to me. Is this some sort of API you are using over the top? Cus seeing System:: ... etc makes me think C# or java immediately. Please elaborate, thanks.

  7. #7
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    This looks like that C++/CLI managed crap that isn't really C++ at all.
    Quote Originally Posted by Stanley B. Lippman, Microsoft
    C++/CLI is a self-contained, component-based dynamic programming language that, like C# or Java, is derived from C++.
    Source

    In any case, this probably belongs on the windows board
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    89
    Umm this is the windows board? And all that code is what was generated by vc++ when I was making my form. I agree that it doesnt really look like c++ and that why I really dont understand how to make it work. I mean I see the general idea of what it is doing but syntactically I can't figure out how to make use out of it. I hate all this managed/unmanaged bs, I just want to write my damn program like I normally would for a command line and have it work when I press a button.... anyway, can anyone tell me how to get text from those fields?
    Last edited by ac251404; 07-11-2006 at 08:16 AM.

  9. #9
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    Maybe some .NET topics might help, which your code is more .NET than API
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  10. #10
    Registered User
    Join Date
    May 2006
    Posts
    89
    Yea I have been reading a lot more and I don't know if vc++ is for me. I thought it would be easier to just whip up some forms and attach the buttons to c++ code I already had to make a simple GUI but it just ain't that easy.

    I have finally resolved this issue however and it had to do with the 340973460 different strings available in visual c++. I had to use String^ instead of std::string to get the info from the text boxes, then in order to pass it to my function I had to convert the String^ into a std::string via a To_string function I found from someone else with this issue.

    Is there any easier damn way to make some simple GUIs? i.e. grab a few things from text boxes and do stuff when you click a button. Maybe even output some text to the window? I'm not trying to do anything to fancy here.

    thanks for all the replies
    -a

  11. #11
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    I would suggest perhaps using MFC, but I am sure somewhere I would get beaten by pillow wielding-freaks.

    Honestly, what compiler are you using? I can't believe it would generate mixed code such as this in C++ anyway.

  12. #12
    Registered User
    Join Date
    May 2006
    Posts
    89
    I just downloaded visual c++ 2005 express and installed it, so whatever compiler is used with that. I had VS 2003 but couldnt get it to install from the CDs because it wanted to take 10 hours so I said screw it. I just wanted to make an easy GUI to test some stuff out with basically and here I am more confused than when I began haha.

    By the way not all that code was generated by vc++, but most of it was. I think the only things I changed were on the button.
    Last edited by ac251404; 07-11-2006 at 12:17 PM.

  13. #13
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    > Umm this is the windows board?

    Wasn't this originally posted in the C++ board? Maybe I wasn't paying attention...

    > I had VS 2003 but couldnt get it to install from the CDs because it wanted to take 10 hours so I said screw it.

    Yeah VS 2003 is by far the longest install of any program I've had in a long time.

    I suppose a language like VB or C# might be easier for making GUI apps; as for C++, I'm just plain confused sometimes as to what I should be using to be prepared for the future of windows programming, although I like Win32 because it gives plenty of control (even if it leads to ugly, horrible messes of code)
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  14. #14
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Just my opinion....

    Use C# (is becoming widely used commercially)

    OR (as I'm an old f__t, resistant to change)

    Install VS2003.

    Use MFC (MS WIN32 wrapper) and as you get better, more comfortable with the way MFC works move into the WIN32 API.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  2. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Textbox Question
    By Smoose777 in forum C# Programming
    Replies: 1
    Last Post: 06-14-2002, 06:30 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM