(for Internet Explorer)
Sub  Txt2BinTxt( SrcPath as string, DstPath as string )
(src)
参考
Function  get_ADODBConsts() as ADODBConsts
ADODB モジュールの定数をメンバーに持つオブジェクトを返します。
ADODBConsts が定義する定数
adReadAll, adTypeBinary, adTypeText
adModeRead, adModeWrite, adModeReadWrite
adSaveCreateOverWrite
adCRLF, adLF, Keep
サンプル
Dim  c : Set c = get_ADODBConsts()
t = f.Read( c.adReadAll )
(src)
バイト配列を作成する関数
バイト配列と整数の間で変換する関数
関連
ファイル:
System.vbs
Function  ADODBConsts::ConvertToByteArray( ByteArray as variant,
             Offset as integer,  Size as integer ) as array of Byte
文字列や配列や数値を、バイト配列に変換します。
【引数】
ByteArray
Offset
文字列、または配列、または数値
返り値の先頭となる ByteArray の中の位置。先頭=0
Size
ByteArray の中から返り値にするサイズ(バイト)。最後まで=-1
ファイル:
System.vbs
返り値
に渡せる
サンプル
  Dim binary, stream
  Dim c : Set c = get_ADODBConsts()
  binary = c.ConvertToByteArray( Array( &h42, &h4D ), 0, Empty )
  stream.Write  binary
  binary = c.ConvertToByteArray( ChrB( &h42 ) + ChrB( &h4D ), 0, Empty )
  binary = c.ConvertToByteArray( &h4D, 1, Empty )
(src)
→ T_Binary フォルダ
テスト
参考
Function  ADODBConsts::ConvertToStructuredByteArray( FormatAndDataArray as array ) as array of Byte
構造化した配列を、バイト配列に変換します。
【引数】
FormatAndDataArray
バイナリ配列へライトする部分の型とライトする値の集合
返り値
に渡せる
(src)
→ T_Binary フォルダ
テスト
参考
構造化した配列、FormatAndDataArray 引数の説明
Function  ADODBConsts::BytesToShortInt( b0, b1, b2, b3 as integer ) as integer
2バイトのバイナリ・データを、-32768(&h8000)〜32767(&h7FFF) の整数に変換します。
サンプル
c.BytesToShortInt( &hFE, &hFF ) = &hFFFE
(src)
Function  ADODBConsts::BytesToUShortIntToLongInt( b0, b1, b2, b3 as integer ) as integer
2バイトのバイナリ・データを、0〜65535 の整数に変換します。
サンプル
c.BytesToUShortIntToLongInt( &hFE, &hFF ) = 65534
(src)
Function  ADODBConsts::BytesToLongInt( b0, b1, b2, b3 as integer ) as integer
4バイトのバイナリ・データを、Long 型整数に変換します。
サンプル
c.BytesToLongInt( &h78, &h56, &h34, &h12 ) = &h12345678
(src)
Function  ADODBConsts::ShortIntToBytes( Value as integer ) as array of integer
-32768(&h8000)〜32767(&h7FFF) の整数を、2バイトの配列に変換します。
サンプル
c.ShortIntToBytes( &hFEFF ) = Array( &hFF, &hFE )
&h0000〜&h7FFF(Integer型)、&h10000〜 &h7FFFFFFF(Long型) は、正の整数です。
&h8000〜&hFFFF(Integer型)、&h80000000〜(Long型) は、負の整数です。
(src)
Function  ADODBConsts::LongIntToUShortIntToBytes( Value as integer ) as array of integer
0〜65535 の整数を、2バイトの配列に変換します。
サンプル
c.LongIntToUShortIntToBytes( 65534 ) = Array( &hFE, &hFF )
(src)
Function  ADODBConsts::LongIntToBytes( Value as integer ) as array of integer
整数を、4バイトの配列に変換します。
サンプル
c.LongIntToBytes( &h12345678 ) = Array( &h78, &h56, &h34, &h12 )
(src)
CSV 形式の1行を解析して、それぞれの項目を配列に格納します。
Function  ArrayFromCSV( a_CSV as string ) as Array of string
For Each column  In ArrayFromCSV( "ABC , DEF" )
Next
【引数】
a_CSV
返り値
CSV 形式の1行
(出力)CSV の項目が入った配列
関連
各項目の両端の空白が削除されたものが戻ります。
項目の端に空白文字がある場合と、項目の中にコンマやダブルクォーテーション(")が
あるときは、" " で囲んでください。 ただし、ダブルクォーテーション1文字あたり、
ダブルクォーテーションを2つ並べてください。
→ T_CSV.vbs # ArrayFromCSV
テスト
(src)
Function  ArrayFromCSV_Int( a_CSV as string ) as Array of integer
上記 ArrayFromCSV の返り値は、Array( "ABC", "DEF" )
ABC , DEF
A, "  ""ABC,"" "
A
  "ABC,"
CSV:
各項目:
VBS:
ArrayFromCSV( "A, ""  """"ABC,"""" """ )
CSV とは別に、VBS も同様に " 文字は " を2つ並べる
"A,  ,C" の真ん中の要素のように、何も無いときは、配列の要素が Empty になります。
"A, " のように最後がコンマのときは、配列の最後の要素が Empty になります
" " のように、空白文字や空文字列のときは、配列要素数が 0 になります。
ArrayFromCSV( "A,,C" ) = Array( "A", Empty, "C" )
ArrayFromCSV( "A," ) = Array( "A", Empty )
要素に "" (ダブルクオーテーション2つだけ)が指定されたときは、空文字列になります。
ArrayFromCSV( "A, """"" ) = Array( "A", "" )
ArrayFromCSV( " " ) = Array( )
複数行の文字列を指定するときは、最後の行以外の行末を "," にしてください。
ArrayFromCSV( "A, B," +vbCRLF+ "C, D," +vbCRLF+ "E, F" )
 = Array( "A","B","C","D","E","F" )
A, B,
C, D,
E, F
つまり
A, B, C, D, E, F
サンプル
CSV 形式の1項目を取り出し、通常の文字列に戻す。
Function  MeltCSV( Line as string, in_out_Start as integer ) as string
  i = 1
  Do
    s = MeltCSV( line, i )
    If not IsEmpty( s ) Then (s を使った処理)
    If i = 0 Then Exit Do
  Loop
【引数】
Line
in_out_Start
CSV 形式の1行
(入力) 取り出しを開始する文字の位置、(出力)次に取り出す〜
返り値
取り出した CSV 形式の1項目。Empty=項目に値が無い
サンプル
(src)
関連
各項目の両端の空白が削除されたものが戻ります。
次の項目が無いときは、i=0 になります。
i=0 を渡すと、Empty を返します。
→ T_CSV.vbs # main
テスト
Function  CSVText( s as string ) as string
CSV の1項目に変換します。
サンプル
s = CSVText( "a,b" )
s は、"""a,b""" になります
  s = ""
  For Each  t  In Array( "a", "b" )
    If s <> "" Then  s = s + ", "
    s = s + CSVText( t )
  Next
サンプル
CSV の1行を作成します
(src)
Function  LoadXML( PathOrStr as string, Opt as variant ) as IXMLDOMElement
XML ファイル、または XML 形式の文字列を読み込みます。
【引数】
PathOrStr
XML ファイルのパス、または XML 形式文字列
Opt
オプション(下記)
IXMLDOMElement
XML のルート要素
返り値
Opt 引数
F_NoRoot フラグ
XML のルート要素が無い XML を読み込みます。 返り値は、内部で自動的に
加えられたルート要素 <Dummy_Root_> になります。
先頭が < でないときは、自動的にルート要素が加えられます。
F_Str フラグ
PathOrStr 引数を XML 形式文字列として処理します
サンプル: XML 形式文字列を展開する
  Dim  s : s = "ABC <TAG1 attr='value1'/> 123"
  Dim  root : Set root = LoadXML( s, F_NoRoot or F_Str )
  Dim  value : value = root.selectSingleNode( "./TAG1" ).getAttribute( "attr" )
  '//  value = "value1"
関連
LoadXML
  Dim  root, elem, attr

  Set root = LoadXML( "sample.xml", Empty )

  '//=== read 1 attribute value
  WScript.Echo  root.selectSingleNode( "./Tests/Test" ).getAttribute( "result" )

  '//=== read 1 text value
  WScript.Echo  root.selectSingleNode( "./Tests/text()" ).nodeValue

  '//=== loop each tags
  For Each elem  In root.selectNodes( "./Tests/Test" )
    WScript.Echo  "result, "+ elem.getAttribute( "result" )
  Next

  '//=== loop each attributes
  For Each elem  In root.selectNodes( ".//Test" )
    WScript.Echo  "<" + elem.tagName + ">"
    For Each attr  In elem.attributes
      WScript.Echo  attr.name + "=" + attr.value
    Next
  Next
"sample.xml"
"./Tests/Test"
"./Tests/Test"
"result"
"result"
".//Test"
result
→ DOM サンプル
LoadXML
日本語があるときは、Unicode にするか、XML宣言で Shift-JIS を指定してください。
→ XmlFilter ツール (.zip)
テスト
→ T_XML フォルダ
サンプル: XML を結合する
  Dim  f, root, elem, attr

  Set f = OpenForWrite( "FileAB.xml", Empty )
  f.WriteLine  "<TabA>"
  Set root = LoadXML( "FileA.xml", Empty )
  f.WriteLine  XmlTags( root.selectSingleNode( "./TagB" ).xml, 1 )
  Set root = LoadXML( "FileB.xml", Empty )
  f.WriteLine  XmlTags( root.selectSingleNode( "./TagB" ).xml, 1 )
  f.WriteLine  "</TabA>"
→ XML
参考
./Tests/text()
関連
Function  ObjToXML( TagName as string, Objs as object or array, Opt as variant ) as string
オブジェクトの基本的なデータを XML 文字列に変換します。
  s = ObjToXML( Empty, obj, Empty )
サンプル:
【引数】
TagName
ルート・タグ名、Empty にすると、ルートタグを追加しません。
返り値
Objs
XML データの内容にするオブジェクト、またはその配列
Opt
Empty を指定してください
XML 文字列
関連
オブジェクトのクラス名と、Name プロパティ、DefinePath プロパティから XML データを作成します。
他のプロパティも含んだ XML データは、xml プロパティを作成してください。
(src)
→ SetDefinePath
Function  XmlAttr( s as string ) as string
" " で囲む XML の属性値に変換します。
サンプル:
s = XmlAttr( "<""'" )
s は、"&lt;&quot;'" になります
(src)
関連
(src)
s は、"&lt;""&apos;" になります
s = XmlAttrA( "<""'" )
サンプル:
' ' で囲む XML の属性値に変換します。
Function  XmlAttrA( s as string ) as string
→ T_XML.vbs # [T_XmlText]
テスト
→ StrT_changeToXmlAttr (clib)
Function  XmlText( s as string ) as string
XML のテキスト(タグの外)に変換します。
Assert  XmlText( "<""" ) = "&lt;"""
(src)
関連
→ T_XML.vbs # [T_XmlText]
テスト
サンプル
関連
Function  OpenForReplaceXML( SrcPath as string, DstPath as string ) as ReplaceXmlFile1
XMLファイルの内容の変更を開始します。
【引数】
SrcPath
DstPath
変更前のテキストファイルのパス
変更後のテキストファイルのパス。 SrcPath と同じ、または Empty 可。
vbslib.vbs
モジュール・シンボル:
返り値
  Set  xml = OpenForReplaceXML( "file1.xml", Empty )
  xml.Write  "/Root/Elem/@attr1", 11
  xml.IsUserConfirm = True
  xml = Empty  '// デストラクタでユーザーの確認およびファイルの更新をする
file1.xml
/Root/Elem/@attr1
11
テスト
→ T_XML.vbs # [T_OpenForReplaceXML]
(src)
タグの間のテキスト、または XML 属性の値を変更します。
XML ファイルを変更する前に、ユーザーに確認をとるかどうか。
→ T_XML_Manually.vbs # [T_OpenForReplaceXML_Manually]
Sub  ReplaceXmlFile1::Write( XPath as string, Value as string )
XML のタグの間のテキスト、または XML の属性の値を変更します。
【引数】
XPath
タグの間のテキスト、または XML の属性の位置を表す XPath
返り値
変化があったかどうか
変更後のテキストまたは XML 属性の値、""=値なし、Empty=削除する
Value
参考
Sub  ReplaceXmlFile1::SetXmlAttribute( XPathForXmlElement as string, AttrName as string,
                                       AttrValue as string );
XML 属性の値を変更します。
【引数】
XPathForXmlElement
AttrName
属性を変更する XML 要素(タグ) への XPath。 絶対パス
XML 属性の名前
AttrValue
変更後の XML 属性の値
廃止されました。
Dim  ReplaceXmlFile1::IsUserConfirm as boolean
XML ファイルを変更する前に、ユーザーに確認をとるかどうかの設定値。
XML ファイルを更新する直前で、値が変わる属性とその値を表示します。
表示中に、ユーザーの確認入力があるまで待ちます。
デフォルトは、False です。
/Root/Tests/Test1@attr1="1"
/Root/Tests/Test3@attr1="3"
更新ファイル:out.xml
XML ファイルの上記属性を変更します。
続行するには Enter キーを押してください . . .
確認画面の例:
Function  OpenForAppendXml( SrcPath as string, DstPath as string ) as AppendXmlFile
XMLファイルの内容の追加を開始します。
【引数】
返り値を使って呼び出せるメソッドは、FileSystemObject::OpenTextFile と同じですが、
いくつかメソッドが追加されています。
Modify.xml (処理前)
Modify.xml (処理後)
<Modify>
<Child1 value="1"/>
</Modify>
クローズするときに、ルートの XML タグ(XML要素)を閉じるタグを出力します。
よって、追加する内容は、ルートの XML タグの直下の末尾に限定されます。
Dim  file : Set file = OpenForAppendXml( "Modify.xml", Empty )
file.WriteLine  "<Child2 value=""2""/> <!-- by WriteLine -->"
file.WriteXml  ReadFile( "Add.xml" )
file = Empty
サンプル
<Modify>
<Child1 value="1"/>
<Child2 value="2"/> <!-- by WriteLine -->
<AddChild value="3"/>
</Modify>
<Add>
<AddChild value="3"/>
</Add>
Add.xml
追加する内容は、OpenForWrite と同様に WriteLine などのメソッドに XML の文字列を
指定します。 XPath ではありません。
テスト
→ T_XML.vbs # [T_OpenForAppendXml]
SrcPath
DstPath
変更前のテキストファイルのパス
変更後のテキストファイルのパス。 SrcPath と同じ、または Empty 可。
返り値
TextStream + α のオブジェクト
(src)
Sub  AppendXmlFile::WriteXml( Xml as string )
指定した XML 文字列から、ルート XML タグを除いて追加します。
【引数】
Xml
追加する XML 文字列
file.WriteXml  "<Root><Child/><Root>"
サンプル
サンプル
OpenForAppendXml( "Modify.xml", Empty ).WriteXml  ReadFile( "Add.xml" )
<Child/> を追加します
Modify.xml に Add.xml を追加します。
Modify.xml (処理前)
Modify.xml (処理後)
<Modify>
<Child1 value="1"/>
</Modify>
<Modify>
<Child1 value="1"/>
<AddChild value="2"/>
</Modify>
<Add>
<AddChild value="2"/>
</Add>
Add.xml
(src)
Function  XmlWrite( BaseXmlElement as IXMLDOMElement, XPath as string, Value as string ) as boolean
XML のタグの間のテキスト、または XML の属性の値を変更します。
【引数】
BaseXmlElement
XPath
XPath の基準となる XML要素(タグ)
タグの間のテキスト、または XML の属性の位置を表す XPath
返り値
変化があったかどうか
(src)
変更後のテキストまたは XML 属性の値、""=値なし、Empty=削除する
Value
タグの間のテキストは、厳密には XPath = "/Root/Elem/text()" ですが、XPath = "/Root/Elem" を指定
してください。

XPath に指定したタグ(XML要素)が存在しないときは、作成します。

XPath = "/Root/Elem" (XML要素へのパス)のとき、Value = "" なら、<Elem/> となります。
XPath = "/Root/Elem" (XML要素へのパス)のとき、Value = Empty なら、<Elem/> を削除します。
XPath = "/Root/Elem/@attr" (XML属性へのパス)のとき、Value = "" なら、<Elem attr=""/> となります。
XPath = "/Root/Elem/@attr" (XML属性へのパス)のとき、Value = Empty なら、<Elem/> となります。
サンプル
→ setAttribute (IXMLDOMElement)
参考
  Dim  b, is_change
  Dim  root : Set root = LoadXML( "in.xml", Empty ) '// as IXMLDOMElement
  b= XmlWrite( root, "./Tag1/@attr1", 123 )
  is_change = is_change or b
  If is_change Then  root.ownerDocument.save  "out.xml"
123
Tag1/@attr1
XmlWrite
テスト
→ T_XML.vbs # T_XmlWrite
関連