Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
Hello,
I am trying to program my listboxes so that the selections appear as they were last saved. Using "Saving the state of controls", I was able to do this for most for the listboxes. Howewer, one of them will not save its settings. The listbox which will not save has an input from another listbox and I'm assuming that this is where the problem is arising.
Attached is a trimmed version of my program. The listbox titled Thickness receives an input from Cross-Section, which affects what is displayed in the Thickness listbox.
I would appreciate any help in solving this issue.
Thanks,
Carl
Solved! Go to Solution.
The listbox which will not save has an input from another listbox and I'm assuming that this is where the problem is arising.
Sort of. You have several problems.
First, notice that block of code that looks at the variable "OnLoad"? That is incredibly important. At the top of the script there should be a line that says "Dim OnLoad : OnLoad=1". That declaration and assignment are only executed when the worksheet is loaded, or when you exit the script editor. So the block of code looks at the value of OnLoad, and if it's 1 (i.e the worksheet was just loaded) then it sets the cursor selection to Inputs(0).Value, and sets OnLoad equal to 0. By deleting the first line you stop that block of code from ever executing. Further, it looks at Inputs(0).Value, but you have moved the SaveData statement to input 1, so even if it did execute it can't set the selection to the saved value.
The next problem is what you are doing with If Geo<>save. When you first load the worksheet save is a null, because it has never been assigned to anything. I assume what you are trying to do is check whether the input has changed, but it's not quite that simple. When the worksheet is first loaded the input must be the same as when it was saved (because you saved the state of the other listbox), so you need to trap that special case: OnLoad again!
I very recently uploaded new versions of the "Saving the state of controls" worksheets: Saving the state of controls.zip I assume you haven't seen them, because I included listboxes that set the list based on an input. They are not quite what you want, but they are close enough that I think you can figure it out. In those examples, if the list is changed the selection is cleared. If that's not what you want then in the "Extra Components" worksheet: Extra Components.mcd there is another example of a dynamically filled listbox that, if possible, retains the selection.
The listbox which will not save has an input from another listbox and I'm assuming that this is where the problem is arising.
Sort of. You have several problems.
First, notice that block of code that looks at the variable "OnLoad"? That is incredibly important. At the top of the script there should be a line that says "Dim OnLoad : OnLoad=1". That declaration and assignment are only executed when the worksheet is loaded, or when you exit the script editor. So the block of code looks at the value of OnLoad, and if it's 1 (i.e the worksheet was just loaded) then it sets the cursor selection to Inputs(0).Value, and sets OnLoad equal to 0. By deleting the first line you stop that block of code from ever executing. Further, it looks at Inputs(0).Value, but you have moved the SaveData statement to input 1, so even if it did execute it can't set the selection to the saved value.
The next problem is what you are doing with If Geo<>save. When you first load the worksheet save is a null, because it has never been assigned to anything. I assume what you are trying to do is check whether the input has changed, but it's not quite that simple. When the worksheet is first loaded the input must be the same as when it was saved (because you saved the state of the other listbox), so you need to trap that special case: OnLoad again!
I very recently uploaded new versions of the "Saving the state of controls" worksheets: Saving the state of controls.zip I assume you haven't seen them, because I included listboxes that set the list based on an input. They are not quite what you want, but they are close enough that I think you can figure it out. In those examples, if the list is changed the selection is cleared. If that's not what you want then in the "Extra Components" worksheet: Extra Components.mcd there is another example of a dynamically filled listbox that, if possible, retains the selection.
Well, that solved all of my problems. The declaration and change of input were pretty weak mistakes on my part.
You were right about my 'save' variable, I didn't realize that it was initially getting no intput.
Thank you so much for your help, greatly appreciated!
Carl,
can you post the improved sheet of your problem?
i think lots of people are looking for a solution for your problem.
Ya of course, probably should have put it up sooner!
The 'thickness' box is dependent on the 'cross-section' box. The 'level' box is independent.