Created
October 10, 2011 06:50
-
-
Save honda0510/1274775 to your computer and use it in GitHub Desktop.
【Windows スクリプト コンポーネント】Utilクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Const UTIL_URL = "https://raw.github.com/gist/1274775/Util.wsc" | |
'Const UTIL_URL = "C:\work\Util.wsc" | |
Sub test1() | |
Dim Util As Object | |
Dim list As Variant | |
list = Array("もみじ", "あかね", "きんむぎ") | |
Debug.Print Join(list) | |
' もみじ あかね きんむぎ | |
Set Util = GetObject("script:" & UTIL_URL) | |
list = Util.SortString(list) | |
Debug.Print Join(list) | |
' あかね きんむぎ もみじ | |
End Sub | |
Sub test2() | |
Dim Util As Object | |
Dim list As Variant | |
list = Array(50, 8, 300, 66, 1) | |
Debug.Print Join(list) | |
' 50 8 300 66 1 | |
Set Util = GetObject("script:" & UTIL_URL) | |
list = Util.SortNumber(list) | |
Debug.Print Join(list) | |
' 1 8 50 66 300 | |
End Sub | |
Sub test3() | |
Dim Util As Object | |
Dim uri As String | |
uri = "http://ja.wikipedia.org/wiki/マイクロソフト?q=テスト" | |
Debug.Print uri | |
' http://ja.wikipedia.org/wiki/マイクロソフト?q=テスト | |
Set Util = GetObject("script:" & UTIL_URL) | |
Debug.Print Util.encodeURI(uri) | |
' http://ja.wikipedia.org/wiki/%E3%83%9E%E3%82%A4%E3%82%AF%E3%83%AD%E3%82%BD%E3%83%95%E3%83%88?q=%E3%83%86%E3%82%B9%E3%83%88 | |
Debug.Print Util.encodeURIComponent(uri) | |
' http%3A%2F%2Fja.wikipedia.org%2Fwiki%2F%E3%83%9E%E3%82%A4%E3%82%AF%E3%83%AD%E3%82%BD%E3%83%95%E3%83%88%3Fq%3D%E3%83%86%E3%82%B9%E3%83%88 | |
End Sub | |
Sub test4() | |
Dim Util As Object | |
Set Util = GetObject("script:" & UTIL_URL) | |
Debug.Print Util.leftShift(14, 2) | |
' 56 | |
Debug.Print Util.rightShift(-14, 2) | |
' -4 | |
Debug.Print Util.rightShiftUnsigned(-14, 2) | |
' 1073741820 | |
End Sub | |
Sub test5() | |
Dim Util As Object | |
Dim a() As Variant | |
Dim b(3) As Variant | |
Set Util = GetObject("script:" & UTIL_URL) | |
Debug.Print Util.arrayLength(a) | |
' 0 | |
Debug.Print Util.arrayLength(b) | |
' 4 | |
End Sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub loadTime() | |
Dim startTime As Single | |
startTime = Timer | |
GetObject "script:" & UTIL_URL | |
Debug.Print Timer - startTime | |
End Sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Const UTIL_URL = "https://raw.github.com/gist/1274775/Util.wsc" | |
'Const UTIL_URL = "C:\work\Util.wsc" | |
Sub test1() | |
list = array("もみじ", "あかね", "きんむぎ") | |
WScript.Echo Join(list) | |
' もみじ あかね きんむぎ | |
Set Util = GetObject("script:" & UTIL_URL) | |
list = Util.SortString(list) | |
WScript.Echo Join(list) | |
' あかね きんむぎ もみじ | |
End Sub | |
Sub test2() | |
list = array(50, 8 ,300, 66, 1) | |
WScript.Echo Join(list) | |
' 50 8 300 66 1 | |
Set Util = GetObject("script:" & UTIL_URL) | |
list = Util.SortNumber(list) | |
WScript.Echo Join(list) | |
' 1 8 50 66 300 | |
End Sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<?component error="false" debug="false"?> | |
<package> | |
<component id="Util"> | |
<public> | |
<method name="SortString"> | |
<parameter name="a" /> | |
</method> | |
<method name="SortNumber"> | |
<parameter name="a" /> | |
</method> | |
<method name="encodeURI" internalName="_encodeURI"> | |
<parameter name="uri" /> | |
</method> | |
<method name="encodeURIComponent" internalName="_encodeURIComponent"> | |
<parameter name="uri" /> | |
</method> | |
<method name="leftShift"> | |
<parameter name="value" /> | |
<parameter name="bitNum" /> | |
</method> | |
<method name="rightShift"> | |
<parameter name="value" /> | |
<parameter name="bitNum" /> | |
</method> | |
<method name="rightShiftUnsigned"> | |
<parameter name="value" /> | |
<parameter name="bitNum" /> | |
</method> | |
<method name="arrayLength"> | |
<parameter name="a" /> | |
</method> | |
</public> | |
<implements type="Behavior" id="Behavior" /> | |
<script language="JScript"> | |
<![CDATA[ | |
function SortNumber(a) { | |
a = a.toArray(); | |
a.sort(function (x, y){ return x - y; }); | |
return jsArray2vbArray(a); | |
} | |
function SortString(a) { | |
a = a.toArray(); | |
a.sort(); | |
return jsArray2vbArray(a); | |
} | |
function _encodeURI(uri) { | |
return encodeURI(uri); | |
} | |
function _encodeURIComponent(uri) { | |
return encodeURIComponent(uri); | |
} | |
function jsArray2vbArray(a) { | |
var dic = new ActiveXObject('Scripting.Dictionary'); | |
for ( var i = 0, n = a.length; i < n; i++ ) { | |
dic.Add(i, a[i]); | |
} | |
return dic.Items(); | |
} | |
function leftShift(value, bitNum) { | |
return value << bitNum; | |
} | |
function rightShift(value, bitNum) { | |
return value >> bitNum; | |
} | |
function rightShiftUnsigned(value, bitNum) { | |
return value >>> bitNum; | |
} | |
function arrayLength(a) { | |
a = a.toArray(); | |
return a.length; | |
} | |
]]> | |
</script> | |
</component> | |
</package> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment