0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

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

Community
  • 1
  • 1
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • Hey guys, i tried something, but everytime failed. Im very sad about this. i need help. Can anybody give an example for my vbscript? I am really happy if you could help me. cheers – user2178824 Jul 24 '13 at 20:06
  • 1
    So, what *exactly* is that "something" you tried? And how *exactly* did it fail? – Ansgar Wiechers Jul 25 '13 at 08:19
  • its okay.thx for your help. i tipped the numbers via hand in the last night...great work.im very proud to me ^_^ .. i delete this thread in the evening.. cheers – user2178824 Jul 25 '13 at 09:38