vb.net - Loop through array and insert items -
i'm working on project read vb.net solutions code files list(of file)
(file being custom class) , loop through code
(code being list(of string)
) property of each file.
what want in loop add random code, i'm having quite bit of trouble figuring out how make work correctly.
the problem code inserted in places don't want inserted.
i have tried couple of different ways of doing this:
simply looping through code property , adding lines if conditions right.
adding property:
public indices list(of integer)
, looping through , inserting lines code property using new properties values.adding property:
public insertionloopcode list(of string)
, assigning code property , looping through new property , adding lines code property
what code looks like:
for each folder folder in folders each file file in folder.files = 0 file.insertionloopcode.count - 1 if file.insertionloopcode(i).contains(" sub ") andalso not file.insertionloopcode(i).contains("delegate") startsub = true elseif file.insertionloopcode(i).contains("end sub") startsub = false elseif startsub = true andalso not file.insertionloopcode(i).contains(" sub ") if mod randomization.random.next(1, 5) = 0 dim randomnumber integer = random.next(0, 2) if randomnumber = 0 'file.code.insert(i, insertion.insertvariable(false)) elseif randomnumber = 1 insertforloop(file, i) elseif randomnumber = 2 end if end if end if next next next
i don't think it's conditional statement, or @ least not that, works fine when i'm not inserting lines, doing msg boxes or writing console.
edit: make more clear. before:
module main dim withevents playerreader new backgroundworker sub main() console.readline() end sub dim player new player dim enemy(64) enemy private sub playerreader_dowork(byval sender object, byval e system.componentmodel.doworkeventargs) handles playerreader.dowork while true player.getinformation() player.checkstate() = 0 64 - 1 enemy(i).getinformation(player, i) if player.health > 0 if player.team <> enemy(i).team andalso enemy(i).health > 0 console.writeline(enemy.name) end if end if next end while end sub end module
after:
module main dim withevents playerreader new backgroundworker *dim awdasndwand integer = 29* 'supposed italic sub main() console.readline() **dim yumngsef string** 'supposed bold end sub dim player new player dim enemy(64) enemy private sub playerreader_dowork(byval sender object, byval e system.componentmodel.doworkeventargs) handles playerreader.dowork while true player.getinformation() player.checkstate() = 0 64 - 1 enemy(i).getinformation(player, i) if player.health > 0 if player.team <> enemy(i).team andalso enemy(i).health > 0 console.writeline(enemy.name) end if end if next end while end sub end module
the bold supposed there, italic not. thing if have couple of files or guess specific files, works fine. read whole solution, insert variables in wrong places.
jesus christ, why post getting minus points? how instead of being jerk , down-voting, commenting on problem is?
i think down votes came because question unclear. made lot of effort explain problem, of describe properties of custom class didn't share. try answering (or @ least reading , seeing if understand) other people's questions , should give better grasp on when question or not communicated.
anyway, though think problem stems code can't see, have hunch on what's causing it. before , after suggests when reach segment of code posted, startsub
true
. due scope of variable; first file
processed correctly, since startsub
declared outside of for
loop, isn't reinitialized each new file
. code should set startsub
false
when encounters end sub
line, if previous file
had line missing or mistyped, throwing off. see if adding startsub = false
before for = 0...
fixes problem.
also note if line in file
has trailing space after end sub
, unexpected results, code never test "end sub" because have found " sub " in same line. if custom class takes care of that, great. if not, changing first if
statement if file.insertionloopcode(i) "*sub ?*"
give safer results, ensure there type of text after word "sub".
and on meta note, you've realized formatting code (bold/italic) won't work inside of text formatted code.
Comments
Post a Comment