6 Replies - 771 Views - Last Post: 12 June 2012 - 07:35 AM Rate Topic: -----

#1 cammyj3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 12-June 12

Winform class to main program

Posted 12 June 2012 - 06:37 AM

How would I get the main program to recognize that I have an outside class that I need to refer to?

I have created a class "Hello"
and I need to refer to an instance of the class

private Hello hello1 = new hello();


But when I write this code out, it does not recognize "Hello" to begin with..

View Postcammyj3, on 12 June 2012 - 06:36 AM, said:

How would I get the main program to recognize that I have an outside class that I need to refer to?

I have created a class "Hello"
and I need to refer to an instance of the class

private Hello hello1 = new Hello();


But when I write this code out, it does not recognize "Hello" to begin with..


Is This A Good Question/Topic? 0
  • +

Replies To: Winform class to main program

#2 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 181
  • View blog
  • Posts: 777
  • Joined: 27-October 11

Re: Winform class to main program

Posted 12 June 2012 - 06:44 AM

Could you please be more specific about 'it does not recognize "Hello" to begin with..'?

Maybe:

Add a reference to the project containing the 'Hello' class to your current project.
Was This Post Helpful? 0
  • +
  • -

#3 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Winform class to main program

Posted 12 June 2012 - 06:44 AM

What does this mean?

Your code is technically wrong, as C# is case sensitive.

As such it should be:
private Hello hello1 = new Hello();


It would help if you provided errors that you get, is it possible that you're not referencing the correct namespace that your class is contained within?
Was This Post Helpful? 0
  • +
  • -

#4 cammyj3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 12-June 12

Re: Winform class to main program

Posted 12 June 2012 - 06:47 AM

View PostRudiVisser, on 12 June 2012 - 06:44 AM, said:

What does this mean?

Your code is technically wrong, as C# is case sensitive.

As such it should be:
private Hello hello1 = new Hello();


I edited the post to begin with adding a quote, the quote is corrected as I could not find the edit button on the whole thread I wrote itself.
Was This Post Helpful? 0
  • +
  • -

#5 cammyj3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 12-June 12

Re: Winform class to main program

Posted 12 June 2012 - 06:56 AM

View PostRexGrammer, on 12 June 2012 - 06:44 AM, said:

Could you please be more specific about 'it does not recognize "Hello" to begin with..'?

Maybe:

Add a reference to the project containing the 'Hello' class to your current project.


I do not know what you are looking for when you mean add a reference to my project, but I'll try explain it a bit more..

I have a Form (Form1) holding the main program
I have a Class (Hello) holding various methods

After creating attributes and methods in the Hello class, I went back into the Form1 class to see if the methods work and the way I know how to do this is by creating an instance of the class Hello and then referring to the method therein via the following code:

private Hello hello1 = new Hello();


But when I write the code, the "Hello" should turn blue, but it does not and it has a syntax error of:

The type or namespace could not be found etc.
Was This Post Helpful? 0
  • +
  • -

#6 cammyj3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 12-June 12

Re: Winform class to main program

Posted 12 June 2012 - 07:02 AM

Okay, I realised the problem. The namespace in the class Hello was different to the Main programs'.
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,647
  • Joined: 02-June 10

Re: Winform class to main program

Posted 12 June 2012 - 07:35 AM

I'm going to suggest you stop trying to figure out how C# works, and instead READ about how C# works and follow a book or some tutorials.

There are three routes people seem to take when learning programming.
  • Just start trying to create programs
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)


For the life of me I can't figure out why people try 1 & 2.
Sure, 35 years ago the only way I could learn BASIC as a kid was to type programs from a book into a TRS-80 model 1 or Commodore VIC-20, then figure out the commands and syntax by watching the results as the program ran. There simply wasn't any courses for a kid back then.

But now, you can't help but to trip over "Learn {coding language} in 3 weeks" type books and the entire internet is at your disposal for tutorials.

I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

Quote

Where do I start?


You start by learning a coding language FIRST.
Learn to plan before you type.
THEN you start designing software with a purpose.


If this sounds like you

Newbie/Rookie said:

I have a little programming experience but I need to write ...
read this section
Spoiler


Otherwise, you can just jump to the resources here:
Some of the tutorials below are for C# or Java not C, C++, VB.NET [...]. But the conceptual stuff of classes, object oriented design, events etc. are not language specific and should give you enough guidance in theory of program development for you to be able to look-up specific code example in your chosen coding language.



Resources, references and suggestions for new programmers. - Updated Mar 2012
Spoiler

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1