Hi to All,

I am a newbie so would really appreciate some help.

I have a text file with several lines and I want to do two things.

1. Search through a file which has a several lines of text but I am only interested in lines which contain ‘=>’ (eg shown below)

scrsep.png=>2 PNG 800×600=>200×200 800×600+300+200 8-bit DirectClass 0.000u 0:00.015

2. Once I find that line, I want to be able to read the last 3 digits (015), compare it with a value say (050) and if it is less then 50, write 0 in an output file. If it is greater then (050), then write 1 in the output text file.Eventually I want to be able to use this string of final 1’s and 0’s stored in the output file to display a green or red cell on a web page respectively.

Would it be possible for you to give me some guidance? I really appreciate that.

Kind Regards

Annie Johnson

i really suck at vbs, but here's my lame attempt, maybe you can work from it (msgboxes are for diagnosis, like "echo"): dim fso

Path1=".\"

Set fso = createobject("Scripting.FileSystemObject")

Set Folder = fso.GetFolder(Path1)

File="test"

Dir=Path1

Fileout="testout"

Const ForReading = 1

Const ForWriting = 2

Const ForAppending = 8

' .\test

Set oFile = fso.OpenTextFile (Dir&Fileout, ForAppending, True)

Set iFile = fso.OpenTextFile (Dir&file, ForReading)

do while iFile.AtEndOfStream=false

x=iFile.readline

if instr(x,"=>")>0 then

msgbox x

ll=len(x)-2

ff=mid(x,ll,3)

if ff>50 then kk=1 else kk=0

ofile.writeline kk

msgbox kk

end if

loopWscript.Quit

Hi , I don’t know how to thank you but this is almost exactly what I was looking for! Once again, thank you for your help.

Regards

Annie

Hi,

I have one more question related to this and would be grateful for some help.

I have a text file which only has one digit in each row; this digit is either 0 or 1I want to be able to read this text file line by line and if I encounter 0 in any row, then I want to save the result in a new text file giving the row number where 0 was found

For example, if my input text file is:

1

1

0

1Then the output text file will say:

Found in row 3Kind Regards

Annie

One last question:

If I have a text file as follows:

all: 8144.4 (0.124276)How can I read the first two digits after the decimal point within brackets? As the number of decemial places can be anywhere between 4 and 6, I need to read 2 places after decimal (from left to write) (i.e. 12)

Please help.

Kind Regards

Annie

plug this into the core of the code in resp #1 (ie: inside the do while loop): n=n+1

if x=0 then

ofile.writeline("zero at row " & n)

end if(initialize var. n to zero prior to the do-while loop): n=0

part 2, (var. Y contains the string you described like:

76(12.8962) read in from file as was done above)p=instr(y,"(")

if p>0 then

p2=instr(y,p+1,".")

if p2>0 then

y=mid(y,p+1,p2-p+2)

end if

end if

Hi thanks again for your reply, really helpful. One last question I have on part 1 is: If my text file was like

1

0

1

1

0Is there a way to write the found ‘0’s’ in a single line so that the output file says:

zero found at 3, 5Also if no 0 is found in any row, how can I write one line to output file saying:

No zero foundKind Regards

Annie

yeah, try something like (pre-loop):

n=0

zeros=""(inside loop)

if x=0 then zeros=zeros&","&n(outside loop:)

if zeros="" then zeros="no zeros found" else zeros="zeros at lines: "&zeros

ofile.writeline zeros

Hi , sorry I am a bit lost. Is that how you mean?

n=0

zeros=""

do while iFile.AtEndOfStream=false

x=iFile.readline

if x=0 then

zeros=zeros&","&n

n=n+1

else

end if

if zeros="" then zeros="no zeros found" else zeros="zeros at lines: "&zeros

ofile.writeline zeros

loopKind Regards

Annie

close! just do some surgery:

n=0

zeros=""

do while iFile.AtEndOfStream=false

x=iFile.readline

n=n+1

if x=0 then zeros=zeros&","&n

loopif zeros="" then zeros="no zeros found" else zeros="zeros at lines: "&zeros

ofile.writeline zeros

Thanks a million for your patience and guidance :)

Ask Your Question

Weekly Poll

Do you think Facebook should be allowed to move forward with the Libra currency?

Discuss in The Lounge

Poll History