i have a sub that takes a tabPage as an argument. a tab page is cleared when a button on that page is clicked.
with option strict on, I get a cast error even when the sub has NO code in it. what is going on?
Printable View
i have a sub that takes a tabPage as an argument. a tab page is cleared when a button on that page is clicked.
with option strict on, I get a cast error even when the sub has NO code in it. what is going on?
Post your code and what is the error exactly.
VB Code:
Private Sub tab_25_btnClearAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles tab_25_btnClearAll.Click 'Dim ctrl As TabControl = CType(sender, TabControl) 'Client.ClearTabControl(ctrl) 'tab_25_optNo.Checked = True End Sub
the error is :"Specified cast is not allowed.
here's what's going on: option strict is on. when I hit F5, I get build errors and I chooses 'yes' to continue (I think that's the problem) then, when I click this button, I get the error. Notice that the code inside the routine is commented out. the error highlights the sub declaration section.
NEVER continue with build errors. It's just not worth..
Try DirectCast function instead of Ctype function .
Why would that matter? The only difference between the two is CType can work with value and reference types whereas DirectCast only works with reference types.Quote:
Originally posted by Pirate
Try DirectCast function instead of Ctype function .
What type of control is tab_25_btnClearAll? Is it a button? If so then sender is probably the button and not a tabcontrol hence the error. Although the designer should be picking that up at compile time.