Results 1 to 5 of 5

Thread: Creating my own Data Type?

  1. #1

    Thread Starter
    Hyperactive Member ZeroCool's Avatar
    Join Date
    Feb 2002
    Location
    In front of my computer
    Posts
    423

    Creating my own Data Type?

    Is there anyway i can create my own data type based on an Integer, basicly I want to change the way the bits are stored.

    eg)

    00000000 00000000 00000001 00001111

    Normally this would represent 2^0+2^1+2^2+2^3+2^8 = 135

    I want the DataType to Interpert that as this:

    00000000 00011111 2^0+2^1+2^2+2^3+2^4 = 31

    I dont really need help with the math, I have implemented this as a class i *think* it would be easier to use if a implemented as a data type.

    Any examples on how to define your own data type?
    Visual Baisc 6 (SP5)
    Windows Xp

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    VB Code:
    1. Public Type NewType
    2.     NewTypeVal1 As String
    3. End Type
    4.  
    5. Dim new_type As NewType
    6. new_type.NewTypeVal1 = "Hello World!"

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Actually type is what it was called in VB6 now its Structure:
    VB Code:
    1. Public Structure NewType
    2.         Public NewTypeVal1 As String
    3.     End Structure
    4.  
    5.     Dim new_type As NewType
    6.     new_type.NewTypeVal1 = "Hello World!"

    Either a structure or class is how to make your own data types.

  4. #4

    Thread Starter
    Hyperactive Member ZeroCool's Avatar
    Join Date
    Feb 2002
    Location
    In front of my computer
    Posts
    423
    So do i do something like this?

    VB Code:
    1. Option Explicit On
    2. Option Strict On
    3.  
    4. Public Class cNewDataType
    5.     Inherits System.Type
    6.  
    7.     Public Overrides ReadOnly Property [Assembly]() As System.Reflection.Assembly
    8.         Get
    9.  
    10.         End Get
    11.     End Property
    12.  
    13.     Public Overrides ReadOnly Property AssemblyQualifiedName() As String
    14.         Get
    15.  
    16.         End Get
    17.     End Property
    18.  
    19.     Public Overrides ReadOnly Property BaseType() As System.Type
    20.         Get
    21.  
    22.         End Get
    23.     End Property
    24.  
    25.     Public Overrides ReadOnly Property FullName() As String
    26.         Get
    27.  
    28.         End Get
    29.     End Property
    30.  
    31.     Protected Overrides Function GetAttributeFlagsImpl() As System.Reflection.TypeAttributes
    32.  
    33.     End Function
    34.  
    35.     Protected Overrides Function GetConstructorImpl(ByVal bindingAttr As System.Reflection.BindingFlags, ByVal binder As System.Reflection.Binder, ByVal callConvention As System.Reflection.CallingConventions, ByVal types() As System.Type, ByVal modifiers() As System.Reflection.ParameterModifier) As System.Reflection.ConstructorInfo
    36.  
    37.     End Function
    38.  
    39.     Public Overloads Overrides Function GetConstructors(ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.ConstructorInfo()
    40.  
    41.     End Function
    42.  
    43.     Public Overloads Overrides Function GetCustomAttributes(ByVal inherit As Boolean) As Object()
    44.  
    45.     End Function
    46.  
    47.     Public Overloads Overrides Function GetCustomAttributes(ByVal attributeType As System.Type, ByVal inherit As Boolean) As Object()
    48.  
    49.     End Function
    50.  
    51.     Public Overrides Function GetElementType() As System.Type
    52.  
    53.     End Function
    54.  
    55.     Public Overloads Overrides Function GetEvent(ByVal name As String, ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.EventInfo
    56.  
    57.     End Function
    58.  
    59.     Public Overloads Overrides Function GetEvents(ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.EventInfo()
    60.  
    61.     End Function
    62.  
    63.     Public Overloads Overrides Function GetField(ByVal name As String, ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.FieldInfo
    64.  
    65.     End Function
    66.  
    67.     Public Overloads Overrides Function GetFields(ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.FieldInfo()
    68.  
    69.     End Function
    70.  
    71.     Public Overloads Overrides Function GetInterface(ByVal name As String, ByVal ignoreCase As Boolean) As System.Type
    72.  
    73.     End Function
    74.  
    75.     Public Overrides Function GetInterfaces() As System.Type()
    76.  
    77.     End Function
    78.  
    79.     Public Overloads Overrides Function GetMembers(ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.MemberInfo()
    80.  
    81.     End Function
    82.  
    83.     Protected Overrides Function GetMethodImpl(ByVal name As String, ByVal bindingAttr As System.Reflection.BindingFlags, ByVal binder As System.Reflection.Binder, ByVal callConvention As System.Reflection.CallingConventions, ByVal types() As System.Type, ByVal modifiers() As System.Reflection.ParameterModifier) As System.Reflection.MethodInfo
    84.  
    85.     End Function
    86.  
    87.     Public Overloads Overrides Function GetMethods(ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.MethodInfo()
    88.  
    89.     End Function
    90.  
    91.     Public Overloads Overrides Function GetNestedType(ByVal name As String, ByVal bindingAttr As System.Reflection.BindingFlags) As System.Type
    92.  
    93.     End Function
    94.  
    95.     Public Overloads Overrides Function GetNestedTypes(ByVal bindingAttr As System.Reflection.BindingFlags) As System.Type()
    96.  
    97.     End Function
    98.  
    99.     Public Overloads Overrides Function GetProperties(ByVal bindingAttr As System.Reflection.BindingFlags) As System.Reflection.PropertyInfo()
    100.  
    101.     End Function
    102.  
    103.     Protected Overrides Function GetPropertyImpl(ByVal name As String, ByVal bindingAttr As System.Reflection.BindingFlags, ByVal binder As System.Reflection.Binder, ByVal returnType As System.Type, ByVal types() As System.Type, ByVal modifiers() As System.Reflection.ParameterModifier) As System.Reflection.PropertyInfo
    104.  
    105.     End Function
    106.  
    107.     Public Overrides ReadOnly Property GUID() As System.Guid
    108.         Get
    109.  
    110.         End Get
    111.     End Property
    112.  
    113.     Protected Overrides Function HasElementTypeImpl() As Boolean
    114.  
    115.     End Function
    116.  
    117.     Public Overloads Overrides Function InvokeMember(ByVal name As String, ByVal invokeAttr As System.Reflection.BindingFlags, ByVal binder As System.Reflection.Binder, ByVal target As Object, ByVal args() As Object, ByVal modifiers() As System.Reflection.ParameterModifier, ByVal culture As System.Globalization.CultureInfo, ByVal namedParameters() As String) As Object
    118.  
    119.     End Function
    120.  
    121.     Protected Overrides Function IsArrayImpl() As Boolean
    122.  
    123.     End Function
    124.  
    125.     Protected Overrides Function IsByRefImpl() As Boolean
    126.  
    127.     End Function
    128.  
    129.     Protected Overrides Function IsCOMObjectImpl() As Boolean
    130.  
    131.     End Function
    132.  
    133.     Public Overrides Function IsDefined(ByVal attributeType As System.Type, ByVal inherit As Boolean) As Boolean
    134.  
    135.     End Function
    136.  
    137.     Protected Overrides Function IsPointerImpl() As Boolean
    138.  
    139.     End Function
    140.  
    141.     Protected Overrides Function IsPrimitiveImpl() As Boolean
    142.  
    143.     End Function
    144.  
    145.     Public Overrides ReadOnly Property [Module]() As System.Reflection.Module
    146.         Get
    147.  
    148.         End Get
    149.     End Property
    150.  
    151.     Public Overrides ReadOnly Property Name() As String
    152.         Get
    153.  
    154.         End Get
    155.     End Property
    156.  
    157.     Public Overrides ReadOnly Property [Namespace]() As String
    158.         Get
    159.  
    160.         End Get
    161.     End Property
    162.  
    163.     Public Overrides ReadOnly Property TypeHandle() As System.RuntimeTypeHandle
    164.         Get
    165.  
    166.         End Get
    167.     End Property
    168.  
    169.     Public Overrides ReadOnly Property UnderlyingSystemType() As System.Type
    170.         Get
    171.  
    172.         End Get
    173.     End Property
    174. End Class
    Visual Baisc 6 (SP5)
    Windows Xp

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Not really there you are inheriting from Type but a type class object will be made for you when you make a normal object. It'd be more like this:
    VB Code:
    1. Public Class IntegerEx
    2.  
    3.     Private _value As Byte
    4.  
    5.     Public Property Value() As Integer
    6.         Get
    7.             'convert yor value to an integer
    8.             Return Integer.Parse(_value.ToString)
    9.         End Get
    10.         Set(ByVal Value As Integer)
    11.             'convert actual integer to your data
    12.             _value = CType(Value, Byte)
    13.         End Set
    14.     End Property
    15.  
    16. End Class
    17.  
    18. 'syntax
    19.         Dim ie As New IntegerEx
    20.         ie.Value = 1
    21.         MsgBox(ie.Value)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width