• 残念なことに、半角→全角変換はないようだ。ExcelならJIS関数、strconv関数でいける。Accessもstrconv関数で可能。SQLServerは関数なし。

ファイル読み込み

Option Explicit
' On Error Resume Next

call read_by_line("a.txt")

sub read_by_line(file_path)
    Dim objFSO, objFile
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(file_path)

    If Err.Number <> 0 Then
        WScript.Echo "Error" & Err.Description
    End If

    Do While objFile.AtEndOfStream <> True
        WScript.Echo objFile.ReadLine
    Loop
    objFile.Close

    Set objFile = Nothing
    Set objFSO = Nothing
end sub

utf-8の場合、上記では不可能らしい。adoを使う必要あり
http://trwtnb.blogspot.jp/2009/10/vbscriptutf-8.html?m=1

ファイル書き込み

Option Explicit
' On Error Resume Next

call write_file("a.txt", "line aaa 1", 2)
call write_file("a.txt", "line aaa 2", 8)

' open_type : 1=read_only, 2=write_only, 8=append
sub write_file(ByVal file_path, ByVal line, ByVal open_type)
    Dim objFSO, objFile
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(file_path, open_type, TRUE)

    If Err.Number <> 0 Then
        WScript.Echo "Error" & Err.Description
    End If

    objFile.WriteLine line
    If Err.Number <> 0 Then
        WScript.Echo "Error in writing" & Err.Description
    End If

    objFile.Close

    Set objFile = Nothing
    Set objFSO = Nothing
end sub

正規表現置換

Option Explicit
' https://msdn.microsoft.com/ja-jp/library/cc392403.aspx

Wscript.Echo my_rep("aaa,1.ABC,ccc")
Wscript.Echo my_rep("aaa,1.xyz,ccc")
Wscript.Echo my_rep("aaa,1.xYz,ccc")
Wscript.Echo my_rep("aaa,1.00,ccc")
Wscript.Echo my_rep("aaa,2.ABC,ccc")
Wscript.Echo my_rep("aaa,3.ABC,ccc")
Wscript.Echo my_rep("aaa,4.ABC,ccc")

Function my_rep(ByVal strRepBefore)
    Dim objRegExp, strRepAfter
    Set objRegExp = New RegExp
    objRegExp.Pattern = "(,[1-4]).[A-Za-z0-9]+,"
    my_rep = objRegExp.Replace(strRepBefore, "$1,")
    Set objRegExp = Nothing
end Function

INPUT box

Option Explicit
' https://msdn.microsoft.com/ja-jp/library/cc410238.aspx

Dim str_txt
str_txt = Inputbox("please input message")

if str_txt = "" then
    Wscript.Echo "message is not entered or canceled"
    Wscript.Quit
end if

Wscript.Echo "You input this message : " & str_txt

配列

 Option Explicit

 Dim arr, v
 arr = Array(1,2,3)

 For Each v in arr
     WScript.Echo v
 Next

ユニークにする (Windows PowerShell)

get-content D:\a.txt | sort-object | get-unique > D:\b.txt

– https://technet.microsoft.com/ja-jp/library/ee176859.aspx
– https://gallery.technet.microsoft.com/scriptcenter/fe809794-5e4c-498d-83a6-4832f3d9160b

その他

  • 三項演算子が存在しない
  • JavaのImport / PHPのinclude に当たるものがない

参考

  • http://qiita.com/honeniq/items/88462b12d2244480026a
  • https://msdn.microsoft.com/ja-jp/library/cc392207.aspx