Category
Recent Entries
Search
Archive
Navigation
ホーム 戻る サイトマップ
Appeals
にわか日ハムファン友の会
Syndicate
RSS 1.0
Powered
Powered by blosxom 2.1.2

[Access] 半角全角混じりの文字列をぴったり60Byteに揃える

下の例ではmcntDetail(定数),mrst!ItemName(レコードセットから取り出した品名)を60byteまで削るか、60byte以下ならスペースで補完して返す。 固定長テキストの作成時のサンプル。


Dim i       As Long
Dim strTemp As String
Dim str     As String

strTemp = mcntDetail & " " & mrst!ItemName
i = LenB(StrConv(strTemp, vbFromUnicode))
If (i > 60) Then
    Do Until (i <= 60)
        strDetail = Left(strTemp, Len(strTemp) - 1) 'LENで削り、LENBでカウント
        i = LenB(StrConv(strTemp, vbFromUnicode))   '全角文字がLENBで切断されるとNULL文字が発生する
    Loop
End If
i = 60 - LenB(StrConv(strTemp, vbFromUnicode)) '不足分を補完
str = str &strTemp & Space(i)                  'ぴったり60Byteに

Title:

Body:

Version Control:
Password: