Forum > Databases

[SOLVED] Fuzzy Math

<< < (2/3) > >>

Slyde:
That's as good of an explanation as anyone cld ever get.  Thanks, Thausand.  Thanks for your time.

Thausand:

--- Quote from: Slyde on June 28, 2022, 02:26:29 am ---
This is the working code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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;
Now, here's the code that fails.  Note the changes in lines 11 and 12:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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;
--- End quote ---

look highlight line. If change i then change if

Slyde:
It means the user has seen all previous data.  So I disable the button at i = 1, the first element of previousVec record.  There's nothing left to see.  It makes sure the user can't click the button and try to read an element from the vector that's not there.  And the next click of the Next button re-enables it.  So far, everything's working out in my little program.  But I have to say that getting the bugs out of the previous button click stuff was about as much fun as having a bowl of rocks for breakfast  :D

Thausand:

--- Quote from: Slyde on June 28, 2022, 04:40:21 am ---It means the user has seen all previous data. 

--- End quote ---
Yes, i now that  :)


--- Quote ---So I disable the button at i = 1, the first element of previousVec record.

--- End quote ---
Yes/No   ;)

In first code answer yes. i=1, vectorindex = i-1 = 0

In second code answer no. i=1 vectorindex = i = 1.

Vector index is run zero ... size-1.


--- Quote ---There's nothing left to see. It makes sure the user can't click the button and try to read an element from the vector that's not there.

--- End quote ---
If i = 1 then is miss zero vector index that have value.

in both code, it read:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  btnPrevious.Enabled := (i=1); 
but if want have good disable button then have show vector index zero to, is better code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  btnPrevious.Enabled := (i=0); 
But can also make button enable before subtract.


--- Quote ---But I have to say that getting the bugs out of the previous button click stuff was about as much fun having a bowl of rocks for breakfast  :D

--- End quote ---
If you have solved problem then good  :)

Slyde:
I'll show you all the code when I finish this.  But it isn't my fault when you go crazy after seeing it :D

But yes, it does work as is.  And I understand what you mean, in that vectors are zero-based.  But what I showed isn't the finished product.  I don't like how it looks either.  It shld be 0 and not 1.  But...like I said: I'm a
--- Quote ---lightweight in the world of Free Pascal and Lazarus
--- End quote ---
 
But I'll get there.  With a little help from my friends. 

I appreciate your input, Thausand.  I really do.  Constructive words are always welcome.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version