ActivePointX = document.selection.GetActivePointX(eePosView)
ActivePointY = document.selection.GetActivePointY(eePosView)
AnchorPointX = document.selection.GetAnchorPointX(eePosView)
AnchorPointY = document.selection.GetAnchorPointY(eePosView)
'選択範囲の端点とカーソル位置のどちらが小さい(左上)か
bGreater = document.selection.IsActiveEndGreater
document.selection.text = UrlEncode(document.selection.text)
if bGreater then
document.selection.SetAnchorPoint eePosView, AnchorPointX, AnchorPointY
else
document.selection.SetAnchorPoint eePosView, ActivePointX, ActivePointY
end if
Function UrlEncode(strSource)
Dim lngSourceSize 'strSource の文字数
Dim strArray() '変換された文字列を格納する配列
Dim strSingle '抜き出された 1 文字を格納する変数
Dim i 'ループカウンタ
Dim intAsc '文字コード
Dim strHex '16 進数に変換した文字コード
Dim lngHexLength 'strHex の文字数
Dim lngCount 'strArray の格納位置
lngSourceSize = Len(strSource)
If lngSourceSize = 0 Then Exit Function
ReDim strArray(lngSourceSize * 6 - 1) 'strArray() のサイズを予約。文字数 * 6 にしておく。
For i = 1 To lngSourceSize Step 1 '引数 strSource の文字数分ループをまわす
strSingle = Mid(strSource, i, 1) 'i 文字目の 1 文字を strSource から抜き出す
intAsc = Asc(strSingle) '文字コードを取得
If intAsc = &H20 Then '文字が半角空白文字の場合
strArray(lngCount) = "+" '"+" を代わりに入れる
ElseIf (intAsc >= &H40 And intAsc <= &H5A) Or _
(intAsc >= &H61 And intAsc <= &H7A) Or _
(intAsc >= &H30 And intAsc <= &H39) Or _
intAsc = &H2A Or intAsc = &H2D Or _
intAsc = &H2E Or intAsc = &H5F Then '無変換文字だった場合
strArray(lngCount) = strSingle
Else
strArray(lngCount) = "%"
strHex = Hex(intAsc) '16 進文字コードを取得する
lngHexLength = Len(strHex)
If lngHexLength = 4 Then '2 バイト文字の場合
strArray(lngCount + 1) = Left(strHex, 2)
strArray(lngCount + 2) = "%"
strArray(lngCount + 3) = Right(strHex, 2)
lngCount = lngCount + 3
ElseIf lngHexLength = 2 Then '1 バイト文字の場合
strArray(lngCount + 1) = strHex
lngCount = lngCount + 1
Else
strArray(lngCount + 1) = "0"
strArray(lngCount + 2) = strHex
lngCount = lngCount + 2
End If
End If
lngCount = lngCount + 1
Next
ReDim Preserve strArray(lngCount - 1)
UrlEncode = Join(strArray, "") 'URL エンコードした文字列を返す
End Function
カーソルで選択した範囲の文字列をURLエンコードする。
URLデコードはまだ開発中。
