Skip to content

Instantly share code, notes, and snippets.

@taka2
Created October 7, 2011 08:54
Show Gist options
  • Select an option

  • Save taka2/1269817 to your computer and use it in GitHub Desktop.

Select an option

Save taka2/1269817 to your computer and use it in GitHub Desktop.
1次元のJScript配列を、1次元のSafeArrayに変換するサンプル
<?xml version="1.0" encoding="Shift_JIS" ?>
<package>
<job>
<script language="VBScript"><![CDATA[
' 1次元のJScript配列を、1次元のSafeArrayに変換する関数
Function convertToSafeArray(jsArray)
Dim length, result(), elem, i
length = jsArray.length
ReDim result(length-1)
For i=1 to length
elem = jsArray.shift()
result(i-1) = elem
Next
convertToSafeArray = result
End Function
]]></script>
<script language="JScript"><![CDATA[
// 1次元のJScript配列
var arr = [1,3,6];
// SafeArrayに変換
var safeArray = convertToSafeArray(arr);
printVBArray(new VBArray(safeArray));
// デバッグ用:VBArrayを表示
function printVBArray(vbArray) {
for(var i=0; i<=vbArray.ubound(1); i++) {
WScript.Echo("vbArray[" + i + "] = " + vbArray.getItem(i));
}
}
]]></script>
</job>
</package>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment