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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Script to Parse Text File - HELP Needed

Status
Not open for further replies.

trytofixalot

Technical User
Jun 28, 2010
8
GB
Hi, I have created a vbs that parses a comma seperated txt file for my machine name which then writes 2 values to the regsisty. I cannot get the 'loop' function to work. the script only works if the computername is on the top of the list with thin text file. Can someone help me out pls.

option explicit
dim wsh, fso, inputfile, machinename, inputline, linetosplit, strhost, strbu, strseg

set wsh = createobject("wscript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputfile = fso.openTextFile("C:\Users\username\Documents\Tools and Scripts\BUSeg Script\mylist.txt",1, FALSE)
machinename = Wsh.ExpandEnvironmentStrings("%computername%")

Do While Not (InputFile.atEndOfStream)

inputline = inputfile.readline
linetosplit = split(inputline,",")
strhost = linetosplit(0)
strbu = linetosplit(1)
strseg = linetosplit(2)
if UCASE(strhost) = UCASE(machinename) then
wsh.regwrite "HKLM\Software\MyCompany\Application\Business",strbu
wsh.regwrite "HKLM\Software\MyCompany\Application\Segment",strseg
else
wsh.regwrite "HKLM\Software\MyCompany\Application\Business","Unknown"
wsh.regwrite "HKLM\Software\MyCompany\Application\Segment","Unknown"


end if

loop
 
First, make sure that the "linetosplit" array has 3 elements.
I suspect that the code did not reach the [blue]if UCASE(strhost) = UCASE(machinename) then[/blue] line because that array's length is less than 3.

Second, I would suggest that you put an error handler there.

Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top