[RESOLVED] [2005] Create Custom type
Ok Here is my situation, I am writing a class that is used to convert between various GPS Coordinate Systems, To do this, the use can select a Datum which changes 2 values that are used in the calcualtions.
ie
Datum
Name = "NAD83/WGS84 (Global)"
a = 6378137
b = 6353752.3142
etc...
What I have now is a structure that is defined as so
VB Code:
Public Structure Datum
Dim Name As String
Dim a As Double
Dim b As Double
End Structure
what I am wondering is this, Is it possible to set up a custom type of sorts with 3 values, (name, a and b) so that I could do something like this
VB Code:
Public Property Datum() as DatumType
Get
Return DatumType.Name
End Get
Set(ByVal value As Double)
DatumType.Name = value
End Set
End Property
Essentially what I want to happen is that when you go to set the property when using this class and you create a new instance, I want the Datum Property to give you a list of specific items that you can pick from that will then set the values of a anb b in the class
VB Code:
Dim gps As New ConvertGPS
gps.Datum = 'have this show a predefined list of my datums to set the property
I hope that I have been clear about this and thank you for any help
Re: [2005] Create Custom type
Like this?
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim gps As New ConvertGPS
gps.Add(MyDatums.Wild_Bill_Test)
gps.Add(MyDatums.NAD83_WGS84_Global)
For Each d As Datum In gps
Console.WriteLine(d.Name)
Next
End Sub
Public Class Datum
Public Name As String
Public a As Double
Public b As Double
Public Sub New(ByVal newName As String, ByVal newA As Double, ByVal newB As Double)
Name = newName
a = newA
b = newB
End Sub
End Class
Public Enum MyDatums
NAD83_WGS84_Global = 0
Wild_Bill_Test = 1
End Enum
Public Class ConvertGPS
Inherits CollectionBase
'stores an array of all possible selections where the index is equal to the MyDatums enumerator
Private _dateNumList() As Datum = New Datum() _
{New Datum("NAD83/WGS84 (Global)", 6378137, 6353752.3142), New Datum("Wild Bill Test", 12, 12)}
Public Overridable Sub Add(ByVal name As MyDatums)
Me.List.Add(_dateNumList(name))
End Sub
Default Public Overridable ReadOnly Property Item(ByVal name As MyDatums) As Datum
Get
Return _dateNumList(name)
End Get
End Property
End Class
1 Attachment(s)
Re: [2005] Create Custom type
Hmmm, I used your example to play around a bit to get what I have now, but it still is not exactly what I am looking for, I am trying to make implementing this into the project a little easier, but I think with this I have actually made it a little more complicated. Here is what I have in my class so far. What I was hoping to acclomplish was to do away with the Datum Structure, however I need it to populate a combobox on the form. Is there a way to populate a combobox with all the items in my enum?
oops, my code is too long so here is an attachment
Re: [2005] Create Custom type
You can use [Enum].GetNames() to get the text of the enums in an array and you can use that to fill the combo.
Re: [2005] Create Custom type
Re: [2005] Create Custom type
bmahler, some time back i developed a project to accomplish the direction you are heading! If you dont mind,It may be of help to you!
Re: [RESOLVED] [2005] Create Custom type
You developed a project to convert GPS systems? or on using custom types?
Re: [RESOLVED] [2005] Create Custom type