« [VB6.0] 配列のソート | メイン | [VB6.0] Excelの操作 »

2005年08月11日

[VB6.0] 文字列バイトチェック

'-----------------------------------------------------------
' ■ 文字列バイトチェック ■
'
' 動作:
' テキストが指定バイト数以下かチェック
'
' 引数:
' CheckText   = チェックしたいテキスト
' CheckType   = チェックタイプ
' ByteNum     = バイト数
'  blnByte     = False(指定バイト以下)、True(指定外)
'
'   * CheckType
'    1 = 全角文字
'    2 = 半角英数
'    3 = 全半角混在
'    4 = 半角数字
'
'-----------------------------------------------------------

Private Function TextByteCheck( _
ByVal CheckText As String, _
ByVal CheckType As Integer, _
ByVal ByteNum As Integer, _
ByRef blnByte As Boolean)

Select Case CheckType
Case 1 '全角文字
If LenB(StrConv(CheckText, vbFromUnicode)) <= ByteNum _
And Len(CheckText) * 2 = LenB(StrConv(CheckText, vbFromUnicode)) Then
blnByte = False
Else
blnByte = True
End If
Case 2 '半角英数
If LenB(StrConv(CheckText, vbFromUnicode)) <= ByteNum _
And Len(CheckText) = LenB(StrConv(CheckText, vbFromUnicode)) Then
blnByte = False
Else
blnByte = True
End If
Case 3 '全半角混在
If LenB(StrConv(CheckText, vbFromUnicode)) <= ByteNum Then
blnByte = False
Else
blnByte = True
End If
Case 4 '半角数字
If LenB(StrConv(CheckText, vbFromUnicode)) <= ByteNum _
And IsNumeric(CheckText) Then
blnByte = False
Else
blnByte = True
End If
Case Else
blnByte = True

End Select
End Function

2005 / 08 / 11