7 Replies - 39168 Views - Last Post: 07 July 2011 - 09:20 PM

#1 Midien   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-July 11

Changing Forms in Visual C++?

Posted 07 July 2011 - 01:06 PM

Hello! I've come to this forum a couple times over the past few years via google, but hadn't had a good reason to post before now. Sadly, my college's C++ courses do not cover anything other than command line programming, so I'm working on messing around a bit with C++ in Visual Studio 2010 to see if I can figure it out for myself. The plan for my first project was to work on a D&D 3.5 character creation tool where you enter and select all the bits for your character, it lets your roll up stats and modifies them according to all the bits you choose, etc. I was going to go for adding as many useful aspects as I could to it and learn as I go, and then have it all output your character to a file.

I'm... stuck at a really basic part of the whole thing, though. I have a 'title' form set up that just says what it is and has a continue button, and then the second form is where the creator starts. However, I can't seem to get the code to switch forms to work properly.

I'm writing two versions of this, one in C++ and one in VB, and I got the VB version to work exactly how I wanted with the 'Form2.Show()' and 'Me.Hide()', but after a BOATLOAD of googling, this is what I ended up with for C++:

I have this added at the head of Form1.
#pragma once
#include <iostream>
#include <fstream>
#include <iomanip>
#include "Form2.h"
#include "resource.h"



I have this added at the head of Form2.
#pragma once
#include "Form1.h"
#include "resource.h"


I have this added for the button on Form1.
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
	{
		Form2 ^newform = gcnew Form2();
		newform->Show();
		Form1::Hide();
	 }


The errors I receive are:
Error	1	error C2065: 'Form2' : undeclared identifier	c:\users\midien\documents\visual studio 2010\projects\practice\practice\Form1.h	100	1	Practice
Error	2	error C2065: 'newform' : undeclared identifier	c:\users\midien\documents\visual studio 2010\projects\practice\practice\Form1.h	100	1	Practice
Error	3	error C2061: syntax error : identifier 'Form2'	c:\users\midien\documents\visual studio 2010\projects\practice\practice\Form1.h	100	1	Practice
Error	4	error C2065: 'newform' : undeclared identifier	c:\users\midien\documents\visual studio 2010\projects\practice\practice\Form1.h	101	1	Practice
Error	5	error C2227: left of '->Show' must point to class/struct/union/generic type	c:\users\midien\documents\visual studio 2010\projects\practice\practice\Form1.h	101	1	Practice



This is a bare-bones version of the program with nothing else really on the forms, since I wanted to make sure I wasn't doing something else that screwed up this bit of code. I did ask my professor for advice on this, but his response was, "Huh, I have no idea. I may have to look that up eventually." So.... yeah, a bit less than helpful.

Another concern I had was whether or not variables would be useful between forms? Like if I wanted to declare a character's stats, class, race, etc. for use in the Feats and Skills forms, is there a specific place on a specific form where I need to declare them? If I'm thinking correctly, were this a command line program, I'd just declare them globally. How does that work if you have multiple forms?

My REALLY newbie questions: What is 'resource.h' anyway? And what's with the '.h'? I'd never seen a '.h' when using the Bloodshed Dev C++ software or in anything my classes went over, but I see it loads in Visual Studio code bits I find online. Is any of that really necessary for what I'm trying to do? Why?

I'm still a C++ (and programming in general) newbie, so any advice would be a huge help. This isn't a homework assignment, but just out of trying to teach myself more than my college offers while I'm taking my classes.

Is This A Good Question/Topic? 0
  • +

Replies To: Changing Forms in Visual C++?

#2 Oler1s   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1397
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Changing Forms in Visual C++?

Posted 07 July 2011 - 01:34 PM

> I'm still a C++ (and programming in general) newbie

Which is why I'm concerned at your attempts here. Also, did you really intend to use C++/CLI?

The .h thing is a naming convention for headers. You shouldn't be writing GUIs and what not if you aren't aware of the basics in C++. Your reliance on globals means you've never written a program of any actual complexity. Please go back to console programs with C++, and work on the basics, and write programs of > 1000 LOC.
Was This Post Helpful? -1
  • +
  • -

#3 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Changing Forms in Visual C++?

Posted 07 July 2011 - 01:44 PM

Moved to CLI C++
Was This Post Helpful? 0
  • +
  • -

#4 Midien   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-July 11

Re: Changing Forms in Visual C++?

Posted 07 July 2011 - 02:08 PM

Wow... I... posted here under the impression that this place might be helpful. I guess I was misinformed. I'm not intending to use CLI, so I don't know why this post was moved there. I've done so much of that at this point for two years that I want to try something new. I call myself a newbie because apparently I'm not nearly as awesome as all you guys yet, but that doesn't mean I'm entirely incompetent.

The problem I'm having is that my college doesn't teach anything more complex than what I'm already doing, and I'm left to teach myself the rest. It's not a reliance on globals. I know about using variables outside of that, but as it's been taught to us here at least, if you want to use a variable in more than one place, you either re-declare it or make it global. I made the comment out of speculation on how to make variables pass between forms. If that's not something that's necessary, then it would have been more helpful for someone to just say that. If something I'm doing is wrong, by all means tell me something useful so that I learn. D: But please don't just tell me to 'go back and learn more CLI.'

I'm not sure why it would 'concern' anyone that I'd try this. Worst thing that would happen is it doesn't work, or it takes me a long time to learn the bits necessary. It's not as though I'm publishing this, selling it, or going to lose an arm or leg in the process.

Seriously, about the forms and the changing between them... anything useful that might help in Visual Studio?
Was This Post Helpful? 0
  • +
  • -

#5 Midien   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-July 11

Re: Changing Forms in Visual C++?

Posted 07 July 2011 - 02:26 PM

Bleh, it ate my post. I think I misunderstood what you guys meant by 'CLI'. >.< Common Language Infrastructure is a new one on me. It was even on an exam here that the 'CLI' in CLI C++ was 'Command Line Interface'.

Yeah, that's the kind of classes I'm working with. x.x Yay.

Anyway, sorry for the misinterpretation on my part, but... I still don't want to go back and do yet more command line programming.
Was This Post Helpful? 0
  • +
  • -

#6 Oler1s   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1397
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Changing Forms in Visual C++?

Posted 07 July 2011 - 07:25 PM

A number of red flags in your post lead me to believe you are absolutely not ready for the kind of program you are writing:

- You don't recognize the language you are using. You are using the language C++/CLI, as opposed to C++. It's a bad sign when you don't know this.

- You don't know how to handle errors. Errors are a regular part of development. In particular, the ones you are looking at are very basic. That you can't handle them means you had too little experience writing code (in any language, not just C++).

- You have no sense of code architecture. "if I wanted to declare a character's stats, class, race, etc. for use in the Feats and Skills forms, is there a specific place on a specific form where I need to declare them" A specific place on the form? What does that mean? Even more troubling, the notion of character stats has nothing to do with a form. Why would you integrate the two??

You aren't separating out the behaviors and logic in your design. You don't seem to have a sense of data flow. It means you have insufficient experience programming.

- You ask about header files. It means you've never written a program of complexity. People start learning about header files when they start writing code in multiple files. Given that you are unaware of this, it means you've never gone past the basics.

And you are using a GUI toolkit. For beginners, the first time they use a GUI toolkit is when they confront a completely different model or multiple models of programming (event driven, perhaps asynchronous). So you can't do the basics, and you are tackling something that challenges people who have mastered the basics?

So the problem isn't something specific. It's that you're missing too much experience. So you're just mimicking or blindly following other people's code as opposed to creating a sensible design yourself. There's nothing I can say in this situation except to tell you to go back to basics.

Quote

if you want to use a variable in more than one place, you either re-declare it or make it global.
Have you not learned to pass variables to functions?

Please, pick up a book like Accelerated C++ by Koenig or C++ Primer by Lippman, and work through the basics.
Was This Post Helpful? 0
  • +
  • -

#7 Midien   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-July 11

Re: Changing Forms in Visual C++?

Posted 07 July 2011 - 07:55 PM

*sigh*

Sure, I'll check out the books. That suggestion would have sufficed in the first place. However, I think in a couple places there's more miscommunication than anything, especially the part where you say:

Quote

the notion of character stats has nothing to do with a form. Why would you integrate the two??


I'm not going to get into asking it again, because I've been reading up on an alternative in the meantime, and am just going to do something else entirely and use a single form. *Shrug* I've already got it mostly working.

While I get that you're pointing out that I don't have a ton of experience and could use practice, it's exceptionally unfair to make generalizations. I've already written this thing in VB, and it works well. The point was to try to do the same thing in a different language. Unfortunately, it's the one that only grad students who don't know what they're talking about teach at my college, so I'm pretty much teaching myself at this point.

Quote

You aren't separating out the behaviors and logic in your design. You don't seem to have a sense of data flow. It means you have insufficient experience programming.


How the 10 tiny codebits I put in there to start the project show that I have no sense of data flow when there's no data IN the program yet?... Well, you've lost me there.

I know what a header file IS. I had just never seen one with a '.h' until I hit Visual Studio. If it's so elementary, it likely wouldn't be morbidly painful to explain why it's there, or... again... just say 'hey, this is a good book and explains all that.' And yes, there are plainly more header bits than 'necessary' for this tiny piece of code I was trying to work with, but those are obviously there in prep for things I intended to add later.

Anyway, I've learned my lesson about bothering with forums, and while I'll check out the books to fill in the pieces left out by atrocious instruction, I likely won't bother coming back here. I do not usually have an actual person to ask the questions of why things work the way they do and why they're set up the way they are (even if other people think they're stupid questions), and while you can't ask a book a question if it confuses you, at least it won't insult you. So to ask for help or explanations, and then be told you're just a blind follower for wanting to know how and why something works? Yep, not what I needed. Thanks, though, and happy coding.
Was This Post Helpful? 0
  • +
  • -

#8 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1853
  • View blog
  • Posts: 6,671
  • Joined: 19-February 09

Re: Changing Forms in Visual C++?

Posted 07 July 2011 - 09:20 PM

You have :
Form2 ^newform = gcnew Form2();



and are getting Form2 and newform undeclared identifier errors.


You might want something like :

Form^ newform = gcnew Form();


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1