'-------------------------------------------------------------------------------
'コメントの追加
'
' CopyRight Naoshi Ide 2015-
'-------------------------------------------------------------------------------
Call Main
Sub Main()
Dim buffer, texts
SuffixStr = InputBox("行末に追加するコメントを記入してください", "memo")
If SuffixStr = "" Then
Exit Sub
End If
'選択したテキストを取得する
buffer = Editor.GetSelectedString()
texts = Split(buffer, vbCrLf)
'行ごとに処理を行う
For Each line in texts
tmpBuffer = SetPrefix("//", line)
tmpBuffer = SetBlank(tmpBuffer, 78)
tmpBuffer = SetSuffix(tmpBuffer, SuffixStr)
output = output + tmpBuffer + vbCrLf
Next
Editor.InsText(output)
End Sub
Function GetStrWidth(str)
' //半角文字を削除する
Dim re
Set re = new RegExp
re.Pattern = "[\u0001-\u00FF]"
re.Global = True
delHalfWidth = re.Replace(str, "")
strWidth = Len(delHalfWidth) * 2 + Len(str) - Len(delHalfWidth)
GetStrWidth = strWidth
End Function
'末尾が指定桁数になるように空白文字を追加する
Function SetBlank(str, length)
strLen = GetStrWidth(str)
ln = length - strLen
tmpBuffer = str
For Cnt = 0 To ln
tmpBuffer = tmpBuffer + " "
Next
SetBlank = tmpBuffer
End Function
'行頭にコメントを追加する
Function SetPrefix(PrefixStr, str)
SetPrefix = PrefixStr + str
End Function
'末尾に文字列を追加する
Function SetSuffix(line, SuffixStr)
SetSuffix = line + SuffixStr
End Function
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme