Can someone help me with this code?

This is a discussion on Can someone help me with this code? within the C# Programming forums, part of the General Programming Boards category; Ok The following code: Code: //Language: C# //Author: RR //Date: 11-14-04 //Description: A calculator to add two usre inputs. //The ...

  1. #1
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309

    Can someone help me with this code?

    Ok The following code:
    Code:
    //Language: C#
    //Author: RR
    //Date: 11-14-04
    //Description: A calculator to add two usre inputs.
    
    
    //The system .NET files to use
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    //The class used for the application:
    Class App
    {
    	public static void Main()
    	{
    		Application.Run(new Calc());
    	}
    }
    
    //the class for the Calc() function
    class Calc:Form
    {
    	TextBox inputA;
    	TextBox inputB;
    	ListBox Answer;
    	Button Add;
    	
    	public Calc()
    	{
    		inputA = new TextBox();
    		inputA.Location=new Point(16,16);
    		inputB=new TextBox();
    		inputB.Location=new Point(28,16);
    		
    		Button Add=new Button();
    		Add.Location=new Point(16,48);
    		Add.Size=new Size(70,20);
    		Add.Text="Add!";
    		Add.Click += new EventHandler(OnClick);
    		AcceptButton=Add;
    		
    		Answer=new ListBox();
    		Answer.Location=new Point(16,88);
    		Answer.Size=new Size(190,130);
    		Answer.Anochor=AnchorStyles.Top|AnchorStlyes.Bottom|AnchorStyles.Left|AnchorStyles.Right;
    		
    		ClientSize=new Size(255,255);
    		Controls.AddRange(new Control[]
    		{
    			inputA,inputB,Add,Answer
    		});
    		Text="Calculator";
    	}
    	
    	void OnClick(Object sender, EventArgs e)
    	{
    		try{
    			Int32 A = Convert.ToInt32(inputA.Text);
    			Int32 B = Convert.ToInt32(inputB.Text);
    			
    			if(A>100||B>100)
    				throw new Exception();
    				
    			Answer.Items.Clear();
    			Decimal ABC=A+B;
    			Answer.Items.Add(ABC);
    			}
    			Answer.SelectedIndex = Answer.Items.Count-1;
    	}
    		catch
    		{
    			MessageBox.Show("Both inputs must be less than 101, not including 101");
    		}
    	}
    When I try to compile it using csc.exe I get the following error:

    Calc.cs(13,1): error CS0116: A namespace does not directly contain members such
    as fields or methods
    Calc.cs(15,16): error CS1518: Expected class, delegate, enum, interface, or
    struct
    Calc.cs(19,1): error CS1022: Type or namespace definition, or end-of-file
    expected


    I've tried checning the Class APP to Class App, and some other things, but I'm not quite sure WHAT the compiler is saying is wrong with it. If anybody could help I would appreciate it very much.
    To code is divine

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I remember getting similar errors. In Visual Studio.NET you need to do more than just add the "using" statement in your code to get the libraries into your code (unlike C/C++ where you just "#include" it). Right click on "References" in your project under the solution explorer, and select, "Add References...". Add the necessary libraries, and if this is the same problem I was having, this should fix the problem.

  3. #3
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    I'm not using Visual Studio, I'm using notepad and the compiler that came with the .NET framework, unless I totally misunderstood what you are saying.
    To code is divine

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Well I believe VisualStudio.NET uses cs.exe too (IDE's are usually just specialized editors that have built-in abilities to use compilers - hence the Eclipse project), so it may be the same problem, but I don't know how to fix it at the command-line level.

  5. #5
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Ahh I finally got it to work! Thanks for the (future) help!
    To code is divine

  6. #6
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Code:
    //The class used for the application:
    Class App
    {
    	public static void Main()
    	{
    		Application.Run(new Calc());
    	}
    }
    The problem was "Class", which should be "class". C#, like C/C++, Java and even PHP, is case sensitive.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 09:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21