vbtitle.jpg (10060 bytes)



Conversions Submitted By
  Byte Array <-> String Danny
  Integer <-> 2 byte String Danny
  Long <-> 4 byte String Danny
  Single <-> 4 byte String Danny
  Double <-> 8 byte String Danny
  Convert Big-Endian & Little-Endian Values Danny
  ASCII formatted Hex to it's Value Danny
  String to Upper-Case / Lower-Case / Proper Case Danny

 

API Declarations

  
Some of these functions will require these API Declarations...

'Toggles Endian for Long
Declare Function ntohl Lib "wsock32.dll" _
       ( ByVal a As Long) As Long

'Toggles Endian for Integer
Declare Function ntohs Lib "wsock32.dll" _
       (ByVal a As Long) As Integer

'memory manipulation
Declare Sub CopyMemory Lib "kernel32" Alias _
        "RtlMoveMemory" ( _
         hpvDest As Any, _
         hpvSource As Any, _
         ByVal cbCopy As Long)


  


back to top

Byte Array  <-> String

  

'string to byte array using StrConv
bArray = StrConv(Text, vbFromUnicode)

'byte array to string using StrConv
Text = StrConv(bArray, vbUnicode)

'string to byte array using CopyMemory API*
Call CopyMemory (bArray(0), ByVal Text, lText)

'byte array to string using CopyMemory API*
Call CopyMemory (ByVal Text, bArray(0), lText)

   

I prefer the CopyMemory but its up to you...
   
  

back to top

Integer  <-> 2 Byte String

  

'2 byte string to integer using CopyMemory API*
Call CopyMemory (iNum, ByVal Text, 2)

'integer to 2 byte string using CopyMemory API*
Call CopyMemory (ByVal Text, iNum, 2)

  

   
  

back to top

Long  <-> 4 Byte String

  

'4 byte string to Long using CopyMemory API*
Call CopyMemory (lNum, ByVal Text, 4)

'Long to 4 byte string using CopyMemory API*
Call CopyMemory (ByVal Text, lNum, 4)

  

   
  

back to top

Single  <-> 4 Byte String

  

'4 byte string to Single using CopyMemory API*
Call CopyMemory (sngNum, ByVal Text, 4)

'Single to 4 byte string using CopyMemory API*
Call CopyMemory (ByVal Text, sngNum, 4)

  

   
  

back to top

Double  <-> 8 Byte String

  

'8 byte string to Double using CopyMemory API*
Call CopyMemory (dblNum, ByVal Text, 8)

'Double to 8 byte string using CopyMemory API*
Call CopyMemory (ByVal Text, dblNum, 8)

  

   
  

back to top

Little-Endian <-> Big-Endian 

  

'toggles long value's Endian ntohl API*
lNum
= ntohl(lNum)

'toggles integer value's Endian ntohs API*
iNum
= ntohs(iNum)

   
  

back to top

ASCII Formatted Hex to it's Value

  
iHexVal = Val("&H" & strHex)
  

  
   Example:
  

Dim strHex As String : strHex = "e3b"
Dim iHexVal As Long

iHexVal = Val("&H" & strHex)

Print.iHexVal   'prints 3643

 

back to top

String to Upper-Case / Lower-Case / Proper-Case

  
strText = StrConv(strText, vbUpperCase)
strText = StrConv(strText, vbLowerCase)
strText = StrConv(strText, vbProperCase)
  

  
   Example:
  

Dim strText As String: strText = "rIgHt oN"

strText = StrConv(strText, vbProperCase)

Print.strText   'prints 'Right On'

 

back to top