How can I call a class void method to display an msg in a form

Asked

Viewed 485 times

-2

I have a method public void listarProduto(). It needs to have all the user input information. My problem is time to call this method within a MessageBox() in the form for the message to be displayed.

  • If you are trying to access the method without an instance, put public Static void listProduct() and see if it works

  • must be void ?

  • Void defines that the method has no return. Do you want to return something ? an int ? a string ?

  • Show your code, and alerting methods void no return.

  • Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).

  • Can you post the code of what you are trying to do? Why do you want to call a method void within a MessageBox? Why not call him before or after?

Show 1 more comment

2 answers

3

It is not possible, at least if I understood the placement. If the method does something but does not result in anything it cannot be used as expression in a place that expects some information, return method void may be called only as statement.

Or you must modify the method to return what you want to use on MessageBox() or should pick up other information somewhere if it is available.

There is probably an error in this method, because if it lists something even, ie if it is something screen, it already does what it should and does not need to pass it to the MessageBox(), probably should have a `Messagebox() inside it showing what you want.

On the other hand the most likely is that it just delivered the product data to do what you want, then should return an object or a string, that is, it should not deal with the screen, are different responsibilities.

0

The way you’re talking, I think it would be the other way around, the way would be to call the method and run the call from MessageBox() within that method.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.