I have question answer form and I have added below the line of code to add dynamically push button using below lines of code.
Note: ansList - it could be any number
For ansOptions as Integer = 0 To ansList.Ubound dim b as new PushButtonAnswerSet b.Visible = true b.Left = ((ansOptions + 1) *(PushButtonAnswerSet(0).Width + 22)) - 94 b.Top = 190 b.Width = 95 b.Height = 30 b.Bold = true b.Caption = ansList(ansOptions) + "(" + Str(ansOptions + 1) + ")" b.Index = ansOptions + 1 Next mAnsControlsAdded = ansList.Ubound + 1
mAnsControlsAdded : Defined a property in a module
and when the user clicks the push button, automatically Action handlers will trigger and it moves to the next question. And also I have added a shortcut so that if the user presses the particular key, automatically action event will trigger. So I have added a key down event in the form and make the Action handlers code into a common module so that it will use multiple places(Action handlers and Shortcut key).
And before moving to the next question I have below lines of code to remove the current button
//Remove current button for i as Integer = mAnsControlsAdded DownTo 1 PushButtonAnswerSet(i).Close next
So my question is:
when I click the push button it will remove the current button using the above lines of code and binding the next questions with binding the dynamic button again. However, when I click through the shortcut, the above code is not working and giving a null object exception.
Here PushButtonAnswerSet(i) object is always null whenever I click through a shortcut. Any idea?
Any help would be greatly appreciated.