- 日時: 2009/12/27 15:32
- 名前: 花ちゃん
 
   -  ***********************************************************************************
  * カテゴリー:[応用コード][文字列処理][]                                        *  * キーワード:構造体,型変換,ユーザ定義型,Byte型,,                                 *  ***********************************************************************************
  始めまして、はらだと申します。(同じ悩みを抱えてました。) こういう方法があります。ご参考まで。 #ただし、LSetのVBリファレンスには #「予期せぬ結果があるかも…」と記述されていました。
  Type Rec1      B1(3) As Byte '"1234"      B2(5) As Byte '"あいう"      B3(3) As Byte '"えお" End Type Type RecB      B0(255) As Byte End Type
  Declare Sub MoveMem Lib "kernel32" Alias "RtlMoveMemory" _  (pDest As Any, pSource As Any, ByVal ByteLen As Long)
  Function LeftSet()     Dim LC_C   As String     Dim LC_X() As Byte     Dim LC_1   As Rec1     Dim LC_1L  As Long     Dim LC_B   As RecB     Dim LC_2() As Byte          ReDim LC_X(LenB(StrConv(LC_C, vbFromUnicode)))     LC_1L = LenB(LC_1)     ReDim LC_2(LC_1L)     Erase LC_2()          '文字列→ユーザー定義型     LC_C = "1234あいうえお"     LC_X = StrConv(LC_C, vbFromUnicode)     MoveMem LC_1, LC_X(0), LenB(StrConv(LC_C, vbFromUnicode))     Debug.Print StrConv(LC_1.B1, vbUnicode)     Debug.Print StrConv(LC_1.B2, vbUnicode)     Debug.Print StrConv(LC_1.B3, vbUnicode)     'ユーザー定義型→バイト型配列     LSet LC_B = LC_1     LC_2 = LeftB(LC_B.B0, LC_1L)     Debug.Print StrConv(LC_2, vbUnicode) End Function
  
 
  |