[SOLVED] Fuzzy Math lazarus / 16-Databases ---------------------------------------------------------------------- Slyde · 2022-06-27 19:24 Being the lightweight in the world of Free Pascal and Lazarus that I am, I find myself at a loss as to why one of these works Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var i: integer;// query herei:= previousVec.Size - previousTracker; // previousVec is a vector, and previousTracker is a integerDMod1.ZQ_Main.Params.ParamByName('id').AsInteger:= previousVec[i-1];// subtracting 1 from i works perfectlyand one doesn't. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var i: integer;// query herei:= (previousVec.Size - previousTracker) - 1;// should be the same as subtracting 1 from iDMod1.ZQ_Main.Params.ParamByName('id').AsInteger:= previousVec[i]; // but this fails Can someone tell me the difference between the two math problems?  How is Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i i:= previousVec.Size - previousTracker;i - 1; not the same as Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i i:= (previousVec.Size - previousTracker) - 1; ---------------------------------------------------------------------- BobDog · 2022-06-27 22:58 What exactly is i-1 i-=1 is not allowed in pascal. i:=i-1 is allowed in code, although in a maths exam you would surely fail i:=i-1 implies i-i=-1 i.e. 0=-1 ---------------------------------------------------------------------- Thausand · 2022-06-27 23:17 Quote from: BobDog on June 28, 2022, 12:58:52 amWhat exactly is i-1 i is value then subract 1 Quoteimplies No, it not implies. question OP is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  i,j, k: integer; i := previousVec.size - previousTracker;j := i-1; k := previousVec.size - previousTracker - 1; .. and why k <> j make example: Code: [Select]previousVec.Size := 10; previousTracker  := 8 i := 10 - 8; (=2) j := 2 - 1;  (=1) k := 10 - 8 - 1; (=1) User slyde say k <> j Is not logical but can if integer overflow ---------------------------------------------------------------------- Slyde · 2022-06-28 00:26 I didn't mean to confuse anyone.  I posted just the relevant code to my question, but I'll add to it. This is the working code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.btnPreviousClick(Sender: TObject);var  i: Integer;begin  btnVerify.Enabled:= False;   DMod1.ZQ_Main.Close;  DMod1.ZQ_Main.SQL.Text := 'SELECT question, a1, a2, a3, a4, the_answer ' +                              'FROM mult_choice '+                            'WHERE id = :id';  i:= previousVec.Size - previousTracker;  // previousVec is a global vector, and previousTracker is a global integer  DMod1.ZQ_Main.Params.ParamByName('id').AsInteger:= previousVec[i-1];  DMod1.ZQ_Main.Open;  lblQuestion.Caption:= DMod1.ZQ_Main.Fields[0].AsString;  rbtn_A1.Caption:= DMod1.ZQ_Main.Fields[1].AsString;  rbtn_A2.Caption:= DMod1.ZQ_Main.Fields[2].AsString;  rbtn_A3.Caption:= DMod1.ZQ_Main.Fields[3].AsString;  rbtn_A4.Caption:= DMod1.ZQ_Main.Fields[4].AsString;  lblTheAnswer.Caption:= DMod1.ZQ_Main.Fields[5].AsString;   if i = 1 THEN btnPrevious.Enabled:= False;   previousTracker:= previousTracker + 1;end; Please note lines 11 and 12. Now, here's the code that fails.  Note the changes in lines 11 and 12: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.btnPreviousClick(Sender: TObject);var  i: Integer;begin  btnVerify.Enabled:= False;   DMod1.ZQ_Main.Close;  DMod1.ZQ_Main.SQL.Text := 'SELECT question, a1, a2, a3, a4, the_answer ' +                              'FROM mult_choice '+                            'WHERE id = :id';  i:= (previousVec.Size - previousTracker) - 1;  DMod1.ZQ_Main.Params.ParamByName('id').AsInteger:= previousVec[i];  DMod1.ZQ_Main.Open;  lblQuestion.Caption:= DMod1.ZQ_Main.Fields[0].AsString;  rbtn_A1.Caption:= DMod1.ZQ_Main.Fields[1].AsString;  rbtn_A2.Caption:= DMod1.ZQ_Main.Fields[2].AsString;  rbtn_A3.Caption:= DMod1.ZQ_Main.Fields[3].AsString;  rbtn_A4.Caption:= DMod1.ZQ_Main.Fields[4].AsString;  lblTheAnswer.Caption:= DMod1.ZQ_Main.Fields[5].AsString;   if i = 1 THEN btnPrevious.Enabled:= False;   previousTracker:= previousTracker + 1;end; In the top block of code, I use Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  i:= previousVec.Size - previousTracker; Then I use the value of i and subtract 1 from it: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DMod1.ZQ_Main.Params.ParamByName('id').AsInteger:= previousVec[i-1]; This works perfectly. No issues at all. However, when I combine the math in the second block of code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  i:= (previousVec.Size - previousTracker) - 1; it should provide me the same outcome as the code in the first block.  But it fails.  So I was thinking I cld get clarity on this here in the forum. ---------------------------------------------------------------------- Thausand · 2022-06-28 01:28 Quote from: Slyde on June 28, 2022, 02:26:29 amI didn't mean to confuse anyone. It clear  QuoteHowever, when I combine the math in the second block of code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  i:= (previousVec.Size - previousTracker) - 1; it should provide me the same outcome as the code in the first block.  But it fails.  So I was thinking I cld get clarity on this here in the forum. It is produce same. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program vectortest; uses  gvector; type  TPreviousVec=specialize TVector; var  PreviousVec:TPreviousVec;  PreviousTracker:integer;  n,i,j:integer;begin  PreviousVec:=TPreviousVec.Create;   for n:=10 to 20    do PreviousVec.PushBack(n);   PreviousTracker:=0;   while previousTracker