Over a million developers have joined DZone.

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

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

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


Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

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 best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

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

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

{{ parent.tldr }}

{{ parent.urlSource.name }}