How to write the simplest Windows program?

Discussion in 'C++' started by Knut Olsen-Solberg, Feb 19, 2007.

  1. This is the program:
    The Form has 3 TextBoxes and 1 Button. The user uses the keyboard to
    enter a number in each of the two first TexBoxes, presses the Button,
    and the sum of the numbers appears in the third TextBox.

    In Borland Builder the OnClick event of the Button can look like this
    (if the TextBoxes are named N1, N2 and N3):

    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    double A = N1->Text.ToDouble();
    double B = N2->Text.ToDouble();

    N3->Text=A+B;
    }

    In MS Visual C++ 2005 Express Edition I miss the ToDouble function. How
    can it be done here? Can anyone help ?

    Regards Knut
    Knut Olsen-Solberg, Feb 19, 2007
    #1
    1. Advertising

  2. Knut Olsen-Solberg

    John Ratliff Guest

    Knut Olsen-Solberg wrote:
    > This is the program:
    > The Form has 3 TextBoxes and 1 Button. The user uses the keyboard to
    > enter a number in each of the two first TexBoxes, presses the Button,
    > and the sum of the numbers appears in the third TextBox.
    >
    > In Borland Builder the OnClick event of the Button can look like this
    > (if the TextBoxes are named N1, N2 and N3):
    >
    > void __fastcall TForm1::Button1Click(TObject *Sender)
    > {
    > double A = N1->Text.ToDouble();
    > double B = N2->Text.ToDouble();
    >
    > N3->Text=A+B;
    > }
    >
    > In MS Visual C++ 2005 Express Edition I miss the ToDouble function. How
    > can it be done here? Can anyone help ?
    >
    > Regards Knut


    Take a look at std::strtod in <cstdlib>.

    That should convert a string to a double. You'll have to pass it a
    C-string though, but your text control surely has some conversion for this.

    --John Ratliff
    John Ratliff, Feb 19, 2007
    #2
    1. Advertising

  3. Knut Olsen-Solberg

    Ryszard Guest

    Knut Olsen-Solberg napisał(a):
    > This is the program:
    > The Form has 3 TextBoxes and 1 Button. The user uses the keyboard to
    > enter a number in each of the two first TexBoxes, presses the Button,
    > and the sum of the numbers appears in the third TextBox.
    >
    > In Borland Builder the OnClick event of the Button can look like this
    > (if the TextBoxes are named N1, N2 and N3):
    >
    > void __fastcall TForm1::Button1Click(TObject *Sender)
    > {
    > double A = N1->Text.ToDouble();
    > double B = N2->Text.ToDouble();
    >
    > N3->Text=A+B;
    > }
    >
    > In MS Visual C++ 2005 Express Edition I miss the ToDouble function. How
    > can it be done here? Can anyone help ?
    >
    > Regards Knut


    double A = Double::parse(Text);

    Regards Ryszard
    Ryszard, Feb 19, 2007
    #3
  4. Ryszard wrote:
    > Knut Olsen-Solberg napisał(a):
    >> This is the program:
    >> The Form has 3 TextBoxes and 1 Button. The user uses the keyboard to
    >> enter a number in each of the two first TexBoxes, presses the Button,
    >> and the sum of the numbers appears in the third TextBox.
    >>
    >> In Borland Builder the OnClick event of the Button can look like this
    >> (if the TextBoxes are named N1, N2 and N3):
    >>
    >> void __fastcall TForm1::Button1Click(TObject *Sender)
    >> {
    >> double A = N1->Text.ToDouble();
    >> double B = N2->Text.ToDouble();
    >>
    >> N3->Text=A+B;
    >> }
    >>
    >> In MS Visual C++ 2005 Express Edition I miss the ToDouble function.
    >> How can it be done here? Can anyone help ?
    >>
    >> Regards Knut

    >
    > double A = Double::parse(Text);
    >
    > Regards Ryszard



    Thanks!
    Still I have a problem getting A+B back to N3->Text. Can you show me
    this too?

    Regards Knut
    Knut Olsen-Solberg, Feb 20, 2007
    #4
  5. On Feb 20, 10:21 am, Knut Olsen-Solberg <> wrote:
    > Ryszard wrote:
    > > Knut Olsen-Solberg napisał(a):
    > >> This is the program:
    > >> The Form has 3 TextBoxes and 1 Button. The user uses the keyboard to
    > >> enter a number in each of the two first TexBoxes, presses the Button,
    > >> and the sum of the numbers appears in the third TextBox.

    >
    > >> In Borland Builder the OnClick event of the Button can look like this
    > >> (if the TextBoxes are named N1, N2 and N3):

    >
    > >> void __fastcall TForm1::Button1Click(TObject *Sender)
    > >> {
    > >> double A = N1->Text.ToDouble();
    > >> double B = N2->Text.ToDouble();

    >
    > >> N3->Text=A+B;
    > >> }

    >
    > >> In MS Visual C++ 2005 Express Edition I miss the ToDouble function.
    > >> How can it be done here? Can anyone help ?

    >
    > >> Regards Knut

    >
    > > double A = Double::parse(Text);

    >
    > > Regards Ryszard

    >
    > Thanks!
    > Still I have a problem getting A+B back to N3->Text. Can you show me
    > this too?


    Might be a better way of doing this but this ought to work:

    N3->Text = Convert::ToString(A + B, 10);

    The 10 at the end means you want it in base 10, I hope this works for
    non-integers too. By the way, this is kind of off-topic here, in the
    future you should ask questions like these in a Microsoft/.Net-
    specific newsgroup, perhaps microsoft.public.dotnet.languages.vc will
    do.

    --
    Erik Wikström
    =?utf-8?B?RXJpayBXaWtzdHLDtm0=?=, Feb 20, 2007
    #5
  6. Erik Wikström wrote:
    > On Feb 20, 10:21 am, Knut Olsen-Solberg <> wrote:
    >> Ryszard wrote:
    >>> Knut Olsen-Solberg napisał(a):
    >>>> This is the program:
    >>>> The Form has 3 TextBoxes and 1 Button. The user uses the keyboard to
    >>>> enter a number in each of the two first TexBoxes, presses the Button,
    >>>> and the sum of the numbers appears in the third TextBox.
    >>>> In Borland Builder the OnClick event of the Button can look like this
    >>>> (if the TextBoxes are named N1, N2 and N3):
    >>>> void __fastcall TForm1::Button1Click(TObject *Sender)
    >>>> {
    >>>> double A = N1->Text.ToDouble();
    >>>> double B = N2->Text.ToDouble();
    >>>> N3->Text=A+B;
    >>>> }
    >>>> In MS Visual C++ 2005 Express Edition I miss the ToDouble function.
    >>>> How can it be done here? Can anyone help ?
    >>>> Regards Knut
    >>> double A = Double::parse(Text);
    >>> Regards Ryszard

    >> Thanks!
    >> Still I have a problem getting A+B back to N3->Text. Can you show me
    >> this too?

    >
    > Might be a better way of doing this but this ought to work:
    >
    > N3->Text = Convert::ToString(A + B, 10);
    >
    > The 10 at the end means you want it in base 10, I hope this works for
    > non-integers too. By the way, this is kind of off-topic here, in the
    > future you should ask questions like these in a Microsoft/.Net-
    > specific newsgroup, perhaps microsoft.public.dotnet.languages.vc will
    > do.
    >
    > --
    > Erik Wikström


    No, this did not work (maybe just a little correction needed?), but I
    found something that worked:
    T3->Text = (A+B).ToString();

    Thanks Knut
    Knut Olsen-Solberg, Feb 20, 2007
    #6
  7. Knut Olsen-Solberg

    Ryszard Guest

    Knut Olsen-Solberg napisa³(a):
    > Ryszard wrote:
    >> Knut Olsen-Solberg napisa³(a):
    >>> This is the program:
    >>> The Form has 3 TextBoxes and 1 Button. The user uses the keyboard to
    >>> enter a number in each of the two first TexBoxes, presses the Button,
    >>> and the sum of the numbers appears in the third TextBox.
    >>>
    >>> In Borland Builder the OnClick event of the Button can look like this
    >>> (if the TextBoxes are named N1, N2 and N3):
    >>>
    >>> void __fastcall TForm1::Button1Click(TObject *Sender)
    >>> {
    >>> double A = N1->Text.ToDouble();
    >>> double B = N2->Text.ToDouble();
    >>>
    >>> N3->Text=A+B;
    >>> }
    >>>
    >>> In MS Visual C++ 2005 Express Edition I miss the ToDouble function.
    >>> How can it be done here? Can anyone help ?
    >>>
    >>> Regards Knut

    >>
    >> double A = Double::parse(Text);
    >>
    >> Regards Ryszard

    >
    >
    > Thanks!
    > Still I have a problem getting A+B back to N3->Text. Can you show me
    > this too?
    >
    > Regards Knut


    N3->Text = A.ToString();

    Regards Ryszard
    Ryszard, Feb 20, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    3
    Views:
    10,074
    VhdlCohen
    Sep 14, 2003
  2. Brent Burkart
    Replies:
    5
    Views:
    761
    Jerry III
    Oct 16, 2003
  3. Bob
    Replies:
    0
    Views:
    377
  4. Simon
    Replies:
    1
    Views:
    391
    Manish Pandit
    Nov 28, 2007
  5. Geoff Cox
    Replies:
    7
    Views:
    102
    Geoff Cox
    May 25, 2005
Loading...

Share This Page