Hi,
Can you expand on your question please?
Are you wanting to change a datatype within a CLASS or simply it's value?
One idea you could do is have all your datatypes as STRING and convert to type string.
E.g. CLASS name is Account.Vb
If account has AccountName, SortCode and AccountNumber elements all As type STRING.
Then in code if you use any other datatype you could do for example>>
Dim accountNum As Integer
Dim newAccount As New Account 'You would need a NEW Sub in your CLASS code.
newAccount.AccountNumber=CSTR(accountNum)
If that's not what your meaning then please expand on your question.
Regards,
S_DS
Public Class IPv4Base Public Overridable Property FirstOct() As Byte Public Overridable Property SecOct() As Byte Public Overridable Property ThirdOct() As Byte Public Overridable Property FourthOct() As Byte Public Property IPClass() As String Public Class SubnetMask Private _SlashNotation As Integer Public Property SlashNotation() As Integer ' Sync with Decimal notation End Set Public Sub New() End Sub ' New() accepting Bytes ' New() accepting Strings ' Validating Strings ' If validated then set values End Sub So basically i want to change the way set() is done in the SubnetMask class. I tried overidding:
Private _FirstOct As Byte
Private _SecOct As Byte
Private _ThirdOct As Byte
Private _FourthOct As Byte
Private _Class As String
' ++++++++++++++++++++++++++++++++++++++++++++++++++++
' Constructors
' ++++++++++++++++++++++++++++++++++++++++++++++++++++
Public Sub New()
_FirstOct = 0
.....
End Sub
' New() accepting Bytes
Public Sub New(ByVal byte1 As Byte, ByVal byte2 As Byte, ByVal byte3 As Byte, ByVal byte4 As Byte)
_FirstOct = byte1
.....
End Sub
' New() accepting Strings
' Requires validation
Public Sub New(ByVal str1 As String, ByVal str2 As String, ByVal str3 As String, ByVal str4 As String)
Dim bytesArray(3) As Byte
Dim index As Int16 = 0
' Validating Strings
Try
bytesArray(0) = CByte(str1)
...
Catch ex As Exception
MessageBox.Show("Error .....)
' Exit Sub New() if have errors
Exit Sub
End Try
' If validated then set values
_FirstOct = bytesArray(0)
_SecOct = bytesArray(1)
_ThirdOct = bytesArray(2)
_FourthOct = bytesArray(3)
End Sub' ++++++++++++++++++++++++++++++++++++++++++++++++++++
' Properties
' ++++++++++++++++++++++++++++++++++++++++++++++++++++
Get
Return _FirstOct
End Get
Set(ByVal value As Byte)
_FirstOct = value
End Set
End Property
Get
Return _SecOct
End Get
Set(ByVal value As Byte)
_SecOct = value
End Set
End Property
Get
Return _ThirdOct
End Get
Set(ByVal value As Byte)
_ThirdOct = value
End Set
End Property
Get
Return _FourthOct
End Get
Set(ByVal value As Byte)
_FourthOct = value
End Set
End Property
Get
Return _Class
End Get
Set(ByVal value As String)
_Class = value
End Set
End Property
Inherits IPv4Base
Private validValues() As Byte = {0, 128, 192, 224, 240, 248, 252}
Get
Return _SlashNotation
End Get
Set(ByVal value As Integer)
' Validating
......
Exit Property
End If
_SlashNotation = value
End Property
' My Sub New() are copied and pasted from IPv4Base is this supposed to be done,
' I thought they should be inherited?
Public Sub New(ByVal byte1 As Byte, ByVal byte2 As Byte, ByVal byte3 As Byte, ByVal byte4 As Byte)
FirstOct = byte1
.....
End Sub
' Requires validation
Public Sub New(ByVal str1 As String, ByVal str2 As String, ByVal str3 As String, ByVal str4 As String)
Dim bytesArray(3) As Byte
Dim index As Int16 = 0
Try
bytesArray(0) = CByte(str1)
bytesArray(1) = ......
Catch ex As Exception
MessageBox.Show("Error .....)
' Exit Sub New() if have errors
Exit Sub
End Try
FirstOct = bytesArray(0)
SecOct = bytesArray(1)
ThirdOct = bytesArray(2)
FourthOct = bytesArray(3)
Public Overrides Property FirstOct() As Byte
Get
Return _FirstOct
' error:IPv4Base._FirstOct is not accessible because its 'Private'
End Get
Set(ByVal value As Byte)
_FirstOct = value ' same Error Here also
End Set
End Property
Hi
I would recommend that you follow your instincts and override the property. You do not need to cut and paste the base class code if you do not want to change the getter .. simply type Get : Return MyBase.PropertyName : End Get.
Sometime I do prefer to split the Get and Set operation into base class methods and allow those to be overridden. This allows you to easily override just the part you want to.
Hope this is what you were looking for.
Richard
Eg
Pubic Property Foo As String
Get : Return Me.getFoo: End Get
Set (ByVal value As String) : Me.setFoo(value) : End Set
End Property
Protected Overridable Function getFoo As String
Return Me.mFoo
End Function
Protected Overridable Sub setFoo (ByVal value As String)
Me.mFoo = Value
End Sub
Additionally, you don't need to copy the code in your sub new() functions if it's the same functionality. Just call the appropriate base function MyBase.New(...) (didn't we already do this in another thread?)
SJWhiteley wrote:
Additionally, you don't need to copy the code in your sub new() functions if it's the same functionality. Just call the appropriate base function MyBase.New(...) (didn't we already do this in another thread?)
Ya, i remembered, but didn't quite understand, so just to clarify, if in MyBaseClass, i have the Sub New() with code already, i just need to put Sub New() with no code in MyChildClass? sorry i just a bit confused.
That's OK...
Public Class BaseClass
Sub New()
End Sub
Sub New(ByVal a As Integer, ByVal b As Integer)
' Lots of code here...
End Sub
End Class
Public Class InheritedClass : Inherits BaseClass
Sub New(ByVal a As Integer, ByVal b As Integer)
MyBase.New(a, b)
End Sub
End Class
As you can see in the inherited class, instead of duplicating all the code from the prameterized constructor in the base class, we simply call the base parameterized constructor. The reason is that the inherited class does not expose the base class parameterized constructor: we must expose it manually.
Hope that makes a bit more sense.