From: Aziz on 11 May 2010 11:56 "Tom Lavedas" <tglbatch(a)verizon.net> wrote in message news:e6dafce3-f680-41c2-8093-ff8599c678d3(a)o14g2000yqb.googlegroups.com... > There are a number of unnecessary lines and variables in the script. > I'm not sure what the problem was, but I found it easier to edited it > to work for me. <SNIP> Thanks Tom, it worked great... Now to comapre it with the rpevious one and try to work out why that didn't work. Thanks again, much appreciated. -- Aziz
From: MikeB on 11 May 2010 18:00 On May 11, 8:37 am, "Aziz" <a...(a)aa.com> wrote: > Hello, > > I have this VB script, it goes through a text file and if it finds a line > with x400, x500 or SystemMailbox it deletes that line. > At the moment, the script removes all lines with x400 but won't do the same > for x500 or SystemMailbox. I think it's something to do with the value being > retained but don't know enough VB script to fix it. Can anyone help? > > Option Explicit > > Call DeleteLine("x400") > Call DeleteLine("x500") > Call DeleteLine("SystemMailbox") > > Function DeleteLine(strKey) > 'DeleteLine Function by TomRiddle 2008 > > Const ForReading=1:Const ForWriting=2 > Dim objFSO,objFile,strLine,strLineCase,strNewFile,strFile,LineNumber > REM,CheckCase > strFile = "C:\proxyaddresses.txt" > strKey = "x400" > > Set objFSO=CreateObject("Scripting.FileSystemObject") > Set objFile=objFSO.OpenTextFile(strFile,ForReading) > Do Until objFile.AtEndOfStream > strLine=objFile.Readline > REM If CheckCase=0 then > strLineCase=ucase(strLine):strKey=ucase(strKey) > If LineNumber=objFile.Line-1 or LineNumber=0 then > If instr(strLine,strKey) or instr(strLineCase,strkey) or strKey="" > then > strNewFile=strNewFile > Else > strNewFile=strNewFile&strLine&vbcrlf > End If > Else > strNewFile=strNewFile&strLine&vbcrlf > End If > Loop > objFile.Close > Set objFSO=CreateObject("Scripting.FileSystemObject") > Set objFile=objFSO.OpenTextFile(strFile,ForWriting) > objFile.Write strNewFile > objFile.Close > > Set objFile = Nothing > Set objFso = Nothing > Set strKey = Nothing > > End Function WOuld it not be far more efficient to pass an array with all the values that you want to delete to the function and then in the function read each line once, compare it to all values in the array, delete if necessary and return? Surely reading the file once, comparing each line against a number of values and then returning is more efficient?
First
|
Prev
|
Pages: 1 2 Prev: Errors compiling the script Next: Shutdown explorer not interactively ? |