| 禁則処理 |
|
対象バージョン : 97, 2000, 2002, 2003
最終更新日 : 2005/04/25 (オリジナル作成日:1996/12/15)
概 要
指定したバイト数で、禁則文字を考慮しながら
CR+LF (&H0D & &H0A) を挿入するユーザー定義関数です。
構 文
Kinsoku(String, Length)
解 説
Kinsoku 関数の戻り値は文字列型 (String)です。
Kinsoku 関数では次の引数を使用します。
| 引 数 | 内 容 |
|---|---|
| String | 禁則処理を行う文字列式です。 |
| Length | CR+LF を挿入するバイト数を指定します。 |
ユーザー定義関数
(宣言)
Option Compare Binary
Option Explicit
Function Kinsoku(Arg_String, Arg_ColLimit As Integer) As String
Dim OStr As String, SChr As String
Dim Pos As Long, ColCnt As Integer, LvlCnt As Integer, ChrBytes As Integer
' 禁則処理を行うレベル
Const Kinsoku_Level = 2
' 行頭禁則文字
Const Gyoto_Kinsoku = "、。,.?!)〕]}〉》」』】、。,.?!)]}」゙゚"
' 行末禁則文字
Const Gyomatsu_Kinsoku = "(〔[{〈《「『【([{「"
If IsNull(Arg_String) Or Arg_String = "" Then Exit Function
If Arg_ColLimit < 10 Or Arg_ColLimit > 200 Then ' 適当に変えて下さい
Beep
MsgBox "バイト数の指定が不正です。", vbOKOnly + vbExclamation
Exit Function
End If
ColCnt = 0
For Pos = 1 To Len(Arg_String)
SChr = Mid(Arg_String, Pos, 1)
ChrBytes = LenB(StrConv(SChr, vbFromUnicode))
If SChr = vbCr Then
OStr = OStr & SChr
ElseIf SChr = vbLf Then
OStr = OStr & SChr
ColCnt = 0
LvlCnt = 0
ElseIf ColCnt + ChrBytes > Arg_ColLimit Then
If InStr(Gyoto_Kinsoku, SChr) <> 0 Then
If LvlCnt >= Kinsoku_Level Then
OStr = OStr & vbCrLf & SChr
ColCnt = ChrBytes
LvlCnt = 0
Else
OStr = OStr & SChr
ColCnt = ColCnt + ChrBytes
LvlCnt = LvlCnt + 1
End If
Else
OStr = OStr & vbCrLf & SChr
ColCnt = ChrBytes
LvlCnt = 0
End If
ElseIf ColCnt >= Arg_ColLimit - Kinsoku_Level * 2 Then
If InStr(Gyomatsu_Kinsoku, SChr) <> 0 Then
OStr = OStr & vbCrLf & SChr
ColCnt = ChrBytes
Else
OStr = OStr & SChr
ColCnt = ColCnt + ChrBytes
End If
Else
OStr = OStr & SChr
ColCnt = ColCnt + ChrBytes
End If
Next
Kinsoku = OStr
End Function
補 足
改訂履歴