Forum Discussion

jackson_1's avatar
jackson_1
Frequent Contributor
14 years ago

TC Assigned incorrect value to loop variable

i got a confused problem that the TC assigned the incorrect value to variable in loop.




below is my script with the for loop. there is any issue is this?




var i,RowCount: integer;




begin


RowCount: = VarToInt(Aliases.RegistryReset.MainForm.dataGridViewRegistryInfo.RowCount);



dataGridView: = Aliases.RegistryReset.MainForm.dataGridViewRegistryInfo;





for i: = 0 to RowCount - 1 do;


begin


        if i = 0 then


                Log.Message(i);


        Log.Message(RowCount);




        if aqConvert.CurrencyToStr(Aliases.RegistryReset.MainForm.dataGridViewRegistryInfo.wValue[i,0]) = 'Track Trial Keys' then





        begin





               //do something;    





       
end;


end;





end;





in my application. there is only one row in datagrid object in fact. so the value of the variable i it should be 0 when i run this first. but the Log.Message(i) statement does not be executed then i step by step to exectue it.


and the error 'The control item 1 not found.' i think that's due to the row 1(row index start from 0) does not exists actully.


appericate deeply if anyone can give help for me.

































  • jackson_1's avatar
    jackson_1
    Frequent Contributor
    in additionly, i used the tc version is 7.52 and in windows 7 64 bit.
  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 3 rankChampion Level 3
    Hi,



    I think that the problem is because of the semicolon in the loop line:

    for i: = 0 to RowCount - 1 do;



    The semicolon means that you have a loop with empty body and when the loop is over, the i variable has value of 1 as expected and observed.

    Just remove semicolon

    for i: = 0 to RowCount - 1 do

    and try your code.