I have a function written in vb
Public Function abc (ByVal x as Integer, ByVal y as String) As String
End Function
I want to call this function on click of a button in C# applcation.
I have a function written in vb
Public Function abc (ByVal x as Integer, ByVal y as String) As String
End Function
I want to call this function on click of a button in C# applcation.
If your VB function is inside a module, you need to call it by specifying the module name.
string result = MyVbModule.abc(1, "Hello");
You may also need to specify the namespace, wich per default is the name of the VB project:
string result = MyDll.MyVbModule.abc(1, "Hello");
Using this post I was able to just call a VB function inside a simple Class module. No VB.dll needed.
I needed to use some Date-math functions written in VB that where huge and almost impossible to rewrite. I had to make my comment an answer so it would fit and be easily understood.
I made a VB Project inside my C# Solution next to the C# project. I added a reference in the C# project to the VB one.
I looked in Object Browser to see how it was referenced. Name of the Project was referenced, twice: "VB_Stuff.VB_Stuff".
In C# Razor Page I put a "using VB_Stuff.VB_Stuff" at the top.
In the Razor Page OnGetAsync where I needed the VB function(s) I declared an object with the name of the VB Class: DateStuff obj = new DateStuff();
Then I called the function (named fTest) with my Model's field . . .
DateStuff obj = new DateStuff();
Dances_Moderated.RecurYesNo =obj.fTest(Dances_Moderated.RecurYesNo.ToString());
I did this right before my Razor Page was going to load and display the Details Page for the "Dances_Moderated" Model.
No .dlls! Just some VB code in a VB class in a VB Project inside a C# Solution. Make sure you right click on the solution to add the project, otherwise from the File menu "New Project" it wants to add a new Solution no matter what you do.
Here is the simple VB Class file with the simple Test function.
Namespace VB_Stuff
Public Class DateStuff
Public Function fTest(ByVal Recurring As String) As String
fTest = Recurring & "xxxxx"
End Function
End Class
End Namespace
objectname.abc(3,"SomeSting");