|
-
Jan 23rd, 2008, 07:58 PM
#1
Thread Starter
Member
[RESOLVED] Try/Catch
ok can I....
Try
Something
Catch
"I want to call a private sub here"
end try
can this be done?
-
Jan 23rd, 2008, 08:01 PM
#2
Re: Try/Catch
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
-
Jan 23rd, 2008, 08:05 PM
#3
Thread Starter
Member
Re: Try/Catch
yeah will I get an error when I do this..here is the code...
Code:
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
help would be great benifitial to my mental health! LOL
-
Jan 23rd, 2008, 08:08 PM
#4
Re: Try/Catch
You're not matching the methods signature.
VB.Net Code:
Panel_Rest(ByVal sender As System.Object, ByVal e As System.EventArgs)
As you can see, it expects two arguments, an object and an instance of the EventArgs class.
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.
-
Jan 23rd, 2008, 08:16 PM
#5
Thread Starter
Member
Re: Try/Catch
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.
-
Jan 24th, 2008, 12:03 AM
#6
Re: [RESOLVED] Try/Catch
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?
-
Jan 24th, 2008, 09:07 AM
#7
Thread Starter
Member
Re: [RESOLVED] Try/Catch
 Originally Posted by jmcilhinney
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.
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?
-
Jan 24th, 2008, 05:28 PM
#8
Re: [RESOLVED] Try/Catch
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|