'********************************************************************

'*

'* Sub ASCII2UnicodeArray

'*

'*   Author: NetworkAdminKB.com

'*  Created: 2007-01-26

'* Modified: 2007-01-26

'*

'* Purpose: Convert any ASCII string to an unicode array/string (VarType

‘*            = 8204). A unicode array/string is where each ASCII character

‘*            is represented by two values (the ascii char value, and 0).

'*            The unicode "string" also ends in two zeros (0).

'*

'* Input:   strAny = The string to convert to the unicode array

'*

'* Return:  An array of unicode character values (VarType = 8204).

'*

'* Example: ASCII2UnicodeArray("IT") = Array(73, 0, 84, 0, 0, 0)

'*            where 73,00=I and 84,00=T and 0,0 are the ending zeros.

'*

'* Notes: This procedure is can be used with the SetBinaryValue Method

'*          of the StdRegProv Class in WMI write to the Registry.

'*

'********************************************************************

Function ASCII2UnicodeArray(ByVal strAny)

  'Version: 1.0 2007-01-26

  Dim iIndex, iPos

 

  ReDim aryBytes(Len(strAny) * 2 + 1)

 

  iIndex = -1

  For iPos = 1 To Len(strAny)

    iIndex = iIndex + 1

    aryBytes(iIndex) = Asc(Mid(strAny, iPos, 1))

    ' add a 0 after each letter

    iIndex = iIndex + 1

    aryBytes(iIndex) = 0

  Next 'iPos

 

  ' add two closing 0's

  iIndex = iIndex + 1

  aryBytes(iIndex) = 0

  iIndex = iIndex + 1

  aryBytes(iIndex) = 0

 

  ASCII2UnicodeArray = aryBytes

End Function 'ASCII2UnicodeArray

 

Article ID: 307, Created On: 9/19/2011, Modified: 9/19/2011