Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
namespace Addedfunction
        {
        if (Strt_Address != null)
        {
            sLong1 = geocodeXmlDoc1.DocumentElement.SelectSingleNode(@"//geometry/location/lat", XmlMngr1).InnerText;
            sLat1 = geocodeXmlDoc1.DocumentElement.SelectSingleNode(@"//geometry/location/lng", XmlMngr1).InnerText;

            sLong2 = geocodeXmlDoc2.DocumentElement.SelectSingleNode(@"//geometry/location/lat", XmlMngr2).InnerText;
            sLat2 = geocodeXmlDoc2.DocumentElement.SelectSingleNode(@"//geometry/location/lng", XmlMngr2).InnerText;

            Label1.Text = sLong1 + ", " + sLat1;
            Label2.Text = sLong2 + ", " + sLat2;

            elong1 = Convert.ToDouble(sLong1);
            elat1 = Convert.ToDouble(sLat1);
            elong2 = Convert.ToDouble(sLong2);
            elat2 = Convert.ToDouble(sLat2);
        }
        else {
            Label1.Text = "Input Valid values";
        }

}
        double distLong = elong1 * (Math.PI / 180.0);
        double distlat = elat1 * (Math.PI / 180.0);
        double distLong1 = elong2 * (Math.PI / 180.0);
        double distlat1 = elat2 * (Math.PI / 180.0);


in my code i want to have a function called added function...
i used namespace to make this as a function

in my code i'm calling this elong1, elat1, elong2, elat2
so values to out side from this code...
so it gives me an error............
outside of the function elong and elat set not working
because it says not assigned values?

but it gives me an error.
so how i'm gonna do that.......
have any idea?
Posted
Updated 15-Jul-13 2:07am
v2
Comments
[no name] 15-Jul-13 8:08am    
namespace != function declaration. Declare your functions inside of classes.
nikhil-vartak 15-Jul-13 8:12am    
What you are trying to achieve is not clear. Please clarify.
promod madushan 15-Jul-13 8:19am    
thing is i have some values from out side out side
String Strt_Address = TextBox1.Text;
String End_Address = TextBox2.Text;

i gave a if condition to check if the textbox is null or not

if (Strt_Address != null)
{
sLong1 = geocodeXmlDoc1.DocumentElement.SelectSingleNode(@"//geometry/location/lat", XmlMngr1).InnerText;
sLat1 = geocodeXmlDoc1.DocumentElement.SelectSingleNode(@"//geometry/location/lng", XmlMngr1).InnerText;

sLong2 = geocodeXmlDoc2.DocumentElement.SelectSingleNode(@"//geometry/location/lat", XmlMngr2).InnerText;
sLat2 = geocodeXmlDoc2.DocumentElement.SelectSingleNode(@"//geometry/location/lng", XmlMngr2).InnerText;

Label1.Text = sLong1 + ", " + sLat1;
Label2.Text = sLong2 + ", " + sLat2;

elong1 = Convert.ToDouble(sLong1);
elat1 = Convert.ToDouble(sLat1);
elong2 = Convert.ToDouble(sLong2);
elat2 = Convert.ToDouble(sLat2);
}
else {
Label1.Text = "Input Valid values";
}

and i want to get all the elong1 elat1 elong2 elat2 values to out side

double distLong = elong1 * (Math.PI / 180.0);
double distlat = elat1 * (Math.PI / 180.0);
double distLong1 = elong2 * (Math.PI / 180.0);
double distlat1 = elat2 * (Math.PI / 180.0);

i declared this aftr my if condition
but this it sho0ws me error that elong1 elat1 elong2 elat2 values are null?


so how i'm do that.........

 
Share this answer
 
Try this way may be it works

C#
namespace Addedfunction
        {
        if (Strt_Address != null)
        {
            sLong1 = geocodeXmlDoc1.DocumentElement.SelectSingleNode(@"//geometry/location/lat", XmlMngr1).InnerText;
            sLat1 = geocodeXmlDoc1.DocumentElement.SelectSingleNode(@"//geometry/location/lng", XmlMngr1).InnerText;
 
            sLong2 = geocodeXmlDoc2.DocumentElement.SelectSingleNode(@"//geometry/location/lat", XmlMngr2).InnerText;
            sLat2 = geocodeXmlDoc2.DocumentElement.SelectSingleNode(@"//geometry/location/lng", XmlMngr2).InnerText;
 
            Label1.Text = sLong1 + ", " + sLat1;
            Label2.Text = sLong2 + ", " + sLat2;
 
            elong1 = Convert.ToDouble(sLong1);
            elat1 = Convert.ToDouble(sLat1);
            elong2 = Convert.ToDouble(sLong2);
            elat2 = Convert.ToDouble(sLat2);
        }
        else {
            Label1.Text = "Input Valid values";
        }
 

        double distLong = elong1 * (Math.PI / 180.0);
        double distlat = elat1 * (Math.PI / 180.0);
        double distLong1 = elong2 * (Math.PI / 180.0);
        double distlat1 = elat2 * (Math.PI / 180.0);
}



Other wise elong,elat1,elong2,elat2 need to be declare globally..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900