Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Call Visual Basic Function in C# Page

DZone's Guide to

Call Visual Basic Function in C# Page

In this post we take a look at how to access a VB class from a page made with C#. Read on to find out more.

· Web Dev Zone
Free Resource

Get the senior executive’s handbook of important trends, tips, and strategies to compete and win in the digital economy.

Sometimes in a real scenario, you need to access a function of a VB class in a C# page, so there is nothing different in this scenario. You just need to create the object of the VB class in your C# page and just use it. I will explain it in detail in the following procedure.

Step 1: Create a ASP.NET empty website named "TestApp" using C#.

Image title

Step 2: Create a Web Form using C# in the website named "Default.aspx".

Image title

Step 3: Create a class file in the website named "MyClass1.vb" using Visual Basic.

Image title

Step 4: Write a function of addition in the VB class that accepts 2 integer values and return the addition of both of the values using another integer variable.

Public Function Add(value1 As Integer, value2 As Integer) As Integer
Dim result = (value1 + value2)
Return result
End Function

Image title

Step 5: Call the addition function of the VB class in the C# page by creating the object of MyClass1.

Print the addition value on the page.

MyClass1 obj = new MyClass1 ();

int addition = obj.Add(2, 3);

Response.Write(addition.ToString());

Image title

Run the page to see the output.

output


Read this guide to learn everything you need to know about RPA, and how it can help you manage and automate your processes.

Topics:
visual basic ,function ,asp.net ,c# ,web dev

Published at DZone with permission of Rahul Bansal, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}