Solved

Can this be done with Action or Func or Lambda expressions?

Posted on 2010-11-29
5
292 Views
Last Modified: 2012-05-10
I want to take a MsgBox statement such as:

result = MsgBox("I need help!", MsgBoxStyle.OkCancel)

and put it inside a function - let's call it MyFunc - that returns a MsgBoxResult and be able to call it with a statement like this:

result = MyFunc(MsgBox("I need help!", MsgBoxStyle.OkCancel))

I don't understand how to specify MyFunc. Can anyone help?
0
Comment
Question by:AIBMass
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:kraiven
ID: 34230362
What are you trying to achieve?
0
 

Author Comment

by:AIBMass
ID: 34230467
I want to put some code in MyFunc that will determine whether or not to actually show the MsgBox or to simply return a MsgBoxResult. This determination will not require additional parameters.

It has to do with planning some automated testing from which we do not actually want to see a MsgBox. Since we will need this code a number of times, I am trying to write a function to make the determination and get the result rather than

If blah blah
   result = such and such
else
  result = MsgBox.Show(.....)
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 34230546
Sample of MyFunc.  You can pass in a messagebox call as the parameter...

Dim dr As DialogResult = MyFunc(MessageBox.Show("Help", "Caption", MessageBoxButtons.OKCancel))
Private Function MyFunc(ByVal result As DialogResult) As DialogResult

        ''More code??

        Return result



    End Function

Open in new window

0
 
LVL 32

Expert Comment

by:Erick37
ID: 34230619
Misread your question.  The following (in VB.Net) allows you to control whether or not to show the MessageBox.
Private Function MyFunc() As DialogResult



        Dim result As DialogResult



        If 1 = 1 Then ''<< your condition here

           result = MessageBox.Show("Help", "Caption", MessageBoxButtons.OKCancel))

        Else

            result = DialogResult.Cancel

        End If



        Return result



    End Function

Open in new window

0
 

Author Comment

by:AIBMass
ID: 34230798
The accepted solution is what I wanted to achieve, not the later comment.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now