Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parser from txt to txt

Status
Not open for further replies.

legrooch

Programmer
Jun 11, 2003
5
PL
First - I'm newbie in programing.
Can anyone help me with some code?
I need to read from txt file and write it to other.
Problem is, that the file is strange.

That's a piece of it:

SMBIOS (aka DMIBIOS) Version 2.3.1 (Build 39) Display Utility - Mar 27 2000
------------------------------------------------------------
The following software is copyrighted material of the IBM Corporation and bla bla bla
------------------------------------------------------------
Structure: BIOS Information (Type 0)
Type: 0
Length: 13h
Handle: 0000h (0t)
BIOS Vendor: ' '
BIOS Version: 'Award Software International, Inc.'
BIOS Release Date: 05/20/1999
------------------------------------------------------------

I need to write it like that (some lines. which i will know in few hours):

BiosVersion = "Award Software International, Inc."
BiosReleaseDate = "05/20/1999
 
Hello legrooch,

I would lead you to an alternative path of getting these info from the machine.
Code:
set svc=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_systembios"
set cBios=svc.execquery(sQuery)
for each oBios in cBios
    BiosVersion=oBios.SMBIOSBIOSVersion
    BiosReleaseDate=Left(oBios.ReleaseDate,8)
        exit for
next
set cBios=nothing
set svc=nothing
As to the parsing of text file, you sure can and I'll leave it for other member's contributing.

regards - tsuji
 
For the parsing stuff, take mainly a look at FileSystemObject (aka fso), InStr, Split and Trim.
Feel free to read the FAQs and do keyword searchs in this forum.
Then come back with what you have so far.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks, sorry for problems.
I can't use WMI. There will be Win NT 4.0 without it.
That's a problem, why i must parse this file.
 
legrooch,

Okay, do it like this. Let the file be "d:\test\xyz.ext". Let the apostrophs "'" be there to enclose BiosVersion. Test it first and make it a sub or whatever for cosmetic reason if you like later.
Code:
const ForReading=1
filespec="d:\test\xyz.ext"
sep="'"
set fso=createobject("scripting.filesystemobject")
set f=fso.getfile(filespec)
set ts=f.openastextstream(ForReading,8)  'let file be coded in system default
bGetBiosVersion=false : bGetReleaseDate=false
do while not ts.atendofstream
    s=ts.readline
    if (instr(1,s,"Bios Version",1)<>0) and (not bGetBiosVersion) then
        pos1=instr(1,s,sep,1)
        pos2=instr(pos1+1,s,sep,1)
        BioVersion=mid(s,pos1+1,(pos2-pos1-1))
        bGetBiosVersion=true
    end if
    if (instr(1,s,"BIOS Release Date",1)<>0) and (not bGetReleaseDate) then
        BiosReleaseDate=trim(right(s,len(s)-instr(1,s,":",1)))
        bGetReleaseDate=true
    end if
    if bGetBiosVersion and bGetReleaseDate then exit do
loop
ts.close
set ts=nothing : set f=nothing : set fso=nothing
See what you get and post back. As I edit the code in-place in the textarea only, correct any typos etc you can discover during testing.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top