| | |
Help understanding code snippet
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 18
Reputation:
Solved Threads: 0
Hi all, here is a code snippet I'm having trouble understanding.
Assume that for the execution of mySub, that an invoke is required. So the IF condition should be satisfied. Why doesn't this code execute the ELSE section as well? My expectation was that the line: Me.Invoke(SI, New Object() {Text}) would cause the program to execute the Else section as well. Can anybody help me understand why it doesn't? Thanks.
VB.NET Syntax (Toggle Plain Text)
public notinheritable class myClass ------Public Delegate Sub mySubDelegate() ------Public Sub mySub(ByVal Text As String) -----------------If Me.InvokeRequired Then ------------------------Dim SI As New mySubDelegate(AddressOf mySub) ------------------------Me.Invoke(SI, New Object() {Text}) -----------------Else ------------------------ Text = "Something" -----------------End If ------End Sub End class
Assume that for the execution of mySub, that an invoke is required. So the IF condition should be satisfied. Why doesn't this code execute the ELSE section as well? My expectation was that the line: Me.Invoke(SI, New Object() {Text}) would cause the program to execute the Else section as well. Can anybody help me understand why it doesn't? Thanks.
•
•
Join Date: Jul 2007
Posts: 276
Reputation:
Solved Threads: 37
First of all - if you surround your code with "" then people will respond quicker.
Secondly,
in an if statement you follow this line of resaoning
if condition is met then perform the routine then go directly to "end if" do not pass go and do not collect $200. If the condition isn't met and there is an else, then everything that doesn't meet your condition gets the else. Let's say you can only choose chocolate or vanilla ice cream. It would be
Secondly,
in an if statement you follow this line of resaoning
if condition is met then perform the routine then go directly to "end if" do not pass go and do not collect $200. If the condition isn't met and there is an else, then everything that doesn't meet your condition gets the else. Let's say you can only choose chocolate or vanilla ice cream. It would be
VB.NET Syntax (Toggle Plain Text)
if iceCream = chocolate give user chocolate (then you head to the end if) else give user vanilla (then head to the end if) end if
Last edited by rapture; Feb 13th, 2009 at 4:42 pm.
•
•
Join Date: Dec 2008
Posts: 18
Reputation:
Solved Threads: 0
•
•
•
•
First of all - if you surround your code with "" then people will respond quicker.
•
•
•
•
Secondly,
in an if statement you follow this line of resaoning
if condition is met then perform the routine then go directly to "end if" do not pass go and do not collect $200. If the condition isn't met and there is an else, then everything that doesn't meet your condition gets the else. Let's say you can only choose chocolate or vanilla ice cream. It would be
VB.NET Syntax (Toggle Plain Text)
if iceCream = chocolate give user chocolate (then you head to the end if) else give user vanilla (then head to the end if) end if
According to my understanding, which, mind you, is shaky at best, since I'm a vb.net newb, on the line:
VB.NET Syntax (Toggle Plain Text)
Dim SI As New mySubDelegate(AddressOf mySub)
SI is declared as a delegate, pointing to the mySub method. So when it's called on the line:
VB.NET Syntax (Toggle Plain Text)
Me.Invoke(SI, New Object() {Text})
it calls the mySub method a second time. This second time, according to my understanding, doesn't need an invoke. So in effect, the mySub() method should be called twice. Once, when an invoke is required causing the IF part to be executed, and once when an invoke is not required, causing the ELSE part to be executed.
What I'd like to find out is why the line:
VB.NET Syntax (Toggle Plain Text)
Me.Invoke(SI, New Object() {Text})
doesn't cause an invoke to not be required, thus causing the ELSE part to be executed.
Last edited by TriceD; Feb 18th, 2009 at 7:20 am.
![]() |
Similar Threads
- Not understanding Class Scope (C++)
- Troubles understanding iterator (C++)
- Send data on a serial port (C++)
- Making sense of this code snippet in python (Python)
- Need help displaying single database values (ASP.NET)
- Alogrithm Analysis (Computer Science)
- Giving code to posters rather than helping them (IT Professionals' Lounge)
- Threading Issue (C#)
- SubRoutine/Function Code Split (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: how to print data from datagrid view ?
- Next Thread: Opening word 2007 hijacks embedded Instance of Word 2007 in vb.net
| Thread Tools | Search this Thread |
.net .net2008 2008 access add advanced application array assignment basic beginner box browser button buttons center click client code combo convert cpu cuesent data database datagrid datagridview datetimepicker designer dissertation dissertations dissertationtopic eclipse editvb.net employees excel exists filter forms function html images isnumericfuntioncall listview map mobile module msaccess mssqlbackend mysql net number open page pan panel pdf picturebox picturebox2 port position print printing printpreview read record regex reuse right-to-left save search serial settings socket sorting sqldatbase sqlserver storedprocedure temp textbox timer timespan transparency txttoxmlconverter usercontol vb vb.net vba vbnet vista visual visualbasic visualbasic.net visualstudio.net web winsock wpf wrapingcode xml year





