+ Reply to Thread
Results 1 to 2 of 2

convert c# code into VBA

  1. #1
    Registered User
    Join Date
    04-29-2019
    Location
    hyderabad, india
    MS-Off Ver
    2007
    Posts
    2

    convert c# code into VBA

    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;
    }
    }

  2. #2
    Registered User
    Join Date
    04-29-2019
    Location
    hyderabad, india
    MS-Off Ver
    2007
    Posts
    2

    Re: convert c# code into VBA

    this is the VB.NET version, I convert it using --carlosag.net/tools/codetranslator

    Public Enum Direction

    North = 0

    South = 4

    East = 6

    West = 2

    Northeast = 7

    Northwest = 1

    Southeast = 5

    Southwest = 3

    Undefined = -1
    End Enum
    Public Class DirectionFinder

    Public Overloads Shared Function GetDirection(ByVal baseLat As String, ByVal baseLng As String, ByVal customerLat As String, ByVal customerLng As String) As Direction
    Try
    Dim baseLatp As Single = Single.Parse(baseLat.ToString, CultureInfo.InvariantCulture.NumberFormat)
    Dim baseLngp As Single = Single.Parse(baseLng.ToString, CultureInfo.InvariantCulture.NumberFormat)
    Dim custLatp As Single = Single.Parse(customerLat.ToString, CultureInfo.InvariantCulture.NumberFormat)
    Dim custLngp As Single = Single.Parse(customerLng.ToString, CultureInfo.InvariantCulture.NumberFormat)
    Dim baseP = New PointF(baseLatp, baseLngp)
    Dim custP = New PointF(custLatp, custLngp)
    Return DirectionFinder.GetDirection(baseP, custP)
    Catch As System.Exception
    Throw
    End Try

    End Function

    Private Overloads Shared Function GetDirection(ByVal p1 As PointF, ByVal p2 As PointF) As Direction
    Dim angle As Double = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X))
    angle = (angle + Math.PI)
    (Math.PI / 4)
    Dim halfQuarter As Integer = Convert.ToInt32(angle)
    8
    Return CType(halfQuarter,Direction)
    End Function
    End Class
    Last edited by mfaizan24; 04-29-2019 at 11:53 AM. Reason: added VB.NET

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Convert InternetExplorer Code to XML Code
    By richardking in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-08-2019, 12:04 AM
  2. [SOLVED] Simple VBA code to convert text to number (simplify/fix current code)
    By kenenthpaul0401 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-26-2018, 10:47 AM
  3. Convert Excel Code to Access Code
    By Ruseju in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2016, 02:36 AM
  4. VBA code to convert all data + formatting of entire sheet to VBA code
    By jocanon in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-14-2016, 06:56 PM
  5. [SOLVED] Is it possible to convert C++ code into VBA
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 06-06-2014, 10:32 PM
  6. Convert Cell Formula to Convert Text to VBA Code
    By PY_ in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-08-2014, 05:51 PM
  7. How can i convert this to vba code
    By siobeh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-04-2014, 09:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1