Newbe question (Linking to a Visual Basic class library)

HaywardIHaywardI Member ✭✭

I want to develope a mobile application for my company using Xamarin.

I have got to grips with basics of Xamarin to the point at which and want to start using my companies standard routines for inter process communications (TCP/IP messages).

All of these standard routines are part of a visual basic class library. I have added a reference to the class library under "project" and I can access the routines in C++ code (e.g. "Produce.Send_message (type, Message);"

When I went to test to see is a message was sent, it initally said it could reference the visual basic runtime, add a NuGet package.

So I did, I found the Microsoft.VisualBasic NuGet runtime and installed that.

Now when I go to test the code, it just hangs and does nothing.

And now I'm stuck.

Before someone says just rewrite into C++ I should say there are a lot of routines coded in the class library that I will want to use (they are all tested and working exteremly well) so I really want to avoid rewriting it all into c++.

Can any one help me?

Best Answer

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Actually I would have said:

    Convert to C# (not C++) as they are both managed OOP .NET languages.

    Maybe it can be made to work. But nobody I know in the commercial software development industry uses/used VB in the last 20 years.

    Wait... You're saying 'VB' - but do you really mean Visual Basic, or at least Visual Basic .NET ? Because if its 30 year old VB that predates .NET, you're hosed and have to bring it up to date.

  • HaywardIHaywardI Member ✭✭

    Hi ClintStLaurent,,

    My apologies. I should have said I want to avoid converting the code to C# as there is so much to convert.. And yes I mean VisualBasic.NET.

  • NMackayNMackay GBInsider, University mod

    @HaywardI said:
    Hi ClintStLaurent,,

    My apologies. I should have said I want to avoid converting the code to C# as there is so much to convert.. And yes I mean VisualBasic.NET.

    There is very limited support for VB.NET

    https://docs.microsoft.com/en-us/xamarin/cross-platform/platform/visual-basic/xamarin-forms

  • HaywardIHaywardI Member ✭✭

    Hi NMackay,

    Yes found that whilst trying to work out what was going on. However, it looked to me like it was giving me the ability to code VB.NET in a Xamarin project. I do not want or need that as I am happy to write the new code in c#.. However, I want to link to a class library DLL for all the standard routines (security, protocol, transmission, encryption, routing, auditing etc). I thought (obviously wrongly) when you built a class library it converted it into binary and could be executed by anything, but clearly there is a dependency on the VB runtime which I hadn't appreciated.

    I also found a post that said something about embedding the VB runtime into the class library itself , but I can't find any posts on how to do that in VS.

    Clint is kind of right in a humours way, but omits to consider the existing standard routines , built about 8 years ago are bullet proof and as the saying goes, if it aint broke, don't fix it. Hence I don't want to re-write and would like to find a way of bridging the c#/VB gap.

    All help appreciated.

  • HaywardIHaywardI Member ✭✭

    NMackey,

    I hear you too, so decided to convert my routines into C#.

    Conversion of first routine surprisingly simple, even if syntax is a little frustrating ;-) But then I started programming Basic on PDP11's (Yes, I am that old).

    Thanks for your help.
    Iain

  • HaywardIHaywardI Member ✭✭

    NMackey/All

    I just tested the new routine for the first time and had a curious result I thought I would share.

    As above I converted my first routine to C# and began testing. It didn't work and just hung as per the results I got when I tested against the VB.NET class library. Discovered I could not debug when testing using a hand set so decided to write a C# console program to test against calling the same class library in C# and it worked first time. That got me thinking! Discovered my wifi security on my handset was blocking the TCP/IP message. Changed my WIFI security and everything work ok. But this isn't the important thing.

    I then thought if I had the same symptom with the C# class library, what if I switched back to my VB.NET class library.

    Holy crap when I ran using the VB.NET library it also WORKED.

    So in summary, you can link a Xamarin C# program to a visual basic class library. All you need to do is add the Nuget Visual Basic runtime package and off you go.

    That said I will convert my common routines (sorry methods) into C# if only for the practice :-)
    Iain

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @HaywardI said:
    Conversion of first routine surprisingly simple, even if syntax is a little frustrating ;-) But then I started programming Basic on PDP11's (Yes, I am that old).

    Not quite at the PDP11 era here... First computer was a Timex-Sinclair. Then a Commodore PET... then VIC20... Then C-64

    into C#. {...} even if syntax is a little frustrating ;-)

    Its a change over. Then one day you'll realize the C# looks normal and the VB seems odd - and wonder when that mental switch happened.

Sign In or Register to comment.