Thread: Conversion with a twist (help needed)

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    4

    Conversion with a twist (help needed)

    Hello everyone, I am new to C++ (all the pros run yelling, "A noob is coming!!" lol) and I am enjoying all that I've learned so far. I have mainly been working with console applications (Plain C really using VC++ 6.0) in class. Our first quarter has ended and I started up a small project to keep myself in tune for the advanced C++ class coming up and to learn VS.Net 2003. I have ran into a problem that I really need help with. Please take it easy on me if I'm not clear or make some mistakes, I'm still a fresh student lol.

    ***Here is what I would like the program to do:
    I would like to take all my old console applications, and put them into a GUI application using VS 2003 .NET. I have designed a form with a combobox, 2 buttons (Start and Exit), and a textbox in which I have stretched out to look like the console. My idea is to use the combobox to select a project from any given chapter, when the start button is clicked that program will run as it should if it were a console application! I want it to accept user input, use the data, and then display the output to the textbox/Console Emulator.

    ***Here is my problem:
    I have successfully passed the textbox to a function called helloWorld and it writes text to the Console Emulator. The only problem that I have no idea how to do is somewhat "stop" or "pause" the program and let the user enter, then continue the rest of the program. Here is my code to show you what I mean.

    Code:
    #include "stdafx.h"
    using namespace System;
    //use System::Windows::Forms to minimize typing that plus TextBox *
    using namespace System::Windows::Forms;
    
    void helloWorld(TextBox *txtConsole, TextBox *txtResponse) //pass by pointer
    {
    	String *answer;
    
    	txtConsole->AppendText("Hello World!");
    	txtConsole->AppendText("\n");
    	txtConsole->AppendText("How are you today? (good or bad) ");
    
    	Here is where I need to stop/pause the program in order to get the users response.
    
    	answer = txtResponse->Text;
                    
                    if(answer == "Good" || answer == "good")
                    {
                               txtConsole->AppendText("\n");
                               txtConsole->AppendText("Thats GREAT!");
                    }
                    else
                    {
                               txtConsole->AppendText("\n");
                               txtConsole->AppendText("Bummer!");
                    }
    }
    I don't really know what to do at this point. I'm use to cin and cout methods of input and output. Can anyone give me some pointers (no pun intended) on what I could possibly do here?


    ***Also, is there anyway to put or use a console within a form? Like I did with the buttons/textbox's?

    I am a newbie so bare with my level of detail please. Also, if you need more of my code I'll gladly put it up, but I think I've covered the jist of what I wanted too. (Is there a way to add an attachment to these forums?)
    Last edited by Mosquito; 06-08-2005 at 09:40 PM.

  2. #2
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    You can attach stuff, just look

    What i would do

    Have two functions for you console textbox. first puts text in there. second read text from there.
    Should be simple enough, i dont know VC .net much yet so i can be two specific

    You can add you code from your other projects, into your code from here. Make them functions < like startPrj4() > and in those functions, any time you would have used a Cout, use a AppendText,
    Cin is where it gets harder. you need to parse whatever input you get
    good luck
    my 2cents

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    4
    Thank you for your response Iamien!

    You have actually pointed out something that I failed to mention in my original post. I have another textbox that I get the user to enter their result in; txtResponse.

    Will that actually "pause" the program and allow the user to enter their response in between functions?

  4. #4
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    you could just do a
    system("pause");
    that won't continue program execution until the user presses a key in the console.
    Registered Linux User #380033. Be counted: http://counter.li.org

  5. #5
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Did you learn state machines yet in class? that's usually one of the early assignments. This is a perfect situation... you do the output, then you go into a waiting for input state except you have to coordinate it with the windows message system. OR... get rid of the input textbox and instead do a Modal input dialog box whenever you need input...this method would be more linear ... and the flow would be closer to the way it would be in a console app.

    As far as system"pause";, that has got to be the worst suggestion ever...sure it will pause your program, but it will open up a console window to do so!!! hmm...Maybe he said that as a joke

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    4
    Yeah, system("PAUSE") would stop the program but open up a console which I do not want to do. I did try that so I know thats what it will do lol.

    Actually we have not learned state machines yet. I'm interested in this method. Could you point me to a good article or tutorial that may demonstrate this method? Thanks Darryl!

    Any help/advice would be greatly appreciated!

  7. #7
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Ok I all the tutorials I found were either too technical or too specific to a specif task, but here is one that is pretty general and not so technical, hopefully it will help get you started.

    http://www.generation5.org/content/2...M_Tutorial.asp

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    4
    Thanks a ton Darryl. I'll keep you updated on my progress!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  4. Do I have a scanf problem?
    By AQWst in forum C Programming
    Replies: 2
    Last Post: 11-26-2004, 06:18 PM