point.vb

来自「wrox出版社的另一套经典的VB2005数据库编程学习书籍,收集了书中源码,郑重」· VB 代码 · 共 87 行

VB
87
字号
Imports System
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server

'Added
Imports System.Math

<Serializable(), SqlUserDefinedType(Format.Native)> _
Public Structure Point
	Implements INullable

	Private blnIsNull As Boolean
	'Coordinates
	Private dblX As Double
	Private dblY As Double

	Public ReadOnly Property IsNull() As Boolean _
	  Implements INullable.IsNull
		'Required
		Get
			Return blnIsNull
		End Get
	End Property

	Public Shared ReadOnly Property Null() As Point
		'Required
		Get
			Dim ptNew As Point
			ptNew.blnIsNull = True
			Return ptNew
		End Get
	End Property

	Public Overrides Function ToString() As String
		'Return the comma-separated values
		If Me.IsNull Then
			Return "Null"
		Else
			Return Me.dblX.ToString + "," + Me.dblY.ToString
		End If
	End Function

	Public Shared Function Parse(ByVal sqlString As SqlString) As Point
		'Creates a Point by splitting an input string at the separator character
		If sqlString.IsNull Then
			Return Nothing
		Else
			Dim ptNew As Point
			Dim strNew As String = sqlString.ToString
			Dim astrXY() As String = strNew.Split(","c)
			ptNew.X = CType(astrXY(0), Double)
			ptNew.Y = CType(astrXY(1), Double)
			Return ptNew
		End If
	End Function

	Public Property X() As Double
        'X-coordinate
		Get
			Return Me.dblX
		End Get
		Set(ByVal Value As Double)
			Me.dblX = Value
			blnIsNull = False
		End Set
	End Property

	Public Property Y() As Double
		'Y-coordinate
		Get
			Return Me.dblY
		End Get
		Set(ByVal Value As Double)
			Me.dblY = Value
			blnIsNull = False
		End Set
	End Property

	Public Function DistanceTo(ByVal ptTest As Point) As Double
		'Optional function: Calculate the distance from Me to ptTest
		Return Sqrt((Me.X - ptTest.X) * (Me.X - ptTest.X) + _
		  (Me.Y - ptTest.Y) * (Me.Y - ptTest.Y))
	End Function
End Structure

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?