Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

774 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