vb.net - VB Reading from text file, searching text and feeding to excel -


i have form richtextbox the path of input file displayed. have button in form. input text file large file repetitions of following chunk of data:

        program tracing   (1)      on ia     mpag    (b) ar0=h'0000 7402              mtv     (b) var h'01 62ae:h'148=h'c350     mtv     (b) var h'01 62ae:h'147=h'071f     mtv     (b) var h'01 62ae:h'02b=h'4404     mtv     (b) var h'01 62ae:h'02c=h'5712     mtv     (b) var h'01 62ae:h'029=h'5405     mtv     (b) var h'01 62ae:h'02a=h'f272     mtv     (b) var h'01 62ae:h'093=h'3853     mtv     (b) var h'01 62ae:h'094=h'2060     mtv     (b) var h'01 62ae:h'091=h'3046     mtv     (b) var h'01 62ae:h'092=h'f024     mtv     (b) var h'01 62ae:h'1bb=h'0d07     mtv     (b) var h'01 62ae:h'1bc=h'0b0b     mtv     (b) var h'01 62ae:h'1bd=h'0616     mtb     (b) var h'00 152e:h'00b(h'0001)=h'0079     mtb     (b) var h'00 152e:h'00b(h'0002)=h'0019     mtb     (b) var h'00 152e:h'00b(h'0003)=h'0062     mtb     (b) var h'00 152e:h'00b(h'0004)=h'0086     mtb     (b) var h'00 152e:h'00b(h'0005)=h'0041     mtb     (b) var h'00 152e:h'00b(h'0006)=h'0000     mtb     (b) var h'00 152e:h'00b(h'0007)=h'0000     mbpag   (b) var h'027=h'5970 c25f  end 

what need : when button clicked, search file each line starting mtv & mtb, values appearing after "=" sign. example starting h'c350 ....to h'0000. call excel & feed values in single row each chunk.

please regarding this.

full linqpad-ready example:

sub main     ' example data     dim data = <xml>        program tracing   (1)      on ia     mpag    (b) ar0=h'0000 7402              mtv     (b) var h'01 62ae:h'148=h'c350     mtv     (b) var h'01 62ae:h'147=h'071f     mtv     (b) var h'01 62ae:h'02b=h'4404     mtv     (b) var h'01 62ae:h'02c=h'5712     mtv     (b) var h'01 62ae:h'029=h'5405     mtv     (b) var h'01 62ae:h'02a=h'f272     mtv     (b) var h'01 62ae:h'093=h'3853     mtv     (b) var h'01 62ae:h'094=h'2060     mtv     (b) var h'01 62ae:h'091=h'3046     mtv     (b) var h'01 62ae:h'092=h'f024     mtv     (b) var h'01 62ae:h'1bb=h'0d07     mtv     (b) var h'01 62ae:h'1bc=h'0b0b     mtv     (b) var h'01 62ae:h'1bd=h'0616     mtb     (b) var h'00 152e:h'00b(h'0001)=h'0079     mtb     (b) var h'00 152e:h'00b(h'0002)=h'0019     mtb     (b) var h'00 152e:h'00b(h'0003)=h'0062     mtb     (b) var h'00 152e:h'00b(h'0004)=h'0086     mtb     (b) var h'00 152e:h'00b(h'0005)=h'0041     mtb     (b) var h'00 152e:h'00b(h'0006)=h'0000     mtb     (b) var h'00 152e:h'00b(h'0007)=h'0000     mbpag   (b) var h'027=h'5970 c25f  end     </xml>      ' create excel instance     dim xl = microsoft.visualbasic.createobject("excel.application")     xl.visible = true     dim wb = xl.workbooks.add()     dim sheet = wb.activesheet      ' find lines starting whitepace followed mtv or mtb , capture     ' text after =     dim pattern = "(?<=\s*(mtv|mtb).*=).*"      dim = 1     dim arg = { microsoft.visualbasic.controlchars.crlf,  microsoft.visualbasic.controlchars.lf }      ' want use file.readlines('yourfile.txt') here instead of data.value.split...     each line in data.value.split(arg, stringsplitoptions.none)         dim match = regex.match(line, pattern)         ' check each line , fill sheet         if match.success             sheet.cells(i, 1).value = match.value             += 1         end if     next  end sub 

Comments