Over a million developers have joined DZone.

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 error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

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);


Image title

Run the page to see the output.


What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

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

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}