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
Solved

Please tell me how to convert this C# to VB.NET

Posted on 2014-11-13
7
209 Views
Last Modified: 2014-11-17
        private void button1_Click(object sender, EventArgs e) {
            const string SERVER_URL = "My.Settings.ReportServerURL";
            const string REPORT_PATH = "My.Settings.ReportPath";

            var p = new ReportParameter("name", "val");
            var rv = new ReportViewer() {
                AutoSize = true,
                ProcessingMode = ProcessingMode.Remote
            };
            rv.ServerReport.ReportServerUrl = new Uri(SERVER_URL);
            rv.ServerReport.ReportPath = REPORT_PATH;
            rv.ServerReport.SetParameters(p);
            rv.RefreshReport();
            rv.RenderingComplete += (sender2, eventArgs) => rv.PrintDialog(new PrinterSettings() {
                PrintRange = PrintRange.SomePages,
                FromPage = 1,
                ToPage = 2,
                PrinterName = "MYPRINTER"
            });
        }

Open in new window


all is fine except i cannot figure out the syntax in VB.Net of this line

rv.RenderingComplete += (sender2, eventArgs) => rv.PrintDialog(new PrinterSettings() {
                PrintRange = PrintRange.SomePages,
                FromPage = 1,
                ToPage = 2,
                PrinterName = "MYPRINTER"
            }

Open in new window

0
Comment
Question by:FamousMortimer
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 50 total points
ID: 40440434
The => is a lambda expression:
http://msdn.microsoft.com/en-us/library/bb311046.aspx

The VB.Net equivalent is here:
http://msdn.microsoft.com/en-us/library/bb531253.aspx
where you have to write that one line as a function
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40440571
You need to do it in this way:
	Private Sub OnClick(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
		Const SERVER_URL As String = "My.Settings.ReportServerURL"
		Const REPORT_PATH As String = "My.Settings.ReportPath"

		Dim p = New ReportParameter("name", "val")
		Dim rv = New ReportViewer() With {.AutoSize = True, .ProcessingMode = ProcessingMode.Remote}
		rv.ServerReport.ReportServerUrl = New Uri(SERVER_URL)
		rv.ServerReport.ReportPath = REPORT_PATH
		rv.ServerReport.SetParameters(p)
		rv.RefreshReport()
		AddHandler rv.RenderingComplete, AddressOf OnRenderingComplete
	End Sub

	Private Sub OnRenderingComplete(ByVal sender As Object, ByVal e As RenderingCompleteEventArgs)
		Dim rv As ReportViewer = TryCast(sender, ReportViewer)
		If Not rv Is Nothing Then
			rv.PrintDialog(New PrinterSettings() With { .PrintRange = PrintRange.SomePages, .FromPage = 1, .ToPage = 2, .PrinterName = "MYPRINTER" }
		End If
	End Sub

Open in new window


VB.NET, currently does not allow Lambda based sub event handlers.

http://10rem.net/blog/2010/04/16/tip-anonymous-event-handlers-in-vbnet

-saige-
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 200 total points
ID: 40440676
@it_saige

Your article reference is 4 years old. Lambdas work just fine in VS 2013:

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AddHandler Me.Button1.Click, Function(snd, evt) MessageBox.Show("Click!")
    End Sub
End Class

Open in new window


Screenshot
P.S.

Sub works as well  : )
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 33

Accepted Solution

by:
it_saige earned 250 total points
ID: 40440723
Aha.  Thanks Kaufmed.  I just tried and confirmed in VS2010.  So I can say that atleast since .NET 3.5, this has been resolved.  Modifed code example above:
	Private Sub OnButtonClick(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
		Const SERVER_URL As String = "My.Settings.ReportServerURL"
		Const REPORT_PATH As String = "My.Settings.ReportPath"

		Dim p = New ReportParameter("name", "val")
		Dim rv = New ReportViewer() With {.AutoSize = True, .ProcessingMode = ProcessingMode.Remote}
		rv.ServerReport.ReportServerUrl = New Uri(SERVER_URL)
		rv.ServerReport.ReportPath = REPORT_PATH
		rv.ServerReport.SetParameters(p)
		rv.RefreshReport()
		AddHandler rv.RenderingComplete, Sub(sender2 As Object, e2 As RenderingCompleteEventArgs)
									   Dim rv2 As ReportViewer = TryCast(sender, ReportViewer)
									   If Not rv2 Is Nothing Then
										   rv2.PrintDialog(New PrinterSettings() With {.PrintRange = PrintRange.SomePages, .FromPage = 1, .ToPage = 2, .PrinterName = "MYPRINTER"})
									   End If
								   End Sub
	End Sub

Open in new window


-saige-
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 40440924
ps.  My link to lambda support in VB states it is supported from VS2008 onwards
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40440942
As I recall, multi-line lambdas weren't introduced in VB until VS 2010/2012.  I'm getting older, though, so I could be off my rocker  ; )
0
 
LVL 10

Author Closing Comment

by:FamousMortimer
ID: 40447944
Thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Directions API to Map URL -C#? 3 37
Convert datetime to time string 10 28
vb.net class 3 21
Create a datatable in vb.net dynamically 1 22
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

861 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