Click here to Skip to main content
15,898,035 members
Articles / Programming Languages / Visual Basic

Writing Your Own GPS Applications: Part 2

Rate me:
Please Sign up or sign in to vote.
4.65/5 (826 votes)
7 Aug 2008CPOL12 min read 1.2M   6.7K   691  
In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.
Imports StormSource.Gps

Public Class NewWaypointForm
	Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

	Public Sub New()
		MyBase.New()

		'This call is required by the Windows Form Designer.
		InitializeComponent()

		'Add any initialization after the InitializeComponent() call

	End Sub

	'Form overrides dispose to clean up the component list.
	Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
		If disposing Then
			If Not (components Is Nothing) Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(disposing)
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	Friend WithEvents Label2 As System.Windows.Forms.Label
	Friend WithEvents btnCancelButton As System.Windows.Forms.Button
	Friend WithEvents WaypointNameLabel As System.Windows.Forms.Label
	Friend WithEvents WaypointName As System.Windows.Forms.TextBox
	Friend WithEvents SymbolLabel As System.Windows.Forms.Label
	Friend WithEvents TabControl As System.Windows.Forms.TabControl
	Friend WithEvents GeneralTab As System.Windows.Forms.TabPage
	Friend WithEvents Position As System.Windows.Forms.TextBox
	Friend WithEvents WaypointDisplayModeComboBox As System.Windows.Forms.ComboBox
	Friend WithEvents WaypointSymbolComboBox As System.Windows.Forms.ComboBox
	Friend WithEvents WaypointColorComboBox As System.Windows.Forms.ComboBox
	Friend WithEvents ColorLabel As System.Windows.Forms.Label
	Friend WithEvents DisplayModeLabel As System.Windows.Forms.Label
	Friend WithEvents Depth As System.Windows.Forms.TextBox
	Friend WithEvents DepthLabel As System.Windows.Forms.Label
	Friend WithEvents Altitude As System.Windows.Forms.TextBox
	Friend WithEvents AltitudeLabel As System.Windows.Forms.Label
	Friend WithEvents City As System.Windows.Forms.TextBox
	Friend WithEvents CityLabel As System.Windows.Forms.Label
	Friend WithEvents Address As System.Windows.Forms.TextBox
	Friend WithEvents AddressLabel As System.Windows.Forms.Label
	Friend WithEvents Country As System.Windows.Forms.TextBox
	Friend WithEvents CountryLabel As System.Windows.Forms.Label
	Friend WithEvents State As System.Windows.Forms.TextBox
	Friend WithEvents StateLabel As System.Windows.Forms.Label
	Friend WithEvents IntersectingRoad As System.Windows.Forms.TextBox
	Friend WithEvents IntersectingRoadLabel As System.Windows.Forms.Label
	Friend WithEvents FacilityLabel As System.Windows.Forms.Label
	Friend WithEvents Facility As System.Windows.Forms.TextBox
	Friend WithEvents SaveButton As System.Windows.Forms.Button
	Friend WithEvents DescriptionLabel As System.Windows.Forms.Label
	Friend WithEvents Description As System.Windows.Forms.TextBox
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(NewWaypointForm))
		Me.WaypointDisplayModeComboBox = New System.Windows.Forms.ComboBox
		Me.WaypointSymbolComboBox = New System.Windows.Forms.ComboBox
		Me.WaypointNameLabel = New System.Windows.Forms.Label
		Me.WaypointName = New System.Windows.Forms.TextBox
		Me.btnCancelButton = New System.Windows.Forms.Button
		Me.SaveButton = New System.Windows.Forms.Button
		Me.Position = New System.Windows.Forms.TextBox
		Me.Label2 = New System.Windows.Forms.Label
		Me.Description = New System.Windows.Forms.TextBox
		Me.DescriptionLabel = New System.Windows.Forms.Label
		Me.SymbolLabel = New System.Windows.Forms.Label
		Me.ColorLabel = New System.Windows.Forms.Label
		Me.WaypointColorComboBox = New System.Windows.Forms.ComboBox
		Me.DisplayModeLabel = New System.Windows.Forms.Label
		Me.Depth = New System.Windows.Forms.TextBox
		Me.DepthLabel = New System.Windows.Forms.Label
		Me.Altitude = New System.Windows.Forms.TextBox
		Me.AltitudeLabel = New System.Windows.Forms.Label
		Me.City = New System.Windows.Forms.TextBox
		Me.CityLabel = New System.Windows.Forms.Label
		Me.Address = New System.Windows.Forms.TextBox
		Me.AddressLabel = New System.Windows.Forms.Label
		Me.Country = New System.Windows.Forms.TextBox
		Me.CountryLabel = New System.Windows.Forms.Label
		Me.State = New System.Windows.Forms.TextBox
		Me.StateLabel = New System.Windows.Forms.Label
		Me.IntersectingRoad = New System.Windows.Forms.TextBox
		Me.IntersectingRoadLabel = New System.Windows.Forms.Label
		Me.TabControl = New System.Windows.Forms.TabControl
		Me.GeneralTab = New System.Windows.Forms.TabPage
		Me.FacilityLabel = New System.Windows.Forms.Label
		Me.Facility = New System.Windows.Forms.TextBox
		Me.TabControl.SuspendLayout()
		Me.GeneralTab.SuspendLayout()
		Me.SuspendLayout()
		'
		'WaypointDisplayModeComboBox
		'
		Me.WaypointDisplayModeComboBox.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.WaypointDisplayModeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.WaypointDisplayModeComboBox.Location = New System.Drawing.Point(120, 126)
		Me.WaypointDisplayModeComboBox.Name = "WaypointDisplayModeComboBox"
		Me.WaypointDisplayModeComboBox.Size = New System.Drawing.Size(264, 21)
		Me.WaypointDisplayModeComboBox.Sorted = True
		Me.WaypointDisplayModeComboBox.TabIndex = 11
		'
		'WaypointSymbolComboBox
		'
		Me.WaypointSymbolComboBox.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.WaypointSymbolComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.WaypointSymbolComboBox.Location = New System.Drawing.Point(120, 78)
		Me.WaypointSymbolComboBox.Name = "WaypointSymbolComboBox"
		Me.WaypointSymbolComboBox.Size = New System.Drawing.Size(264, 21)
		Me.WaypointSymbolComboBox.Sorted = True
		Me.WaypointSymbolComboBox.TabIndex = 7
		'
		'WaypointNameLabel
		'
		Me.WaypointNameLabel.Location = New System.Drawing.Point(9, 9)
		Me.WaypointNameLabel.Name = "WaypointNameLabel"
		Me.WaypointNameLabel.Size = New System.Drawing.Size(99, 15)
		Me.WaypointNameLabel.TabIndex = 0
		Me.WaypointNameLabel.Text = "Name:"
		'
		'WaypointName
		'
		Me.WaypointName.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.WaypointName.Location = New System.Drawing.Point(120, 6)
		Me.WaypointName.Name = "WaypointName"
		Me.WaypointName.Size = New System.Drawing.Size(264, 20)
		Me.WaypointName.TabIndex = 1
		Me.WaypointName.Text = ""
		'
		'btnCancelButton
		'
		Me.btnCancelButton.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.btnCancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel
		Me.btnCancelButton.Location = New System.Drawing.Point(339, 396)
		Me.btnCancelButton.Name = "btnCancelButton"
		Me.btnCancelButton.Size = New System.Drawing.Size(72, 24)
		Me.btnCancelButton.TabIndex = 2
		Me.btnCancelButton.Text = "Cancel"
		'
		'SaveButton
		'
		Me.SaveButton.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.SaveButton.DialogResult = System.Windows.Forms.DialogResult.OK
		Me.SaveButton.Location = New System.Drawing.Point(261, 396)
		Me.SaveButton.Name = "SaveButton"
		Me.SaveButton.Size = New System.Drawing.Size(72, 24)
		Me.SaveButton.TabIndex = 1
		Me.SaveButton.Text = "Save"
		'
		'Position
		'
		Me.Position.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.Position.Location = New System.Drawing.Point(120, 30)
		Me.Position.Name = "Position"
		Me.Position.Size = New System.Drawing.Size(264, 20)
		Me.Position.TabIndex = 3
		Me.Position.Text = ""
		'
		'Label2
		'
		Me.Label2.Location = New System.Drawing.Point(9, 33)
		Me.Label2.Name = "Label2"
		Me.Label2.Size = New System.Drawing.Size(99, 15)
		Me.Label2.TabIndex = 2
		Me.Label2.Text = "Position:"
		'
		'Description
		'
		Me.Description.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.Description.Location = New System.Drawing.Point(120, 54)
		Me.Description.Name = "Description"
		Me.Description.Size = New System.Drawing.Size(264, 20)
		Me.Description.TabIndex = 5
		Me.Description.Text = ""
		'
		'DescriptionLabel
		'
		Me.DescriptionLabel.Location = New System.Drawing.Point(9, 57)
		Me.DescriptionLabel.Name = "DescriptionLabel"
		Me.DescriptionLabel.Size = New System.Drawing.Size(99, 15)
		Me.DescriptionLabel.TabIndex = 4
		Me.DescriptionLabel.Text = "Description:"
		'
		'SymbolLabel
		'
		Me.SymbolLabel.Location = New System.Drawing.Point(9, 81)
		Me.SymbolLabel.Name = "SymbolLabel"
		Me.SymbolLabel.Size = New System.Drawing.Size(99, 15)
		Me.SymbolLabel.TabIndex = 6
		Me.SymbolLabel.Text = "Symbol:"
		'
		'ColorLabel
		'
		Me.ColorLabel.Location = New System.Drawing.Point(9, 105)
		Me.ColorLabel.Name = "ColorLabel"
		Me.ColorLabel.Size = New System.Drawing.Size(99, 15)
		Me.ColorLabel.TabIndex = 8
		Me.ColorLabel.Text = "Color:"
		'
		'WaypointColorComboBox
		'
		Me.WaypointColorComboBox.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.WaypointColorComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.WaypointColorComboBox.Location = New System.Drawing.Point(120, 102)
		Me.WaypointColorComboBox.Name = "WaypointColorComboBox"
		Me.WaypointColorComboBox.Size = New System.Drawing.Size(264, 21)
		Me.WaypointColorComboBox.Sorted = True
		Me.WaypointColorComboBox.TabIndex = 9
		'
		'DisplayModeLabel
		'
		Me.DisplayModeLabel.Location = New System.Drawing.Point(9, 129)
		Me.DisplayModeLabel.Name = "DisplayModeLabel"
		Me.DisplayModeLabel.Size = New System.Drawing.Size(99, 15)
		Me.DisplayModeLabel.TabIndex = 10
		Me.DisplayModeLabel.Text = "Display Mode:"
		'
		'Depth
		'
		Me.Depth.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.Depth.Location = New System.Drawing.Point(120, 174)
		Me.Depth.Name = "Depth"
		Me.Depth.Size = New System.Drawing.Size(264, 20)
		Me.Depth.TabIndex = 15
		Me.Depth.Text = ""
		'
		'DepthLabel
		'
		Me.DepthLabel.Location = New System.Drawing.Point(9, 177)
		Me.DepthLabel.Name = "DepthLabel"
		Me.DepthLabel.Size = New System.Drawing.Size(99, 15)
		Me.DepthLabel.TabIndex = 14
		Me.DepthLabel.Text = "Depth:"
		'
		'Altitude
		'
		Me.Altitude.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.Altitude.Location = New System.Drawing.Point(120, 150)
		Me.Altitude.Name = "Altitude"
		Me.Altitude.Size = New System.Drawing.Size(264, 20)
		Me.Altitude.TabIndex = 13
		Me.Altitude.Text = ""
		'
		'AltitudeLabel
		'
		Me.AltitudeLabel.Location = New System.Drawing.Point(9, 153)
		Me.AltitudeLabel.Name = "AltitudeLabel"
		Me.AltitudeLabel.Size = New System.Drawing.Size(99, 15)
		Me.AltitudeLabel.TabIndex = 12
		Me.AltitudeLabel.Text = "Altitude:"
		'
		'City
		'
		Me.City.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.City.Location = New System.Drawing.Point(120, 246)
		Me.City.Name = "City"
		Me.City.Size = New System.Drawing.Size(264, 20)
		Me.City.TabIndex = 21
		Me.City.Text = ""
		'
		'CityLabel
		'
		Me.CityLabel.Location = New System.Drawing.Point(9, 249)
		Me.CityLabel.Name = "CityLabel"
		Me.CityLabel.Size = New System.Drawing.Size(99, 15)
		Me.CityLabel.TabIndex = 20
		Me.CityLabel.Text = "City:"
		'
		'Address
		'
		Me.Address.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.Address.Location = New System.Drawing.Point(120, 222)
		Me.Address.Name = "Address"
		Me.Address.Size = New System.Drawing.Size(264, 20)
		Me.Address.TabIndex = 19
		Me.Address.Text = ""
		'
		'AddressLabel
		'
		Me.AddressLabel.Location = New System.Drawing.Point(9, 225)
		Me.AddressLabel.Name = "AddressLabel"
		Me.AddressLabel.Size = New System.Drawing.Size(99, 15)
		Me.AddressLabel.TabIndex = 18
		Me.AddressLabel.Text = "Address:"
		'
		'Country
		'
		Me.Country.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.Country.Location = New System.Drawing.Point(120, 294)
		Me.Country.MaxLength = 2
		Me.Country.Name = "Country"
		Me.Country.Size = New System.Drawing.Size(264, 20)
		Me.Country.TabIndex = 25
		Me.Country.Text = ""
		'
		'CountryLabel
		'
		Me.CountryLabel.Location = New System.Drawing.Point(9, 297)
		Me.CountryLabel.Name = "CountryLabel"
		Me.CountryLabel.Size = New System.Drawing.Size(99, 15)
		Me.CountryLabel.TabIndex = 24
		Me.CountryLabel.Text = "Country:"
		'
		'State
		'
		Me.State.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.State.Location = New System.Drawing.Point(120, 270)
		Me.State.MaxLength = 2
		Me.State.Name = "State"
		Me.State.Size = New System.Drawing.Size(264, 20)
		Me.State.TabIndex = 23
		Me.State.Text = ""
		'
		'StateLabel
		'
		Me.StateLabel.Location = New System.Drawing.Point(9, 273)
		Me.StateLabel.Name = "StateLabel"
		Me.StateLabel.Size = New System.Drawing.Size(99, 15)
		Me.StateLabel.TabIndex = 22
		Me.StateLabel.Text = "State:"
		'
		'IntersectingRoad
		'
		Me.IntersectingRoad.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.IntersectingRoad.Location = New System.Drawing.Point(120, 318)
		Me.IntersectingRoad.Name = "IntersectingRoad"
		Me.IntersectingRoad.Size = New System.Drawing.Size(264, 20)
		Me.IntersectingRoad.TabIndex = 27
		Me.IntersectingRoad.Text = ""
		'
		'IntersectingRoadLabel
		'
		Me.IntersectingRoadLabel.Location = New System.Drawing.Point(9, 321)
		Me.IntersectingRoadLabel.Name = "IntersectingRoadLabel"
		Me.IntersectingRoadLabel.Size = New System.Drawing.Size(99, 15)
		Me.IntersectingRoadLabel.TabIndex = 26
		Me.IntersectingRoadLabel.Text = "Intersecting Road:"
		'
		'TabControl
		'
		Me.TabControl.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
					Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.TabControl.Controls.Add(Me.GeneralTab)
		Me.TabControl.Location = New System.Drawing.Point(9, 9)
		Me.TabControl.Name = "TabControl"
		Me.TabControl.SelectedIndex = 0
		Me.TabControl.Size = New System.Drawing.Size(405, 375)
		Me.TabControl.TabIndex = 0
		'
		'GeneralTab
		'
		Me.GeneralTab.Controls.Add(Me.FacilityLabel)
		Me.GeneralTab.Controls.Add(Me.Facility)
		Me.GeneralTab.Controls.Add(Me.CountryLabel)
		Me.GeneralTab.Controls.Add(Me.State)
		Me.GeneralTab.Controls.Add(Me.StateLabel)
		Me.GeneralTab.Controls.Add(Me.AddressLabel)
		Me.GeneralTab.Controls.Add(Me.Address)
		Me.GeneralTab.Controls.Add(Me.CityLabel)
		Me.GeneralTab.Controls.Add(Me.City)
		Me.GeneralTab.Controls.Add(Me.Country)
		Me.GeneralTab.Controls.Add(Me.IntersectingRoad)
		Me.GeneralTab.Controls.Add(Me.WaypointColorComboBox)
		Me.GeneralTab.Controls.Add(Me.WaypointDisplayModeComboBox)
		Me.GeneralTab.Controls.Add(Me.DisplayModeLabel)
		Me.GeneralTab.Controls.Add(Me.WaypointNameLabel)
		Me.GeneralTab.Controls.Add(Me.IntersectingRoadLabel)
		Me.GeneralTab.Controls.Add(Me.Label2)
		Me.GeneralTab.Controls.Add(Me.Depth)
		Me.GeneralTab.Controls.Add(Me.WaypointSymbolComboBox)
		Me.GeneralTab.Controls.Add(Me.WaypointName)
		Me.GeneralTab.Controls.Add(Me.Position)
		Me.GeneralTab.Controls.Add(Me.Description)
		Me.GeneralTab.Controls.Add(Me.AltitudeLabel)
		Me.GeneralTab.Controls.Add(Me.DepthLabel)
		Me.GeneralTab.Controls.Add(Me.SymbolLabel)
		Me.GeneralTab.Controls.Add(Me.Altitude)
		Me.GeneralTab.Controls.Add(Me.ColorLabel)
		Me.GeneralTab.Controls.Add(Me.DescriptionLabel)
		Me.GeneralTab.Location = New System.Drawing.Point(4, 22)
		Me.GeneralTab.Name = "GeneralTab"
		Me.GeneralTab.Size = New System.Drawing.Size(397, 349)
		Me.GeneralTab.TabIndex = 0
		Me.GeneralTab.Text = "General"
		'
		'FacilityLabel
		'
		Me.FacilityLabel.Location = New System.Drawing.Point(9, 201)
		Me.FacilityLabel.Name = "FacilityLabel"
		Me.FacilityLabel.Size = New System.Drawing.Size(99, 15)
		Me.FacilityLabel.TabIndex = 16
		Me.FacilityLabel.Text = "Facility Name:"
		'
		'Facility
		'
		Me.Facility.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.Facility.Location = New System.Drawing.Point(120, 198)
		Me.Facility.Name = "Facility"
		Me.Facility.Size = New System.Drawing.Size(264, 20)
		Me.Facility.TabIndex = 17
		Me.Facility.Text = ""
		'
		'NewWaypointForm
		'
		Me.AcceptButton = Me.SaveButton
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
		Me.CancelButton = Me.btnCancelButton
		Me.ClientSize = New System.Drawing.Size(423, 433)
		Me.Controls.Add(Me.TabControl)
		Me.Controls.Add(Me.btnCancelButton)
		Me.Controls.Add(Me.SaveButton)
		Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
		Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
		Me.MaximizeBox = False
		Me.MinimizeBox = False
		Me.Name = "NewWaypointForm"
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		Me.Text = "Add Waypoint"
		Me.TabControl.ResumeLayout(False)
		Me.GeneralTab.ResumeLayout(False)
		Me.ResumeLayout(False)

	End Sub

#End Region

	' Stores information about a GPS device
	Private WithEvents pDevice As Device

	' Returns/sets the device containing waypoint information
	Public Property Device() As Device
		Get
			Return pDevice
		End Get
		Set(ByVal Value As Device)
			' Remember the waypoint for editing later on
			pDevice = Value

			' Populate the combo box with the list of available waypoint symbols
			WaypointSymbolComboBox.Items.Clear()
			WaypointSymbolComboBox.Items.AddRange(pDevice.GetSymbols)
			WaypointSymbolComboBox.SelectedIndex = WaypointSymbolComboBox.FindString("Dot")

			' Populate the color combo box with the list of available waypoint symbols
			WaypointColorComboBox.Items.Clear()
			WaypointColorComboBox.Items.AddRange(pDevice.GetColors)
			WaypointColorComboBox.SelectedIndex = WaypointColorComboBox.FindString("Default")

			' Populate the display mode box with the list of available waypoint symbols
			WaypointDisplayModeComboBox.Items.Clear()
			WaypointDisplayModeComboBox.Items.AddRange(pDevice.GetDisplayModes)
			WaypointDisplayModeComboBox.SelectedIndex = WaypointDisplayModeComboBox.FindString("SymbolOnly")

			' Now, enable/disable features based on the capabilities of the device
			Description.Enabled = pDevice.SupportsWaypointComment
			Address.Enabled = pDevice.SupportsWaypointAddress
			WaypointSymbolComboBox.Enabled = pDevice.SupportsWaypointSymbol
			WaypointColorComboBox.Enabled = pDevice.SupportsWaypointColor
			WaypointDisplayModeComboBox.Enabled = pDevice.SupportsWaypointDisplayMode
			Facility.Enabled = pDevice.SupportsWaypointFacility
			Address.Enabled = pDevice.SupportsWaypointAddress
			City.Enabled = pDevice.SupportsWaypointCity
			State.Enabled = pDevice.SupportsWaypointState
			Country.Enabled = pDevice.SupportsWaypointCountry
			IntersectingRoad.Enabled = pDevice.SupportsWaypointIntersectingRoad
		End Set
	End Property

	Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
		Dim NewWaypoint As Waypoint
		' Now set the waypoint's properties
		Try
			' Create a new waypoint 
			NewWaypoint = New Waypoint()
			' Update the waypoint with values from the form
			NewWaypoint.Name = Me.WaypointName.Text
			' Update the position
			Dim NewPosition As Position = StormSource.GPS.Position.Parse(Position.Text)
			NewWaypoint.Latitude = NewPosition.Latitude
			NewWaypoint.Longitude = NewPosition.Longitude
			' Update the comment
			NewWaypoint.Description = Me.Description.Text
			' Update the symbol
			NewWaypoint.Symbol = System.Enum.Parse(GetType(WaypointSymbol), WaypointSymbolComboBox.Text)
			' Update the color
			NewWaypoint.Color = System.Enum.Parse(GetType(WaypointColor), WaypointColorComboBox.Text)
			' Update the symbol
			NewWaypoint.DisplayMode = System.Enum.Parse(GetType(WaypointDisplayMode), WaypointDisplayModeComboBox.Text)
			' Update the altitude
			Dim NewAltitude As Distance = Distance.Parse(Me.Altitude.Text)
			NewWaypoint.Altitude = NewAltitude
			' Update the depth
			Dim NewDepth As Distance = Distance.Parse(Me.Depth.Text)
			NewWaypoint.Depth = NewDepth
			' Update the facility
			NewWaypoint.Facility = Me.Facility.Text
			' Update the address
			NewWaypoint.Address = Me.Address.Text
			NewWaypoint.City = Me.City.Text
			NewWaypoint.State = Me.State.Text
			NewWaypoint.Country = Me.Country.Text
			' Update the intersecting road/intersection
			NewWaypoint.IntersectingRoad = Me.IntersectingRoad.Text
		Catch ex As Exception
			' Some error occurred while try to update waypoint information
			MessageBox.Show(ex.Message, "Form Information is Invalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
			Exit Sub
		End Try
		Try
			' Tell the waypoint which kind of GPS device to use
			NewWaypoint.Device = Me.Device
			' Save this waypoint to the device
			NewWaypoint.Save()
			' Refresh the waypoints collection
			NewWaypoint.Device.Receiver.Waypoints.Refresh()
			' And unload this form
			Close()
		Catch ex As Exception
			' Notify of the problem saving the waypoint
			MessageBox.Show(ex.Message, "Unable to Create Waypoint", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
			Exit Sub
		End Try
	End Sub

	' Raised when editing of a waypoint has been cancelled
	Private Sub btnCancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelButton.Click
		Close()
	End Sub

	' Raised when the device becomes identified
	Private Sub pDevice_DeviceIdentified(ByVal sender As Object, ByVal e As StormSource.GPS.DeviceEventArgs) Handles pDevice.DeviceIdentified
		Me.Device = e.Device
	End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Black Knight Financial Services
United States United States
Hi there! From 2004 to 2009 I ran a company called "GeoFrameworks," publishing two components called GPS.NET and GIS.NET which helped developers quickly write location-based services. Now, I've released the source code for GPS.NET to CodePlex for you to use as you see fit.

GPS.NET 2.0 on CodePlex
GPS.NET 3.0 on CodePlex

... I've also released the source code of a library called the "GeoFramework," a collection of commonly used classes such as Latitude, Longitude, Distance, Speed, and Position:

GeoFramework 1.0 on CodePlex
GeoFramework 2.0 on CodePlex

I'm now taking a break from programming, but I really appreciate the positive feedback from readers!

Comments and Discussions