Use global variable in dialog's ControlCustomScript

Please let our ADS show!

This sites offers only FREE software and it's supported by a few advertisement boxes (no intrusive popups).
Please:

  • disable your AdBlocker by adding CoolSoft website to whitelist
  • give the proper cookie consent
  • enable JavaScript for this website

This seconds wait is to let you update your browser configuration...

Ok, I've done the required changes... now show me your content!
!!! Please enable JavaScript !!!
Anonymous user
Use global variable in dialog's ControlCustomScript

Hi! I have used Dialog Designer to create a dialog with radio buttons and worked out fine. I have successfully managed to handle radiobuttons selections. However, I have the following problem: when I switch between pages my radiobutton selection disappears. So I want to somehow store the selected value in the outside script (I used a global variable like this Var /GLOBAL MAIN_SELECTION and store the value selected in each of the onClick callbacks for each radiobutton) and then use this value when dialog is recreated (defined in CreateFunctionCustomScript). 

The script I added was the following

MessageBox MB_OK|MB_ICONEXCLAMATION "Selection $(MAIN_SELECTION)" /SD IDOK
 
${If} $MAIN_SELECTION == "1"
    MessageBox MB_OK|MB_ICONEXCLAMATION "Select radio 1" /SD IDOK
    ${NSD_Check} $hCtl_MainPage_RadioButton1
${Endif}
 
${If} $MAIN_SELECTION == "2"
    MessageBox MB_OK|MB_ICONEXCLAMATION "Select radio 2" /SD IDOK     
    ${NSD_Check} $hCtl_MainPage_RadioButton2
${Endif}
 
${If} $MAIN_SELECTION == "3"
    MessageBox MB_OK|MB_ICONEXCLAMATION "Select radio 3" /SD IDOK
    ${NSD_Check} $hCtl_MainPage_RadioButton3
${Endif}
 
${If} $MAIN_SELECTION == "4"
    MessageBox MB_OK|MB_ICONEXCLAMATION "Select radio 4" /SD IDOK
    ${NSD_Check} $hCtl_MainPage_RadioButton4
${Endif}

But it doesn't work. My question is.
1) How can I restore the selected radiobutton when going back and forth between pages (back in my case)?
2) Is it possible and how to communicate some variables between main script and scripts generated by Dialog Designer?
 
Looking forward to any tip!
Thanks in advance.

Posts: 1978
Joined: March 25, 2012 - 01:19
Re: Use global variable in dialog's ControlCustomScript

If you defined ${MAIN_SELECTION} variable outside th .nsdinc file and before including it it should work.
What's the output of the first MessageBox? I mean, what's the value of ${MAIN_SELECTION} variable?

MessageBox MB_OK|MB_ICONEXCLAMATION "Selection $(MAIN_SELECTION)" /SD IDOK

How do you store the value into the variable?
I'd like to give a look to the whole script, if you like too.
Please remove everything but the radiobuttons page and a page before/after, zip all the .nsi* files together and post it here (or send it to me through the contact form).