RSPANGLER_AVTIA
asked on
C# class - every time I add one to my code I get a "CS1513: } expected" error
I have a project that I'm working on that basically requires me to use C# code like PHP or classic ASP as opposed to using visual studio - part of that project includes adding a class - whenever I add any classes, I get "CS1513: } expected"
Guessing this is just an order / syntax thing - any advice you can provide would be greatly appreciated!
Thanks!
Guessing this is just an order / syntax thing - any advice you can provide would be greatly appreciated!
Thanks!
<%@ Page Language="C#" debug="true" %>
<%@ Import Namespace="System" %>
<%
class PointTest
{
public int x;
public int y;
}
class MainClass4
{
static void Main()
{
PointTest p = new PointTest();
// Direct access to public members:
p.x = 10;
p.y = 15;
Response.Write("x = {0}, y = {1}", p.x, p.y);
}
}
// Output: x = 10, y = 15
// additional C# code here to do stuff
%>
ASKER
Thanks Ryan,
Really appreciate it! I think I'm getting closer on this with the .cs page, but I'm confused as to how to structure the page to call the code appropriately.
Here's the actual code I'm calling in my .cs page now:
and here's what I have on the top of my main page (mainpage.aspx) that calls the .cs page (mainpage.aspx.cs)
Right now it seems close, but I'm getting the following error:
Parser Error Message: 'calcdistance.GeoCodeCalcM easurement ' is not allowed here because it does not extend class 'System.Web.UI.Page'.
Thanks so much!!
Really appreciate it! I think I'm getting closer on this with the .cs page, but I'm confused as to how to structure the page to call the code appropriately.
Here's the actual code I'm calling in my .cs page now:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace calcdistance {
public static class GeoCodeCalc
{
public const double EarthRadiusInMiles = 3956.0;
public const double EarthRadiusInKilometers = 6367.0;
public static double ToRadian(double val) { return val * (Math.PI / 180); }
public static double DiffRadian(double val1, double val2) { return ToRadian(val2) - ToRadian(val1); }
public static double CalcDistance(double lat1, double lng1, double lat2, double lng2)
{
return CalcDistance(lat1, lng1, lat2, lng2, GeoCodeCalcMeasurement.Miles);
}
public static double CalcDistance(double lat1, double lng1, double lat2, double lng2, GeoCodeCalcMeasurement m)
{
double radius = GeoCodeCalc.EarthRadiusInMiles;
if (m == GeoCodeCalcMeasurement.Kilometers) { radius = GeoCodeCalc.EarthRadiusInKilometers; }
return radius * 2 * Math.Asin( Math.Min(1, Math.Sqrt( ( Math.Pow(Math.Sin((DiffRadian(lat1, lat2)) / 2.0), 2.0) + Math.Cos(ToRadian(lat1)) * Math.Cos(ToRadian(lat2)) * Math.Pow(Math.Sin((DiffRadian(lng1, lng2)) / 2.0), 2.0) ) ) ) );
}
}
public enum GeoCodeCalcMeasurement : int
{
Miles = 0,
Kilometers = 1
}
}
and here's what I have on the top of my main page (mainpage.aspx) that calls the .cs page (mainpage.aspx.cs)
<%@ Page Language="C#" debug="true" src="mainpage.aspx.cs" Inherits="calcdistance.GeoCodeCalcMeasurement" AutoEventWireup="true"%>
Right now it seems close, but I'm getting the following error:
Parser Error Message: 'calcdistance.GeoCodeCalcM
Thanks so much!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Ryan,
I'm still playing with a few variations (getting an error) - will report back today. Really appreciate your assistance!!
Cheers!
I'm still playing with a few variations (getting an error) - will report back today. Really appreciate your assistance!!
Cheers!
ok coool, let us know if you need further assistance cheers
frontend:
Open in new window
code behind:Open in new window