How to initialize checkbox value in installshield
Asked Answered
S

5

6

How to set initial value of a check box (Checked/NotChecked) in InstallShield 2010.

I added CheckBox to the Form, during adding I let for creation of custom property (I named it ISCHECKED). I set Value to 1, so when checbox is checked then this property has value equal to 1.

When I run installer I CheckBox is always checked and I want to have it unchecked, what should I do. I tried to modify this custom property and set value to different values in property manager but without luck. I know that when I click on the CheckBox it modifies this property value (I enable / disable other UI elements).

Sectarian answered 29/7, 2011 at 17:52 Comment(0)
E
12

A checkbox is checked when its property is set and unchecked when the property is empty.

To make it unchecked by default, make sure that its property is not initialized to a value. Only associate the property to your checkbox, but do not set its value to "1".

Erysipelas answered 29/7, 2011 at 22:33 Comment(6)
Thank you, Question my property is a global property and it is visible under Properties list in InstallShield, By default it is set to 0. What can I do in order to un - initialize this property.Sectarian
Delete it. "0" is still a value, so the property is set. It doesn't matter if it's "0" or "1" or "value".Erysipelas
Another one of those quirky InstallShield things, I wonder if Flexera will ever get around to fix this?Spellbound
This illogical behavior of InstallShield made me lose quite some time today. I don't think anyone in Flexera is actively working anymore on InstallShield... We just have to deal with its mess.Gherkin
Eight years later this is still an issue in InstallShield 2018.Masterful
Eleven years later this is still an issue in Installshield 2020Killough
N
2

I worked around this by creating a CheckBoxGroup with two checkboxes. One "Yes" and one "No" where "Yes" had the value 1 and "No" was value 0.

Nonchalant answered 5/3, 2013 at 18:59 Comment(1)
This is a good solution on a dialog with one or two simple yes/no choices, but would get messy if you want a list of several items to enable/disable.Borreri
M
2

As I said in my comment this is still an issue in InstallShield 2018. Here's the workaround I came up with. I created two custom action scripts. One for translating from "0" and "1" to empty "" and "1" and another script for translating back to "0" and "1". I created custom actions TranslateChkBoxesZeroToEmptyAction and TranslateChkBoxesEmptyToZeroAction that call functions TranslateChkBoxesZeroToEmpty and TranslateChkBoxesEmptyToZero respectively.

I call TranslateChkBoxesZeroToEmptyAction In Behavior and Logic:Custom Actions and Sequences:Sequences:Installation:User Interface just after SetupCompleteSuccess and before AppSearch. I call TranslateChkBoxesEmptyToZeroAction just after MaintenanceWelcome and before SetupProgress.

So the affect is to convert "0" strings to empty"" before the dialog is opened and to convert empty "" to "0" after the dialog closes

===setup.rul====

export prototype ForceEmptyToZero(HWND, STRING);
export prototype ForceZeroToEmpty(HWND, STRING);
export prototype TranslateChkBoxesEmptyToZero(HWND);
export prototype TranslateChkBoxesZeroToEmpty(HWND);

// **********************************************************************
// function ForceEmptyToZero -- Convert "" to "0"
// 
// This function must be called on each CheckBox property after closing
// the dialog that contains the checkbox.  It converts empty "" string 
// to "0" in order to be compatible with InstallShield logic for checkboxes.
// 
// 2018Aug02jdn Created by Jon D. Newbill / www.bitworkssystems.com
// **********************************************************************
function ForceEmptyToZero(hMSI, propStr)
    STRING valStr;
    NUMBER strLen;
begin
    strLen = 100;
    MsiGetProperty(hMSI, propStr, valStr, strLen);
    // If not "1" then assume false and force to "0"
    if (valStr != "1") then
        valStr = "0";
        MsiSetProperty(hMSI, propStr, valStr);
    endif;
end;    

// **********************************************************************
// function ForceZeroToEmpty- Convert "0" to ""
// 
// This function must be called on each CheckBox property before opening
// the dialog that contains the checkbox.  It converts "0" string to 
// empty "" in order to be compatible with InstallShield logic for 
// checkboxes.
// 
// 2018Aug02jdn Created by Jon D. Newbill / www.bitworkssystems.com
// **********************************************************************
function ForceZeroToEmpty(hMSI, propStr)
    STRING valStr;
    NUMBER strLen;
begin
    strLen = 100;
    MsiGetProperty(hMSI, propStr, valStr, strLen);
    // If not "1" then assume false and force to empty string ""
    if (valStr != "1") then
        valStr = "";
        MsiSetProperty(hMSI, propStr, valStr);
    endif;
end;    



// **********************************************************************
// function TranslateChkBoxesZeroToEmpty -- Convert "0" to ""
// 
// This function must be called before the OptionSelection dialog is
// run.  This function converts all CheckBox properties from values of
// "0" or "1" to empty string "" or "1" respectively.  This is done to
// deal with an anomaly in the way InstallShield handles CheckBoxes
// assigned to properties.  Checkboxes are unchecked only when
// associated property is an empty string "" and checked for any other
// non-empty string.
// 
// https://mcmap.net/q/1635272/-how-to-initialize-checkbox-value-in-installshield
//
// So we must convert all "0" strings to "" empty string before the
// OptionSelection dialog runs and then convert all "" to "0" after the
// dialog closes.
// 
// 2018Aug02jdn Created by Jon D. Newbill / www.bitworkssystems.com
// **********************************************************************
function TranslateChkBoxesZeroToEmpty(hMSI)
    STRING valStr;
    NUMBER strLen;
begin
   ForceZeroToEmpty(hMSI,"TIMESTAMP");
   ForceZeroToEmpty(hMSI,"HIDECAPWIN");
   ForceZeroToEmpty(hMSI,"FINDVCP");
   ForceZeroToEmpty(hMSI,"LCDACCEPT");
   ForceZeroToEmpty(hMSI,"SERNUM");
   ForceZeroToEmpty(hMSI,"TOPWIN");
   ForceZeroToEmpty(hMSI,"ZOOM");
   ForceZeroToEmpty(hMSI,"ACCEPTCLOSE");
end;




// **********************************************************************
// function TranslateChkBoxesEmptyToZero -- Convert "" to "0"
// 
// This function must be called after the OptionSelection dialog closes.
// This function converts all CheckBox properties from values of empty
// string "" or "1" to "0" or "1" respectively.  This is done to deal
// with an anomaly in the way InstallShield handles CheckBoxes assigned
// to properties.  Checkboxes are unchecked only when associated
// property is an empty string "" and checked for any other non-empty
// string.
// 
// https://mcmap.net/q/1635272/-how-to-initialize-checkbox-value-in-installshield
//
// So we must convert all "0" strings to "" empty string before the
// OptionSelection dialog runs and then convert all "" to "0" after the
// dialog closes.
// 
// 2018Aug02jdn Created by Jon D. Newbill / www.bitworkssystems.com
// **********************************************************************
function TranslateChkBoxesEmptyToZero(hMSI)
    STRING valStr;
    NUMBER strLen;
begin
    ForceEmptyToZero(hMSI,"TIMESTAMP");
    ForceEmptyToZero(hMSI,"HIDECAPWIN");
    ForceEmptyToZero(hMSI,"FINDVCP");
    ForceEmptyToZero(hMSI,"LCDACCEPT");
    ForceEmptyToZero(hMSI,"SERNUM");
    ForceEmptyToZero(hMSI,"TOPWIN");
    ForceEmptyToZero(hMSI,"ZOOM");
    ForceEmptyToZero(hMSI,"ACCEPTCLOSE");
end;

FROM MICROSOFT LINK:

"This CheckBox_control is a two-state check box. To associate an integer or string property with this control, enter the property name into the Property column of the Control table. The selected state of the box sets the property either to the value specified in the Value column of the CheckBox table or to the initial value of the property specified in the Property table. If the property has no initial value, the checked state sets it to 1. The unselected state sets the property to null."

The terminology is confusing. What do they mean by "The selected state"? Do they mean the "Checked state"? And then it says it sets to EITHER the Value column or the initial [default] property value. Well which is it? It can't be both. From my experience the CHECKED state sets to the Value field of the CheckBox properties table and the UNCHECKED state always sets property to empty string "". The above text also fails to describe how the initial display state of the CHECKBOX is defined from the associated property by non-empty string = CHECKED and empty string = UNCHECKED. It only describes the action of setting the property on closing of dialog window.

Masterful answered 3/8, 2018 at 18:31 Comment(2)
After filing a support case with Flexera and referencing this Stackoverflow post I have been told that a request has been made to update their documentation to better explain this unexpected behavior. The support person also noted that this is actually a Microsoft issue. Referring me to the following Microsoft link learn.microsoft.com/en-us/windows/desktop/msi/checkbox-control I noted that even Microsoft does a poor job of describing the behavior and he agreed.Masterful
It is terribly unpleasant to have to add custom code to make checkboxes work the way they should, but this solution does resolve the issue reliably.Borreri
A
1

I found the answer on: https://resources.flexera.com/web/pdf/archive/check.pdf

For any type of control, the initial value or state of the control is defined by the corresponding property's value. The value can be set in the Property table. In the case of a check box control, the initial state can be checked (selected) or unchecked (cleared): To have the check box initially checked, use the Property Manager view of the InstallShield environment to set the property (CHECKBOXPROP) to the same value you defined in the check box control's Value setting (1, in this example). To have the check box initially unchecked, delete the property (CHECKBOXPROP) from the Property Manager view.

This helped me at least for the VIEW.

Athlete answered 14/12, 2021 at 11:18 Comment(0)
E
-2
  1. In the View List under Behavior and Logic, click Property Manager.

  2. Set the Value to 1 which property you want.

Edgington answered 23/6, 2013 at 15:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.