Hey guys, I'm having trouble with an error message in my code, would you mind taking a look and helping me out?

private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text == "user" && passwordBox1.Password == "password")
            {
                Window2 W2;
                {
                    W2 = new Window2();
                    W2->Show;
                }
                Close();
            }
        }

The error is: The * or -> operator must be applied to a pointer
and: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
(The error occurs on the "W2->Show;" line)

I really appriciate your time!!
Thanks,
TSims11

Edited 5 Years Ago by TSims11: Added info

managed c++ does not use new -- it uses gcnew. And you have to make W2 a pointer. The braces are unnecessary.

Window2^ W2;
               W2 = gcnew Window2;
               W2->Show;

Edited 5 Years Ago by Ancient Dragon: n/a

I'm sorry, I didn't know about it and I think it's weird. Why microsoft would want to change syntax so much?

managed c++ does not use new -- it uses gcnew. And you have to make W2 a pointer. The braces are unnecessary.

Window2^ W2;
               W2 = gcnew Window2;
               W2->Show;

On the second Window2, it throws an error saying "; expected"...

Edited 5 Years Ago by TSims11: n/a

That doesn't work either... It throws 5 more errors when I add the "()" to W2->Show;
I'm sorry I feel like a bit of a pest.

What are the errors? Copy and paste them instead of paraphrasing, please. Also, how is Window2 defined?

This is all of the code related to this action:

private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text == "user" && passwordBox1.Password == "password")
            {
                Window2 W2;
                W2 = gcnew Window2;
                W2->Show;
                Close();
            }
        }

(This includes the changes that AD suggested besdes adding () to the end of W2->Show;)
This is just a simple password prompt that is supposed to open the main body of the program when the correct user name (user) and password (password) are used. I'm not even sure if this is really the correct way to make a password prompt, but this is what I came up with.
Thanks again guys,
TSims11
PS: I'm an ameture programmer. I'm not in college. I'm a high school seinor. I was just asking for help, not for you guys to do it for me.

Edited 5 Years Ago by TSims11: n/a

You did not make the changes I suggested. You forgot to add the ^ in the declaration of W2. Window2^ W2; Just like c++ and C W2 has to be a pointer. Pointers in CLI are designated with ^ instead of *.

Amazing. You failed to provide both pieces of information I requested.

Edited 5 Years Ago by Narue: n/a

>>PS: I'm an ameture programmer. I'm not in college. I'm a high school seinor. I was just asking for help, not for you guys to do it for me.

If you want to learn to program then you have to learn to read, comprehend, and follow instructions. Both Narue and I have offered to help you but you have so far failed to provide the information we need to do so.

I'm sorry. I was in a rush this morning... You guys don't have to help me... But based on my searches through the web daniweb seemed to be the best for help. I'm trying to learn... I started maybe a month ago.

If this helps at all I'm using Visual C++ in Visual Studio 2010. This is a WPF form. I made the changes you listed on the pervious page Ancient Dragon, and the following errors pop up.

Chores.Window2' is a 'type' but is used like a 'variable'
'Chores.Window2' is a 'type' but is used like a 'variable'
; expected
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
The name 'gcnew' does not exist in the current context
The name 'W2' does not exist in the current context
The name 'W2' does not exist in the current context
The name 'W2' does not exist in the current context

The last three refer to lines 5, 6, and 7.
Narue, I'm not sure what you mean by "how is Window2 defined."
I really appriciate your help and patience on this.
I'm sorry I forgot to list the info you two asked for.

If it helps, here is my new code.

private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text == "user" && passwordBox1.Password == "password")
            {
                Window2^ W2;
                W2 = gcnew Window2;
                W2->Show();
                Close();
            }
        }

Did you add #include "Window2.h" at the top of that file? I just compiled the code you posted and did not get any erors or warnings, and it ran just as I expected it to run.

Comments
He pointed out something I was too dumb to figure out.

Ancient Dragon, you are my hero. I haven't included that into my program. However, when I put what you typed above (with an added ";" to it) above all of the using statements, several errors pop up. Is this the correct spot to put a file header? If I recall correctly in Visual Studio 2008 you could place it here. Thank you so much for your infinite patience.
My errors and complete code are listed bellow.

#include "Window2.h";
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Chores
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text == "user" && passwordBox1.Password == "password")
            {
                Window2^ W2;
                W2 = gcnew Window2;
                W2->Show();
                Close();
            }
        }
    }
}

Errors:
Preprocessor directive expected
Single-line comment or end-of-line expected

Thanks again,
TSims11

Edited 5 Years Ago by TSims11: n/a

That worked perfectly. Thank you so much!! You are a life (and grey hair) savior!!!

This question has already been answered. Start a new discussion instead.