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

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

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


Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

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.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}