Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-11-29
5
Medium Priority
?
304 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 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