Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 397395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:38:45+00:00 2026-05-12T16:38:45+00:00

It appears that VB in VS8 doesn’t support/convert lambda expressions with a statement body.

  • 0

It appears that VB in VS8 doesn’t support/convert lambda expressions with a statement body. I’m using them in my C# application, but now must convert it to VB.

I’m creating a whole bunch of controls dynamically, and I want to be able to give them event handlers on the fly. This is so I can build a dynamic user interface from a database. In the following code I’ll create a form and a checkbox, make the checkbox control the form’s visibility, add a few method handlers to the form, and then add the newly created checkbox to a pre-existing form/panel/etc. Handlers for the form, for instance, affect the checkbox:

  // Inside some loop creating a lot of these forms and matching checkboxes
      Form frmTemp = frmTestPanels[i];  // New form in array
      CheckBox chkSelectPanel;          // New checkbox that selects this panel
      chkSelectPanel = new CheckBox();
      chkSelectPanel.Text = SomeName;   // Give checkbox a label
      chkSelectPanel.Click += (ss, ee) =>  // When clicked
      {
          label1.Text = SomeName;       // Update a label
          if (chkSelectPanel.Checked)   // Show or hide the form
          {
              frmTemp.Show();
          }
          else
          {
              frmTemp.Hide();
          }
      };

      frmTemp.VisibleChanged += (ss, ee) =>  // When form visibility changes
      {
          chkSelectPanel.Checked = frmTemp.Visible;  // Reflect change to checkbox
          ConfigurationFileChanged = true;   // Update config file later
      };

      frmTemp.FormClosing += (ss, ee) =>     // When the form closes
      {   // We're only pretending to close the form - it'll sit around until needed
          chkSelectPanel.Checked = false;    // Update the checkbox
          frmTemp.Hide();                    // Hide the form
          ee.Cancel = true;                  // Cancel the close
      };

      flpSelectGroup.Controls.Add(chkSelectPanel); // Add checkbox to flow layout panel
  // End of loop creating a bunch of these matching forms/checkboxes

Of course, I’m getting the conversion error:

VB does not support anonymous methods/lambda expressions with a statement body

I really liked the ability to create everything on the fly, and then let the objects handle themselves – I don’t need to add any special functions that figure out which form is giving the close event so it can search for the right checkbox and update the checkbox – It Just Works (TM).

Unfortunately it needs to be converted to VB.

What is the best way to convert lambda/anonymous statement bodies into something that will work in VB, especially when one needs to create many of them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T16:38:46+00:00Added an answer on May 12, 2026 at 4:38 pm

    Wait for the nearest release of .NET 4, it will support things like this in VB. Don’t see other alternative.

    Ugly alternatives are:

    1. This work, but you can use a single statement in a function.

      AddHandler Me.Click, Function(o, e) MessageBox.Show("text")
      
    2. Create some regular Sub Foo

      Public Sub Foo(ByVal o As Object, ByVal e As EventArgs)
           MessageBox.Show("text")
      End Sub
      

      and use AddHandler to bind it to an event

      AddHandler Me.Click, AddressOf Foo
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 188k
  • Answers 188k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer With the help of this blog: http://goneale.com/2009/03/04/using-metadatatype-attribute-with-aspnet-mvc-xval-validation-framework/ I was able… May 12, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer devenv.exe /installvstemplates http://msdn.microsoft.com/en-us/library/ms247116.aspx May 12, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer I'd suggest you put both of them inside a grid… May 12, 2026 at 5:39 pm

Related Questions

I need to impersonate a user in a VB.NET 2008 WinForms application, so that
Looking for some direction here as I'm running into some migration problems. We have
I'm looking for some advice for unit-testing in a manner that doesn't leave test
I have written a COM component in unmanaged C++ to provide customers access to
You can save a SQL Server 2000 DTS package as a VB .BAS file.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.