Options

Values in checkboxes

RainerRainer Member Posts: 103
How do I "taste" if value in a checkbox is true or false?

I have a few checkboxes in the form, and some is true..some is false when users activate those. When I "run" som code.. I have to "taste" which checkbox is false and which is true....like this:

if "chkBox_01 value" then
..some code

else begin
..some code

end

...and... how do I set a checkbox TRUE from the C/AL code?

Rainer
Kind Regards

E-mail: info@rainerbay.dk
Skype: rainerbaydk

Comments

  • Options
    CodeGeniusCodeGenius Member Posts: 40
    Hi Rainer,

    To see what value the checkbox has you should look at the value of the "SourceExpr" of the checkbox.

    Also by setting the value of the "SourceExpr" to true you will check the check in the checkbox. When set to False you uncheck the checkbox.
  • Options
    DenSterDenSter Member Posts: 8,304
    Almost :)

    Each checkbox on your form should have a boolean variable in its SourceExpr property that is defined as a global variable, so you can access its value anywhere in the object code.

    So let's say we have a gobal boolean variable called MyCheck, and it is et as the SourceExpr on the form. In your code, you'd do something like this:
    IF (MyCheck = TRUE) THEN BEGIN
      // do your stuff here
    END ELSE BEGIN
      // here's the other stuff
    END;
    
    For one evaluation the parentheses are not necessary, but it's the most complete you can get.

    To set the value of the checkbox, you use the assignment operator ":=", like this:
    MyCheck := TRUE;
    

    I would personally not put TRUE or FALSE directly into the SourceExpr, because then you can't manipulate the value, and that makes the checkbox meaningless.

    Let me know if you need more information.
  • Options
    CodeGeniusCodeGenius Member Posts: 40
    Yup ... That's what I said... :?

    Does not need to be a variable. Field in a table is also possible.

    You set the value of the variable (or field) to TRUE (or FALSE) and this variable (or field) is defined in "SourceExpr". I never said put true or false in SourceExpr... That would be a NO NO... [-X
  • Options
    DenSterDenSter Member Posts: 8,304
    CodeGenius wrote:
    ...I never said put true or false in SourceExpr... That would be a NO NO...
    Ahem... I would beg to differ :roll:
    CodeGenius wrote:
    ...by setting the value of the "SourceExpr" to true you will check the check in the checkbox...

    I didn't think you'd suggest anything like that, I just thought because of the way you said this maybe someone would read it that way and I wanted to make sure that they use variables. :)
Sign In or Register to comment.