vbscript - How to find the random value for a particular string in an array -


i have text file in following format more 100 entries

header responses  --- amd 6001 --- sent packet fro 101 a_test 5001 status 0  --- amd 6002 --- sent packet fro 101 a_test 5002 status 1 

my requirement validate whether value of 'status' 0, if so, proceed further fetch random 'a_test' value each entry. please me effective approach find 'a_test' values in each entry, because time taken execution more important due large number entries.

i have written code in following structure

set txtfile = fso.opentextfile("") set content= txtfile.readall arrentry = split (content,"--- amd") num=1 ubound(arrentry)     '2nd entry fails due entry status         if instr(arrentry(num),"status 0") > 0         ' how proceed further value of 'a_test' array ????      else         'fail - dont proceed further     end if next 

your code fails, because

set content= txtfile.readall 

wrongly uses set assign non-object (string) variable. like

  dim sall : sall = gofs.opentextfile("..\data\31429305.txt").readall()   dim s   each s in split(sall, "--- amd")       if instr(s, "status 0")          wscript.echo split(s, vbcrlf)(3)       end if   next 

will 'work' if lucky (eol marker vbcrlf, a_test in 4th line).

i'd use regexp, in:

  dim sall : sall     = gofs.opentextfile("..\data\31429305.txt").readall()   dim rcut : set rcut = new regexp   rcut.global    = true   rcut.multiline = true   rcut.pattern   = "^a_test (\d+)\r$\n^status 0\r$"   dim m   each m in rcut.execute(sall)       wscript.echo m.submatches(0)   next 

Comments