Data Type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Morris

    #1

    Data Type

    In VB6 I use this code:

    Public Island() as MapPoint
    Type MapPoint
    GridEast as Single
    GridNorth as Single
    End Type

    How do I do this in VB.NET?


  • Fergus Cooney

    #2
    Re: Data Type

    Hi Simon,

    I think you'll like Structures in VB.NET. They are much cleverer than
    those dumb VB6 Types.

    Regards,
    Fergus

    <code>
    Structure MapPoint
    Public GridEast As Single
    Public GridNorth As Single

    'Optional
    Public Sub New (ThisGridEast As Single, ThisGridNorth As Single)
    GridEast = ThisGridEast
    GridNorth = ThisGridNorth
    End Sub

    'Structures in VB.NET can be clever.
    Public Sub GoNorth (Amount As Single)
    GridNorth += Amount
    End Sub

    'Structures in VB.NET can be informative.
    Public Overrides Function ToString As String
    Return "(" & GridEast.ToStri ng & ", " & GridNorth.ToStr ing & ")"
    End Function
    End Structure

    Public Island() As MapPoint

    Public Sub TryMe
    Dim WhereTheTreasur eIs As New MapPoint (0, 100)
    Dim IAmHere As MapPoint 'Defaults to (0, 0)

    Dim S As String = vbCrLf
    S &= IAmHere.ToStrin g & vbCrLf
    IAmHere.GoNorth (100)
    S &= IAmHere.ToStrin g & vbCrLf

    S &= WhereTheTreasur eIs.ToString & vbCrLf
    S &= IAmHere.Equals (WhereTheTreasu reIs).ToString & vbCrLf
    S = S 'Breakpoint on me!
    End Sub
    </code>


    Comment

    • Justin Weinberg

      #3
      Re: Data Type

      Use a Structure:

      Structure MapPoint
      Public GridEast as Single
      Public GridNorth as Single
      End Structure

      By the way, there's a built in single based Point type
      (System.Drawing .PointF)

      --

      Justin Weinberg
      Designing a PrintDocument? Drawing to forms?
      Check out GDI+ Architect at www.mrgsoft.com


      "Simon Morris" <simon.morris@x tra.co.nz> wrote in message
      news:Ox1uBbboDH A.2188@TK2MSFTN GP11.phx.gbl...[color=blue]
      > In VB6 I use this code:
      >
      > Public Island() as MapPoint
      > Type MapPoint
      > GridEast as Single
      > GridNorth as Single
      > End Type
      >
      > How do I do this in VB.NET?
      >
      >[/color]


      Comment

      Working...