1 (edited by sdpc62 2022-07-13 09:19:47)

Topic: Help for my division please

Hello everyone, I'm trying to do a division for my son but I find an error and I don't know where it comes from.
Can anyone help me?

Post's attachments

Attachment icon Formulaire de calcul.zip 336.33 kb, 105 downloads since 2022-07-13 

Re: Help for my division please

sdpc62 wrote:

Hello everyone, I'm trying to do a division for my son but I find an error and I don't know where it comes from.
Can anyone help me?

frmOperation.edTotalDivision.Value := frmOperation.edDivision1.Value / frmOperation.edDivision2.Value;

Re: Help for my division please

Hi,
 

if frmOperation.edDivision2.Value <> 0 then
    frmOperation.edTotalDivision.Value := frmOperation.edDivision1.Value / frmOperation.edDivision2.Value
    else ShowMessage('You cant divide by 0.');

Re: Help for my division please

Super, Merci a vous deux, ca fonctionne très bien. Vous êtes des chefs.
Bizzz

Re: Help for my division please

Hi Sabine,
In your attachment, I noticed that you have procedures 'frmoperation_edDivision1_OnChange' and 'frmoperation_edDivision2_OnChange' and both procedures then call your own procedure 'calculatetotaldivision'.  So, in effect, your script has 3 procedures.
Instead of using the procedure name that is automatically generated by MVD, you can just enter your own procedure name and then double-click to create it in the script. 
So, 1 procedure instead of 3 which makes the script both more compact and more readable.
However, the real bonus is that you can also use your own procedure on many different objects.
Perhaps the attachment will illustrate better the point - instead of 6 separate procedures for the 6 edit 'onchange' events that all then call the 7th procedure (to calculate everything), it can be done just with 1 procedure.  Notice how the 'onchange' event for all 6 edit fields is the same - 'calculatetotal'
Maybe this helps,
Derek.

Post's attachments

Attachment icon sdpc own procedure.zip 335.49 kb, 121 downloads since 2022-07-13 

6 (edited by sparrow 2022-07-13 14:03:07)

Re: Help for my division please

Hi Sabine and Hi Derek )


Sabine, I would recommend adding a divide-by-0 check like the example I posted. But of course this is optional.
And the restriction on entering only numbers.

7 (edited by sdpc62 2022-07-14 09:43:58)

Re: Help for my division please

Exactly the program only concerns numbers and it gives me an error when I apply it.

Post's attachments

Attachment icon erreur.jpg 5.83 kb, 58 downloads since 2022-07-14