ok can I....
Try
Something
Catch
"I want to call a private sub here"
end try
can this be done?
Printable View
ok can I....
Try
Something
Catch
"I want to call a private sub here"
end try
can this be done?
Of course it can be done:)
VB.Net Code:
Try 'Some code that could throw an exception Catch Ex As Exception CallSomeSub(Ex) End Try
yeah will I get an error when I do this..here is the code...
help would be great benifitial to my mental health! LOLCode:Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim arrPan As Panel() = {Panel3, Panel4, Panel5, Panel6}
Panel2.Top = 25
Panel2.Dock = DockStyle.Bottom
arrPan(panState).Dock = DockStyle.None
arrPan(panState).Top = 2000
panState = panState + 1
arrPan(panState).Top = 25
arrPan(panState).Dock = DockStyle.Fill
Catch ex As Exception
Call Panel_Rest(ex) '<-------- Problem Line
'panState = Nothing
' Panel1.Visible = True
' Panel2.Dock = DockStyle.None
' Panel2.Top = 2000
End Try
End Sub
Public Sub Panel_Rest(ByVal sender As System.Object, ByVal e As System.EventArgs)
panState = Nothing
Panel1.Visible = True
Panel2.Dock = DockStyle.None
Panel2.Top = 2000
End Sub
You're not matching the methods signature.
As you can see, it expects two arguments, an object and an instance of the EventArgs class.VB.Net Code:
Panel_Rest(ByVal sender As System.Object, ByVal e As System.EventArgs)
This method looks like an eventhandler and they should not be called directly. Altough IF you where to call this directly you must pass an object and an eventargs instance to it.
ok I got it. I am not sure what but when I deleted the ByVal items in the Private Sub Panel_Rest line, it now works.
That Panel_Rest method has the signature of an event handler. If you're not using it to handle any events then what are those arguments for? Also, why are you passing the Exception object when you call it if you aren't using it?
I will have a few subs calling the Reset_Panel sub. It sort of resets the form with the beginning panels I have setup. Button One click event has an array of 4 panels. There will be like 4 more button click evens with as much as 15 panels in an array. Once the user sees these via the code in the click event, when the get past the '.length' it would create an exception, at which point I send that to the Reset to reset the panel back to the original where they can choose anothe button with different panels.Quote:
Originally Posted by jmcilhinney
I am a noob here. I remember this kind of structure from BV6 many years ago although new to VB.Net and the try/catch argument. Can this be done another way to simplify the code?
I don't really understand your explanation but basically you shouldn't be calling event handlers directly from code. If you want to execute the same code from multiple places then put it in its own method and call that method from multiple places.