Reputation: 1
I have a Unicode TXT file and I want do replace some parts with a numbering. But it failed with following reason:
Line: 24
Character: 1
Code: 800A0005
Here my VBS file:
Ein = "D:\aaa\column.txt"
Aus = "D:\aaa\column-final.txt"
'Suchbegriff im RegEx-Format, daher: Punkt maskieren und zu ersetzenden Teil (=Nummer) in Klammern setzen
Such = "<TD>(XXXXX)</TD>"
N = 1 'Startwert für neue Nummerierung
Set fso = CreateObject("Scripting.FileSystemObject")
T1 = fso.OpenTextFile(Ein).ReadAll
Set rE = New RegExp
rE.Pattern = Such
rE.IgnoreCase = True
rE.Global = True
SP = 1 'Startposition im String
For Each M In rE.Execute(T1)
P = M.FirstIndex + M.Length + 1 'Endposition des die Fundstelle enthaltenden Teilstrings
'im gefundenen Teilstring (des Originaltextes) die bisherige Nummer ersetzen und zum neuen Text hinzufügen
T2 = T2 & Replace(Mid(T1, SP, P - SP), M.SubMatches(0), N, 1, 1)
N = N + 1
SP = P 'Startposition = vorige Endposition
Next
T2 = T2 & Mid(T1, SP) 'den Teil nach der letzten Fundstelle auch noch mitnehmen
fso.CreateTextFile(Aus, true).Write T2
I'm sorry for the german texts, hope you can read it.
Can you help me to find the error?
Upvotes: 0
Views: 183
Reputation: 38755
The problem is caused by opening/creating both Ein
and Aus
for ASCII encoding (the FSO's default). The "Microsoft VBScript runtime error '800a0005'. Invalid procedure call or argument" is often caused by asking .Write(Line) to output something illegal for the selected encoding. (cf. this answer)
If Ein
is UTF-16 you can open/create the file in that mode (encoding parameter of those methods); if it is UTF-8 you can use an ADODB.Stream for I/O
Upvotes: 1