Solved

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

Posted on 2010-11-29
5
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 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