Data Type

  • Thread starter Thread starter Simon Morris
  • Start date Start date
S

Simon Morris

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?
 
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.ToString & ", " & GridNorth.ToString & ")"
End Function
End Structure

Public Island() As MapPoint

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

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

S &= WhereTheTreasureIs.ToString & vbCrLf
S &= IAmHere.Equals (WhereTheTreasureIs).ToString & vbCrLf
S = S 'Breakpoint on me!
End Sub
</code>
 
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)
 
Back
Top