Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Using a Class in a C# console application [modified]

Using a Class in a C# console application [modified]

Scheduled Pinned Locked Moved C#
csharptutorialcssdata-structures
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    B Don Davis
    wrote on last edited by
    #1

    Thanks, but I finally figured it out.
    I am fairly new to VB.net but I am getting by. I am almost clueless about C# though. I have managed to find a C# function that does what I need
    and have converted it with the online code converter. It runs in VB and works but two of the four calculations are not working. (I had hoped to get it
    working in C# to test the formulas.) It takes a string (a mapping Tile Quadkey, 02311102221333130 for example) and calculates the bounding box for that
    map tile(Lat/Lon) corner positions coordinates of the four corners). The calculated values W (West Longitude) N (North Latitude) E (East Longitude) and
    S (South Latitude). I have set up a new C# project, a console app. I have used the code at bottom and created a new class in that program. On the form Program.cs
    I don't have a clue about how to make use of that class. The test value would be Quadkey = "02311102221333130"
    It appears that it returns a string of the array bounds, values separated by commas.
    If someone wanted to convert this to working VB.net that would really great, but I hardly expect that.

    The corrected, working calling procedure. I guess that I knew even less than I thought.

    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    // Instance of OutputClass
    WMSHandler outCl = new WMSHandler();
    double N = 0;
    // Call Output class' method
    string MyString = outCl.QuadKeyToBBox("02311102221333130");
    Console.WriteLine(MyString);
    Console.ReadLine();
    }
    }
    }

    But that is not working. Any help would be appreciated.

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    // to do
    }
    }
    }

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace ConsoleApplication1
    {
    using System;
    using System.Math;
    using System.IO; // MemoryStream

    public class WMSHandler
    {
        // Bing Maps tiles are always 256px x 256px
        public const int TILE\_HEIGHT = 256, TILE\_WIDTH = 256;
        // Returns the bounding box coordinates for a given tile quadkey
        public string QuadKeyToBBox(string quadKey)
        {
            int zoom = quadKey.Length;
            int x = 0, y = 0;
            // Work out
    
    P realJSOPR 2 Replies Last reply
    0
    • B B Don Davis

      Thanks, but I finally figured it out.
      I am fairly new to VB.net but I am getting by. I am almost clueless about C# though. I have managed to find a C# function that does what I need
      and have converted it with the online code converter. It runs in VB and works but two of the four calculations are not working. (I had hoped to get it
      working in C# to test the formulas.) It takes a string (a mapping Tile Quadkey, 02311102221333130 for example) and calculates the bounding box for that
      map tile(Lat/Lon) corner positions coordinates of the four corners). The calculated values W (West Longitude) N (North Latitude) E (East Longitude) and
      S (South Latitude). I have set up a new C# project, a console app. I have used the code at bottom and created a new class in that program. On the form Program.cs
      I don't have a clue about how to make use of that class. The test value would be Quadkey = "02311102221333130"
      It appears that it returns a string of the array bounds, values separated by commas.
      If someone wanted to convert this to working VB.net that would really great, but I hardly expect that.

      The corrected, working calling procedure. I guess that I knew even less than I thought.

      namespace ConsoleApplication1
      {
      class Program
      {
      static void Main(string[] args)
      {
      // Instance of OutputClass
      WMSHandler outCl = new WMSHandler();
      double N = 0;
      // Call Output class' method
      string MyString = outCl.QuadKeyToBBox("02311102221333130");
      Console.WriteLine(MyString);
      Console.ReadLine();
      }
      }
      }

      But that is not working. Any help would be appreciated.

      using System;
      using System.Collections.Generic;
      using System.Text;

      namespace ConsoleApplication1
      {
      class Program
      {
      static void Main(string[] args)
      {
      // to do
      }
      }
      }

      using System;
      using System.Collections.Generic;
      using System.Text;

      namespace ConsoleApplication1
      {
      using System;
      using System.Math;
      using System.IO; // MemoryStream

      public class WMSHandler
      {
          // Bing Maps tiles are always 256px x 256px
          public const int TILE\_HEIGHT = 256, TILE\_WIDTH = 256;
          // Returns the bounding box coordinates for a given tile quadkey
          public string QuadKeyToBBox(string quadKey)
          {
              int zoom = quadKey.Length;
              int x = 0, y = 0;
              // Work out
      
      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Don't bother converting it. Leave it in VB.NET as a class library, and add that as a reference to any application that needs it. The whole point of .NET is supposed to be language neutrality.

      I'm not a stalker, I just know things. Oh by the way, you're out of milk.

      Forgive your enemies - it messes with their heads

      My blog | My articles | MoXAML PowerToys | Onyx

      M 1 Reply Last reply
      0
      • P Pete OHanlon

        Don't bother converting it. Leave it in VB.NET as a class library, and add that as a reference to any application that needs it. The whole point of .NET is supposed to be language neutrality.

        I'm not a stalker, I just know things. Oh by the way, you're out of milk.

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Onyx

        M Offline
        M Offline
        Michael9000
        wrote on last edited by
        #3

        I Agree, but if you want to see how it can be done in c#, create a new WinfowdFormsApplication and take a look at it's Program.cs

        P 1 Reply Last reply
        0
        • M Michael9000

          I Agree, but if you want to see how it can be done in c#, create a new WinfowdFormsApplication and take a look at it's Program.cs

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Why would I want to do this? The OP doesn't get replies to posts sent to me, so you might want to address it to him instead.

          I'm not a stalker, I just know things. Oh by the way, you're out of milk.

          Forgive your enemies - it messes with their heads

          My blog | My articles | MoXAML PowerToys | Onyx

          M 1 Reply Last reply
          0
          • P Pete OHanlon

            Why would I want to do this? The OP doesn't get replies to posts sent to me, so you might want to address it to him instead.

            I'm not a stalker, I just know things. Oh by the way, you're out of milk.

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Onyx

            M Offline
            M Offline
            Michael9000
            wrote on last edited by
            #5

            Pete O'Hanlon wrote:

            The OP doesn't get replies to posts sent to me, so you might want to address it to him instead.

            Ooops, didn't know that, 'cause That's the most common way in other forums

            1 Reply Last reply
            0
            • B B Don Davis

              Thanks, but I finally figured it out.
              I am fairly new to VB.net but I am getting by. I am almost clueless about C# though. I have managed to find a C# function that does what I need
              and have converted it with the online code converter. It runs in VB and works but two of the four calculations are not working. (I had hoped to get it
              working in C# to test the formulas.) It takes a string (a mapping Tile Quadkey, 02311102221333130 for example) and calculates the bounding box for that
              map tile(Lat/Lon) corner positions coordinates of the four corners). The calculated values W (West Longitude) N (North Latitude) E (East Longitude) and
              S (South Latitude). I have set up a new C# project, a console app. I have used the code at bottom and created a new class in that program. On the form Program.cs
              I don't have a clue about how to make use of that class. The test value would be Quadkey = "02311102221333130"
              It appears that it returns a string of the array bounds, values separated by commas.
              If someone wanted to convert this to working VB.net that would really great, but I hardly expect that.

              The corrected, working calling procedure. I guess that I knew even less than I thought.

              namespace ConsoleApplication1
              {
              class Program
              {
              static void Main(string[] args)
              {
              // Instance of OutputClass
              WMSHandler outCl = new WMSHandler();
              double N = 0;
              // Call Output class' method
              string MyString = outCl.QuadKeyToBBox("02311102221333130");
              Console.WriteLine(MyString);
              Console.ReadLine();
              }
              }
              }

              But that is not working. Any help would be appreciated.

              using System;
              using System.Collections.Generic;
              using System.Text;

              namespace ConsoleApplication1
              {
              class Program
              {
              static void Main(string[] args)
              {
              // to do
              }
              }
              }

              using System;
              using System.Collections.Generic;
              using System.Text;

              namespace ConsoleApplication1
              {
              using System;
              using System.Math;
              using System.IO; // MemoryStream

              public class WMSHandler
              {
                  // Bing Maps tiles are always 256px x 256px
                  public const int TILE\_HEIGHT = 256, TILE\_WIDTH = 256;
                  // Returns the bounding box coordinates for a given tile quadkey
                  public string QuadKeyToBBox(string quadKey)
                  {
                      int zoom = quadKey.Length;
                      int x = 0, y = 0;
                      // Work out
              
              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #6

              When I ran it through the converter found here: http://www.developerfusion.com/tools/convert/csharp-to-vb/[^] I got this:

              Public Function QuadKeyToBBox(quadKey As String) As String
              Dim TILE_HEIGHT As Integer = 256
              Dim TILE_WIDTH As Integer = 256
              Dim zoom As Integer = quadKey.Length
              Dim x As Integer = 0
              Dim y As Integer = 0

              For i As Integer = zoom To 1 Step -1
                  Dim mask As Integer = 1 << (i - 1)
                  Select Case quadKey(zoom - i)
                      Case "0"C
                          Exit Select
                      Case "1"C
                          x = x Or mask
                          Exit Select
                      Case "2"C
                          y = y Or mask
                          Exit Select
                      Case "3"C
                          x = x Or mask
                          y = y Or mask
                          Exit Select
                      Case Else
                          Throw New ArgumentException("Invalid QuadKey digit sequence.")
                  End Select
              Next
              
              Dim W As Double = CSng(x \* TILE\_WIDTH) \* 360 / CSng(TILE\_WIDTH \* Math.Pow(2, zoom)) - 180
              Dim N As Double = CSng(Math.Asin((Math.Exp((0.5 - ((y \* TILE\_HEIGHT) / (TILE\_HEIGHT)) / Math.Pow(2, zoom)) \* 4 \* Math.PI) - 1) / (Math.Exp((0.5 - ((y \* TILE\_HEIGHT) / 256) / Math.Pow(2, zoom)) \* 4 \* Math.PI) + 1))) \* 180 / CSng(Math.PI)
              Dim E As Double = CSng((x + 1) \* TILE\_WIDTH) \* 360 / CSng(TILE\_WIDTH \* Math.Pow(2, zoom)) - 180
              Dim S\_\_1 As Double = CSng(Math.Asin((Math.Exp((0.5 - (((y + 1) \* TILE\_HEIGHT) / (TILE\_HEIGHT)) / Math.Pow(2, zoom)) \* 4 \* Math.PI) - 1) / (Math.Exp((0.5 - (((y + 1) \* TILE\_HEIGHT) / 256) / Math.Pow(2, zoom)) \* 4 \* Math.PI) + 1))) \* 180 / CSng(Math.PI)
              Dim bounds As Double() = New Double() {W, S\_\_1, E, N}
              
              Return String.Join(",", Array.ConvertAll(bounds, Function(s\_\_2) s\_\_2.ToString()))
              

              End Function

              I have no idea how this is going to work because I just converted it and pasted it here (with some corrections where the converter incorrectly inserted backslashes in the converted code).

              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
              -----
              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
              -----
              "Why do

              B 1 Reply Last reply
              0
              • realJSOPR realJSOP

                When I ran it through the converter found here: http://www.developerfusion.com/tools/convert/csharp-to-vb/[^] I got this:

                Public Function QuadKeyToBBox(quadKey As String) As String
                Dim TILE_HEIGHT As Integer = 256
                Dim TILE_WIDTH As Integer = 256
                Dim zoom As Integer = quadKey.Length
                Dim x As Integer = 0
                Dim y As Integer = 0

                For i As Integer = zoom To 1 Step -1
                    Dim mask As Integer = 1 << (i - 1)
                    Select Case quadKey(zoom - i)
                        Case "0"C
                            Exit Select
                        Case "1"C
                            x = x Or mask
                            Exit Select
                        Case "2"C
                            y = y Or mask
                            Exit Select
                        Case "3"C
                            x = x Or mask
                            y = y Or mask
                            Exit Select
                        Case Else
                            Throw New ArgumentException("Invalid QuadKey digit sequence.")
                    End Select
                Next
                
                Dim W As Double = CSng(x \* TILE\_WIDTH) \* 360 / CSng(TILE\_WIDTH \* Math.Pow(2, zoom)) - 180
                Dim N As Double = CSng(Math.Asin((Math.Exp((0.5 - ((y \* TILE\_HEIGHT) / (TILE\_HEIGHT)) / Math.Pow(2, zoom)) \* 4 \* Math.PI) - 1) / (Math.Exp((0.5 - ((y \* TILE\_HEIGHT) / 256) / Math.Pow(2, zoom)) \* 4 \* Math.PI) + 1))) \* 180 / CSng(Math.PI)
                Dim E As Double = CSng((x + 1) \* TILE\_WIDTH) \* 360 / CSng(TILE\_WIDTH \* Math.Pow(2, zoom)) - 180
                Dim S\_\_1 As Double = CSng(Math.Asin((Math.Exp((0.5 - (((y + 1) \* TILE\_HEIGHT) / (TILE\_HEIGHT)) / Math.Pow(2, zoom)) \* 4 \* Math.PI) - 1) / (Math.Exp((0.5 - (((y + 1) \* TILE\_HEIGHT) / 256) / Math.Pow(2, zoom)) \* 4 \* Math.PI) + 1))) \* 180 / CSng(Math.PI)
                Dim bounds As Double() = New Double() {W, S\_\_1, E, N}
                
                Return String.Join(",", Array.ConvertAll(bounds, Function(s\_\_2) s\_\_2.ToString()))
                

                End Function

                I have no idea how this is going to work because I just converted it and pasted it here (with some corrections where the converter incorrectly inserted backslashes in the converted code).

                ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                -----
                You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                -----
                "Why do

                B Offline
                B Offline
                B Don Davis
                wrote on last edited by
                #7

                Thanks, I just tried it again myself and got another error message"-- line 3 col 8: invalid TypeDecl" That is the converter that I was using yesterday. Anyway the conversion that you posted is something that I can work with. Thanks again.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups