Advertisement
Guest User

Visual Basic: Conversions

a guest
May 28th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.73 KB | None | 0 0
  1. #Region "Conversions"
  2.         Public Function [Boolean](ByVal lpValue() As Byte) As Boolean
  3.             Return BitConverter.ToBoolean(lpValue, 0)
  4.         End Function
  5.  
  6.         Public Function [Boolean](ByVal bValue As Boolean) As Byte()
  7.             Return BitConverter.GetBytes(bValue)
  8.         End Function
  9.  
  10.         Public Function [Byte](ByVal lpValue() As Byte) As Byte
  11.             Return lpValue(0)
  12.         End Function
  13.  
  14.         Public Function [Byte](ByVal dwValue As Byte) As Byte()
  15.             Return BitConverter.GetBytes(dwValue)
  16.         End Function
  17.  
  18.         Public Function [Char](ByVal lpValue() As Byte) As Char
  19.             Return BitConverter.ToChar(lpValue, 0)
  20.         End Function
  21.  
  22.         Public Function [Char](ByVal cValue As Char) As Byte()
  23.             Return BitConverter.GetBytes(cValue)
  24.         End Function
  25.  
  26.         Public Function [Double](ByVal lpValue() As Byte) As Double
  27.             Return BitConverter.ToDouble(lpValue, 0)
  28.         End Function
  29.  
  30.         Public Function [Double](ByVal dblValue As Double) As Byte()
  31.             Return BitConverter.GetBytes(dblValue)
  32.         End Function
  33.  
  34.         Public Function [Int16](ByVal lpValue() As Byte) As Int16
  35.             Return BitConverter.ToInt16(lpValue, 0)
  36.         End Function
  37.  
  38.         Public Function [Int16](ByVal nValue As Int16) As Byte()
  39.             Return BitConverter.GetBytes(nValue)
  40.         End Function
  41.  
  42.         Public Function [Int32](ByVal lpValue() As Byte) As Int32
  43.             Return BitConverter.ToInt32(lpValue, 0)
  44.         End Function
  45.  
  46.         Public Function [Int32](ByVal nValue As Int32) As Byte()
  47.             Return BitConverter.GetBytes(nValue)
  48.         End Function
  49.  
  50.         Public Function [Int64](ByVal lpValue() As Byte) As Int64
  51.             Return BitConverter.ToInt64(lpValue, 0)
  52.         End Function
  53.  
  54.         Public Function [Int64](ByVal nValue As Int64) As Byte()
  55.             Return BitConverter.GetBytes(nValue)
  56.         End Function
  57.  
  58.         Public Function [Integer](ByVal lpValue() As Byte) As Integer
  59.             Return [Int32](lpValue)
  60.         End Function
  61.  
  62.         Public Function [Integer](ByVal nValue As Integer) As Byte()
  63.             Return [Int32](nValue)
  64.         End Function
  65.  
  66.         Public Function [Long](ByVal lpValue() As Byte) As Long
  67.             Return [Int64](lpValue)
  68.         End Function
  69.  
  70.         Public Function [Long](ByVal nValue As Long) As Byte()
  71.             Return [Int64](nValue)
  72.         End Function
  73.  
  74.         Public Function [Short](ByVal lpValue() As Byte) As Short
  75.             Return [Int16](lpValue)
  76.         End Function
  77.  
  78.         Public Function [Short](ByVal nValue As Short) As Byte()
  79.             Return [Int16](nValue)
  80.         End Function
  81.  
  82.         Public Function [Single](ByVal lpValue() As Byte) As Single
  83.             Return BitConverter.ToSingle(lpValue, 0)
  84.         End Function
  85.  
  86.         Public Function [Single](ByVal flValue As Single) As Byte()
  87.             Return BitConverter.GetBytes(flValue)
  88.         End Function
  89.  
  90.         Public Function [String](ByVal lpValue() As Byte) As String
  91.             Return [ASCII](lpValue)
  92.         End Function
  93.  
  94.         Public Function [String](ByVal strValue As String) As Byte()
  95.             Return [ASCII](strValue)
  96.         End Function
  97.  
  98.         Public Function [ASCII](ByVal lpValue() As Byte) As String
  99.             Return Text.Encoding.ASCII.GetString(lpValue)
  100.         End Function
  101.  
  102.         Public Function [ASCII](ByVal strValue As String) As Byte()
  103.             Dim lpValue() As Byte = Text.Encoding.ASCII.GetBytes(strValue)
  104.             ReDim Preserve lpValue(Text.Encoding.ASCII.GetBytes(strValue).Length)
  105.             Return lpValue
  106.         End Function
  107.  
  108.         Public Function [Unicode](ByVal lpValue() As Byte) As String
  109.             Return Text.Encoding.Unicode.GetString(lpValue)
  110.         End Function
  111.  
  112.         Public Function [Unicode](ByVal strValue As String) As Byte()
  113.             Dim lpValue() As Byte = Text.Encoding.Unicode.GetBytes(strValue)
  114.             ReDim Preserve lpValue(Text.Encoding.Unicode.GetBytes(strValue).Length)
  115.             Return lpValue
  116.         End Function
  117.  
  118.         Public Function [UInt16](ByVal lpValue() As Byte) As UInt16
  119.             Return BitConverter.ToUInt16(lpValue, 0)
  120.         End Function
  121.  
  122.         Public Function [UInt16](ByVal dwValue As UInt16) As Byte()
  123.             Return BitConverter.GetBytes(dwValue)
  124.         End Function
  125.  
  126.         Public Function [UInt32](ByVal lpValue() As Byte) As UInt32
  127.             Return BitConverter.ToUInt32(lpValue, 0)
  128.         End Function
  129.  
  130.         Public Function [UInt32](ByVal dwValue As UInt32) As Byte()
  131.             Return BitConverter.GetBytes(dwValue)
  132.         End Function
  133.  
  134.         Public Function [UInt64](ByVal lpValue() As Byte) As UInt64
  135.             Return BitConverter.ToUInt64(lpValue, 0)
  136.         End Function
  137.  
  138.         Public Function [UInt64](ByVal dwValue As UInt64) As Byte()
  139.             Return BitConverter.GetBytes(dwValue)
  140.         End Function
  141.  
  142.         Public Function [UInteger](ByVal lpValue() As Byte) As UInteger
  143.             Return [UInt32](lpValue)
  144.         End Function
  145.  
  146.         Public Function [UInteger](ByVal dwValue As UInteger) As Byte()
  147.             Return [UInt32](dwValue)
  148.         End Function
  149.  
  150.         Public Function [ULong](ByVal lpValue() As Byte) As ULong
  151.             Return [UInt64](lpValue)
  152.         End Function
  153.  
  154.         Public Function [ULong](ByVal dwValue As ULong) As Byte()
  155.             Return [UInt64](dwValue)
  156.         End Function
  157.  
  158.         Public Function [UShort](ByVal lpValue() As Byte) As UShort
  159.             Return [UInt16](lpValue)
  160.         End Function
  161.  
  162.         Public Function [UShort](ByVal dwValue As UShort) As Byte()
  163.             Return [UInt16](dwValue)
  164.         End Function
  165. #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement