Hello, I been trying to convert my c# code into VBA but couldn't find any solution, I appreciate if anyone can help me in this regard. Here is my code:
using System.Drawing;
using System.Globalization;
public enum Direction
{
North = 0,
South = 4,
East = 6,
West = 2,
Northeast = 7,
Northwest = 1,
Southeast = 5,
Southwest = 3,
Undefined = -1
}
public class DirectionFinder
{
public static Direction GetDirection(string baseLat, string baseLng, string customerLat, string customerLng)
{
try
{
float baseLatp = float.Parse(baseLat.ToString(), CultureInfo.InvariantCulture.NumberFormat);
float baseLngp = float.Parse(baseLng.ToString(), CultureInfo.InvariantCulture.NumberFormat);
float custLatp = float.Parse(customerLat.ToString(), CultureInfo.InvariantCulture.NumberFormat);
float custLngp = float.Parse(customerLng.ToString(), CultureInfo.InvariantCulture.NumberFormat);
var baseP = new PointF(baseLatp, baseLngp);
var custP = new PointF(custLatp, custLngp);
return GetDirection(baseP, custP);
}
catch
{
throw;
}
}
private static Direction GetDirection(PointF p1, PointF p2)
{
double angle = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X);
angle += Math.PI;
angle /= Math.PI / 4;
int halfQuarter = Convert.ToInt32(angle);
halfQuarter %= 8;
return (Direction)halfQuarter;
}
}
Bookmarks