473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to return value from invoked function?

How do I get this to work? It always returns False, even though I can see
"This is True!" in the debug window. Do I have to invoke functions
differently than subs?

Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As Integer)
As Boolean
Private Function IsLvItemChecked(ByVal ClientID As Integer) As Boolean
If lvServers.InvokeRequired = True Then
lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf IsLvItemChecked),
ClientID)
Else
For i As Integer = 0 To lvServers.CheckedItems.Count - 1
If CInt(lvServers.CheckedItems(i).SubItems(1).Text) = ClientID Then
Debug.WriteLine("This is true!")
Return True
End If
Next
Return False
End If
End Function
Aug 6 '07 #1
7 10259
"Terry Olsen" <to******@hotmail.comschrieb
How do I get this to work? It always returns False, even though I
can see "This is True!" in the debug window. Do I have to invoke
functions differently than subs?

Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As
Integer) As Boolean
Private Function IsLvItemChecked(ByVal ClientID As Integer) As
Boolean If lvServers.InvokeRequired = True Then
lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf
IsLvItemChecked), ClientID)
Else
For i As Integer = 0 To lvServers.CheckedItems.Count - 1
If CInt(lvServers.CheckedItems(i).SubItems(1).Text) = ClientID Then
Debug.WriteLine("This is true!")
Return True
End If
Next
Return False
End If
End Function

I don't completely understand the example. What returns false? The Debug
statement doesn't evaluate a function return value. It is based on an
expression, a comparsion comparing two integers (ClientID and Cint).
In other words, the debug output is not based on the function return value.

Using the delegate, you never evaluate the returned value, thus you can not
say whether it's True or False. If you wanted to do it, just look at the
return value of the Invoke function.
Armin

Aug 6 '07 #2
Terry Olsen wrote:
How do I get this to work? It always returns False, even though I can see
"This is True!" in the debug window. Do I have to invoke functions
differently than subs?

Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As Integer)
As Boolean
Private Function IsLvItemChecked(ByVal ClientID As Integer) As Boolean
If lvServers.InvokeRequired = True Then
lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf IsLvItemChecked),
ClientID)
Else
For i As Integer = 0 To lvServers.CheckedItems.Count - 1
If CInt(lvServers.CheckedItems(i).SubItems(1).Text) = ClientID Then
Debug.WriteLine("This is true!")
Return True
End If
Next
Return False
End If
End Function
The invoked function returns the value just fine, and the Invoke method
returns it to the calling code, but as you don't get the return value
from the Invoke method, the value is gone.

Get the return value, cast it to boolean and return it.

--
Göran Andersson
_____
http://www.guffa.com
Aug 6 '07 #3
I must be missing something here. I AM returning the boolean values. Look at
the "Return True" and "Return False" code lines.

I call this code with :

Dim x as boolean=IsLvItemChecked(ClientID)

It always returns x=false, even though the ClientID and CInt(expression) are
equal (hence the "This is true!" in the debug window). Directly after that
Debug.Writeline statement, is coded "Return True". Yet I still get a False.

"Göran Andersson" <gu***@guffa.comwrote in message
news:O0**************@TK2MSFTNGP02.phx.gbl...
Terry Olsen wrote:
>How do I get this to work? It always returns False, even though I can see
"This is True!" in the debug window. Do I have to invoke functions
differently than subs?

Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As
Integer) As Boolean
Private Function IsLvItemChecked(ByVal ClientID As Integer) As Boolean
If lvServers.InvokeRequired = True Then
lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf
IsLvItemChecked), ClientID)
Else
For i As Integer = 0 To lvServers.CheckedItems.Count - 1
If CInt(lvServers.CheckedItems(i).SubItems(1).Text) = ClientID Then
Debug.WriteLine("This is true!")
Return True
End If
Next
Return False
End If
End Function

The invoked function returns the value just fine, and the Invoke method
returns it to the calling code, but as you don't get the return value from
the Invoke method, the value is gone.

Get the return value, cast it to boolean and return it.

--
Göran Andersson
_____
http://www.guffa.com

Aug 7 '07 #4

"Armin Zingler" <az*******@freenet.dewrote in message
news:eS**************@TK2MSFTNGP04.phx.gbl...
"Terry Olsen" <to******@hotmail.comschrieb
>How do I get this to work? It always returns False, even though I
can see "This is True!" in the debug window. Do I have to invoke
functions differently than subs?

Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As
Integer) As Boolean
Private Function IsLvItemChecked(ByVal ClientID As Integer) As
Boolean If lvServers.InvokeRequired = True Then
lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf
IsLvItemChecked), ClientID)
Else
For i As Integer = 0 To lvServers.CheckedItems.Count - 1
If CInt(lvServers.CheckedItems(i).SubItems(1).Text) = ClientID Then
Debug.WriteLine("This is true!")
Return True
End If
Next
Return False
End If
End Function


I don't completely understand the example. What returns false?
The function 'IsLvItemChecked' returns false.

Dim x as boolean=IsLvItemChecked(ClientID)

x is false every time, even when it should be true.
>The Debug
statement doesn't evaluate a function return value. It is based on an
expression, a comparsion comparing two integers (ClientID and Cint).
In other words, the debug output is not based on the function return
value.
Yes, I know that. The debug statement is my troubleshooting tool. I know the
comparison of the two integers are equal, because it is writing "This is
true!" in the debug window! Get it? The next statement after the debug line
is the "Return True" line. So If I see "This is true!" in my debug window, I
should see x=True. That is not happening. The x variable is alway false,
even when it "Return's True".
>
Using the delegate, you never evaluate the returned value,
So what am I missing here? How do I evaluate the returned value? I thought I
was doing that in the calling code....Is there something else I should be
doing to get the returned value from the delegate? This routine works fine
when I call it from the same thread (because it's not invoking the
delegate). But when I call it from another thread, it always returns false.
>thus you can not
say whether it's True or False.
Yes I can. The calling code told me so. The fact that "This is true!"
appears in the debug window tells me that it should have returned True when,
in fact, it returned False.
>If you wanted to do it, just look at the return value of the Invoke
function.
Been there, done that. Doesn't work.
Aug 7 '07 #5
Terry Olsen wrote:
I must be missing something here. I AM returning the boolean values. Look at
the "Return True" and "Return False" code lines.
Yes, as I said, the invoked function returns the value just fine, but
the code that invokes the method just throws away the return value.

Look at the lvServers.Invoke line.
I call this code with :

Dim x as boolean=IsLvItemChecked(ClientID)

It always returns x=false, even though the ClientID and CInt(expression) are
equal (hence the "This is true!" in the debug window). Directly after that
Debug.Writeline statement, is coded "Return True". Yet I still get a False.
Yes, of course you do. The return value of the method is initialised to
zero (false) when the method starts. The code in the method just invokes
a method (which happens to be the same method) in another thread, it
never sets the return value. Therefore the initialised value is returned.
"Göran Andersson" <gu***@guffa.comwrote in message
news:O0**************@TK2MSFTNGP02.phx.gbl...
>Terry Olsen wrote:
>>How do I get this to work? It always returns False, even though I can see
"This is True!" in the debug window. Do I have to invoke functions
differently than subs?

Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As
Integer) As Boolean
Private Function IsLvItemChecked(ByVal ClientID As Integer) As Boolean
If lvServers.InvokeRequired = True Then
lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf
IsLvItemChecked), ClientID)
Else
For i As Integer = 0 To lvServers.CheckedItems.Count - 1
If CInt(lvServers.CheckedItems(i).SubItems(1).Text) = ClientID Then
Debug.WriteLine("This is true!")
Return True
End If
Next
Return False
End If
End Function
The invoked function returns the value just fine, and the Invoke method
returns it to the calling code, but as you don't get the return value from
the Invoke method, the value is gone.

Get the return value, cast it to boolean and return it.

--
Göran Andersson
_____
http://www.guffa.com


--
Göran Andersson
_____
http://www.guffa.com
Aug 7 '07 #6
"Terry Olsen" <to******@hotmail.comschrieb
>
"Armin Zingler" <az*******@freenet.dewrote in message
news:eS**************@TK2MSFTNGP04.phx.gbl...
"Terry Olsen" <to******@hotmail.comschrieb
How do I get this to work? It always returns False, even though
I can see "This is True!" in the debug window. Do I have to
invoke functions differently than subs?
>
Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID
As Integer) As Boolean
Private Function IsLvItemChecked(ByVal ClientID As Integer) As
Boolean If lvServers.InvokeRequired = True Then
lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf
IsLvItemChecked), ClientID)
Else
For i As Integer = 0 To lvServers.CheckedItems.Count - 1
If CInt(lvServers.CheckedItems(i).SubItems(1).Text) = ClientID
Then Debug.WriteLine("This is true!")
Return True
End If
Next
Return False
End If
End Function

I don't completely understand the example. What returns false?

The function 'IsLvItemChecked' returns false.

Dim x as boolean=IsLvItemChecked(ClientID)

x is false every time, even when it should be true.
You didn't show where you check the return value of the function, that's why
I asked. In addition, in the subject you was referring to the return value
from an invoked function. In the code you posted, you ignore the return
value. That's why I asked "what returns false?".
The Debug
statement doesn't evaluate a function return value. It is based on
an expression, a comparsion comparing two integers (ClientID and
Cint). In other words, the debug output is not based on the
function return value.

Yes, I know that. The debug statement is my troubleshooting tool. I
know the comparison of the two integers are equal, because it is
writing "This is true!" in the debug window! Get it? The next
statement after the debug line is the "Return True" line. So If I
see "This is true!" in my debug window, I should see x=True. That is
not happening. The x variable is alway false, even when it "Return's
True".
You are ignoring the return value of the Invoke function. Return it to the
caller and you will get the correct value.
Using the delegate, you never evaluate the returned value,

So what am I missing here? How do I evaluate the returned value? I
thought I was doing that in the calling code....Is there something
else I should be doing to get the returned value from the delegate?
This routine works fine when I call it from the same thread (because
it's not invoking the delegate). But when I call it from another
thread, it always returns false.
see above
thus you can not
say whether it's True or False.

Yes I can. The calling code told me so. The fact that "This is
true!" appears in the debug window tells me that it should have
returned True when, in fact, it returned False.
I was referring to your statement saying that the invoked function always
returns False. As you ignore the function return value, I stated that you
can not say whether it's True or False.
If you wanted to do it, just look at the return value of the
Invoke function.

Been there, done that. Doesn't work.
No, you ignore the return value of the Invoke function. :)
Armin

Aug 7 '07 #7
Okay, lightbulb comes on....again. I missed the difference between the
"Invoked Function" and the "Invoke Function" :)

Thanks for setting me straight...both of you....

"Armin Zingler" <az*******@freenet.dewrote in message
news:ug**************@TK2MSFTNGP05.phx.gbl...
"Terry Olsen" <to******@hotmail.comschrieb
>>
"Armin Zingler" <az*******@freenet.dewrote in message
news:eS**************@TK2MSFTNGP04.phx.gbl...
"Terry Olsen" <to******@hotmail.comschrieb
How do I get this to work? It always returns False, even though
I can see "This is True!" in the debug window. Do I have to
invoke functions differently than subs?

Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID
As Integer) As Boolean
Private Function IsLvItemChecked(ByVal ClientID As Integer) As
Boolean If lvServers.InvokeRequired = True Then
lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf
IsLvItemChecked), ClientID)
Else
For i As Integer = 0 To lvServers.CheckedItems.Count - 1
If CInt(lvServers.CheckedItems(i).SubItems(1).Text) = ClientID
Then Debug.WriteLine("This is true!")
Return True
End If
Next
Return False
End If
End Function
I don't completely understand the example. What returns false?

The function 'IsLvItemChecked' returns false.

Dim x as boolean=IsLvItemChecked(ClientID)

x is false every time, even when it should be true.

You didn't show where you check the return value of the function, that's
why I asked. In addition, in the subject you was referring to the return
value from an invoked function. In the code you posted, you ignore the
return value. That's why I asked "what returns false?".
The Debug
statement doesn't evaluate a function return value. It is based on
an expression, a comparsion comparing two integers (ClientID and
Cint). In other words, the debug output is not based on the
function return value.

Yes, I know that. The debug statement is my troubleshooting tool. I
know the comparison of the two integers are equal, because it is
writing "This is true!" in the debug window! Get it? The next
statement after the debug line is the "Return True" line. So If I
see "This is true!" in my debug window, I should see x=True. That is
not happening. The x variable is alway false, even when it "Return's
True".

You are ignoring the return value of the Invoke function. Return it to the
caller and you will get the correct value.
Using the delegate, you never evaluate the returned value,

So what am I missing here? How do I evaluate the returned value? I
thought I was doing that in the calling code....Is there something
else I should be doing to get the returned value from the delegate?
This routine works fine when I call it from the same thread (because
it's not invoking the delegate). But when I call it from another
thread, it always returns false.

see above
thus you can not
say whether it's True or False.

Yes I can. The calling code told me so. The fact that "This is
true!" appears in the debug window tells me that it should have
returned True when, in fact, it returned False.

I was referring to your statement saying that the invoked function always
returns False. As you ignore the function return value, I stated that you
can not say whether it's True or False.
If you wanted to do it, just look at the return value of the
Invoke function.

Been there, done that. Doesn't work.

No, you ignore the return value of the Invoke function. :)
Armin

Aug 7 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michael Satterwhite | last post by:
I wanted to centralize connection to a MySQL database, so I created a function that reads (eliminating extraneous) function connectDB() { $db = mysql_connect(-------);...
5
by: Bob | last post by:
Hi, I have a std::vector, say myVec, of some user defined object, say myOb. In my code, I have a function that searches myVec for a particular myOb. The way I was doing this was searching...
4
by: gsyoon | last post by:
hi, all. I'm trying to make a "framework" to store the return value of a function to a global memory. My first attempt was 1) void store_to_global( char * type_name ) { if ( strcmp(...
1
by: Seong-Kook Shin | last post by:
Hi. Just curiocity, Because of pre-ANSI C, it is possible to have a function without specifying return type of a function (which makes the return type 'int', though) and give no 'return'...
1
by: Dan | last post by:
hi ng, i want to give the invoker of my application information whether application has passed successfully. it shall get scheduled, and if the exeution did not pass, it should be repeated some...
3
by: b_naick | last post by:
I have a class file in my ASP .NET C# application - defined as follows: namespace ABC { public class BizObj { public Style GetVal(int id) { Style temp = new Style(); // run some db queries...
11
by: igor.lautar | last post by:
Hi, How can I get the address of return value in function? ex. int function(int argument) { int *arg_address; int *rtn_address;
4
by: shapper | last post by:
Hello, I have a function inside a compiled class which code is as follows: Public Function Send() As Boolean ' Try
19
Dheeraj Joshi
by: Dheeraj Joshi | last post by:
Hi... I have a php script which has a function call and function returns a value. But when i open it in browser and refresh the page the return value will get added to the old value. Code...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.