SLEEP function
Option Explicit
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub sleepp(Optional time_tmp As Long = 1000)
Sleep time_tmp ' Pause for 1 second (1000 milliseconds)
End Sub
[Open path1 For Input As #1] can only write save file in sjis
CreateObject(“ADODB.Stream”) can save file in sjis/utf8/utf8bom
logic of function replace_str_file:
- open file in utf8
- set position 0,read content to buffer
- reopen the file, otherwise u cannot write
- edit content,then write the file,contents of the file will all delete before writing
- if the file has bom, remove the comment from ここから to ここまで ,it will remove bom
'sjis or utf8
Function replace_str_file(ByVal path1, ByVal find As String, ByVal replace_str As String)
Dim buffer As String, stream_tmp
Set stream_tmp = CreateObject("ADODB.Stream")
With stream_tmp
' ストリームの文字コードをUTF8に設定する
.Charset = "UTF-8"
' ファイルのタイプ(1:バイナリ 2:テキスト)
.Type = 2
' ストリームを開く
.Open
' ストリームにファイルを読み込む
.LoadFromFile (path1)
.Position = 0
' ファイルの中身をbufferへ代入
buffer = .ReadText
' ストリームを閉じる
.Close
.Open
buffer = replace(buffer, find, replace_str)
' ストリームの保存形式をテキスト形式にする
.WriteText buffer
' ---------- ここから ----------
' タイプをバイナリにして、先頭の3バイトをスキップ
.Position = 0
.Type = 1 ' タイプ変更するにはPosition = 0である必要がある
.Position = 3
' 一時格納用
Dim p_byteData() As Byte
p_byteData = .Read
.Close ' 一旦閉じて
.Open ' 再度開いて
.Write p_byteData ' ストリームに書き込む
' ---------- ここまで を追加 ----------
' ストリームに名前を付けて保存する(1は新規作成 2は上書き保存)
.SaveToFile (path1), 2
.Close
End With
Set stream_tmp = Nothing
End Function
'sjis
Function replace_str_file_sjis(ByVal path1, ByVal find As String, ByVal replace_str As String)
Dim text, text_line As String
Open path1 For Input As #1
Do While Not EOF(1)
Line Input #1, text_line
If text = "" Then
text = text_line
Else
text = text & vbLf & text_line
End If
Loop
Close #1
text = replace(text, find, replace_str)
text = replace(text, ChrW(&HFEFF), "")
Open path1 For Output As #1
Print #1, text
Close #1
End Function
how to save text file in utf8 and by LF
if using sakura editor,ctrl+shifl+s,set as below
what file format is needed in linux
- LF+UTF8 is ok
- if CRLF ,it will raise error if u executethe file(ep. . TT.sh)
- if sjis,it will output 文字化け,but can be executed