| | |
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 |
"crystal .net .net2005 30minutes 2008 access add arithmetic array assignment basic binary box button buttons center code combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall listview login math memory mobile module ms mssqlbackend mysql navigate net opacity page pan peertopeervideostreaming picturebox picturebox1 plugin port print printing printpreview problemwithinstallation project record reports" reuse save savedialog serial server sorting sql sqldatbase storedprocedure string structures studio temp textbox timer updown upload useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml





