I have a script that is supposed to check the first 4 characters of each line. It's not working. I'm processing HL7 documents that look like this:
MSH|...
EVN|...
PID|...
MSH|...
EVN|...
PID|...
MSH|...
EVN|...
PID|...
and here is my code:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile (f.path, 1)
Do Until file.AtEndOfStream
line = file.Readline
wscript.echo left(line,4)
Loop
This outputs the following:
MSH|
MSH|
MSH|
Is there something I should use besides Readline
?
I ended up using emeditor 's replace in files
feature to replace all instances of \\r
with \\r\\n
. This seems to fix the issue.
Revisited this for another task and found a better way. The following set of loops and conditions will break down a .dat file full of HL7 messages into Message, Segment, Field and Subfield. It does not account for repeating fields (~).
The first two FOR
statments solve the original issue with line feeds vs carriage returns. It turns out there is a lf between each message and a cr between each segment.
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
file = fso.OpenTextFile(f.path).ReadAll
for each msg in split(file,vbLf)
if msg <> "" then
msgType = split(split(msg,"|")(8),"^")(1) 'results in something like A08
for each line in split(msg,vbCr)
if line <> "" then
seg = left(line,3) 'MSH, PID, etc
for each field in split(line,"|")
if instr(field,"^") > 0 then
for each subfield in split(field,"^")
'do code here for each subfield
next
end if
next
end if
next
end if
next
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.