Solved

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

Posted on 2010-11-29
5
301 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

617 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