Hi.
I'm trying to use a code library written in C# in visual basic, but i cant figure out how to do it. Here's the library:
i want to be able to use the functions in it in VB. I've tried compile it into a class library and then add it as a reference in visual basic, but it still doesn't work.
mattias

using code written in C#
sss5234
Hi,
I have not tried that download. But in page itself they are tell ing it wont work in vb.net 2003 and may work with vb.net 2005 (not in visual basic).
So, Please check the compatibility of the dll.
Jonathan MacCollum
Can you let me know if you want to achieve this in a old VB 6 App or a VB.Net App
The reason behind this is Operator Overloading is not supported in VB.Net 2003 but it is in VB.Net 2005. For the VB6 App some work would be required to be done in the class itself. Let me know which path are you taking so that I can help you out.
Both will suffice. I originally tried to implement this in a VB 6.0 project, but I was advised to move it to .NET since it wouldn't work in 6.0 and it was "so easy" in .NET
So i tried to download it, but it didn't work out. I guess now that i have gotten VB.NET i could as well take it in it.
Do i really have to make a dll file of it in visual C# before i use it in Visual Basic isn't the whole point of .NET that you're supposed to be able to use functions from each others languages
I also don't understand how the library works. Some of the functions dont have an argument, like isProbablePrime(), how am i supposed to control what number are being tested So if anybody has any idea on how to use this library, or have a suggestion for a better one, I would be gladly appreciated.
S Dano
Where is the library
There is no reason why you shouldn't be able to import and call a C# library from VB.NET, in fact to VB it will look the same as if it was also written in VB, as it's been compiled to the same IL.
You need to define 'doesn't work'. Can you import it Can you call it Do you get the wrong results Do you get an error What does your code look like
Saberinth
Shankar KC
sorry. i saw that i forgot to post the link to the library. this is it: http://www.codeproject.com/csharp/BigInteger.asp
the library is in .cs format, so i couldn't read it in visual basic. First i tried to run it in visual basic, but it didn't work out very well. so i downloaded Visual C# and compiled it to a class library. I'm completly new to .net so this was a bit messy for me. then i took the .dll file and added it as a reference in Visual Basic.
then i wonder, do i have to write imports BigInteger in Visual Basic
the problem is that i cant use the functions in visual basic. i've tried different constelletions of code and they all give different error messages. sometimes i've maneged to use some of the functions in the library, but not all. i dont know why it is like this.
Edward Clements
woho.. it's working :D
now I only have to figure out how to add numbers like c=a+b and such operations
but i get problems when I do like this:
Dim x as BigInteger = New BigInteger()
x= 2 ^ 131 - 1
DSV-Alex
Mattias,
The compatibility of .Net between languages is at runtime or at binary level and not at source code level, so if you create a VB.Net project you cannot add a C# source code file in it and vice versa, hence the need for the dll. And if you still dont want to make a dll from the C# class file and use it as a reference, you can create a class library project for C# add the BigInteger.cs in it and to the solution add a new VB.Net project to it. In the VB.Net Project add a new reference, select the Projects tab and select the C# project. Note that this will still create a dll for the C# project and an Exe for the VB.Net project just that both the projects will be tied to a single solution. I hope I was clear in my explanation.
The isProbablePrime() function that you are having problems with is an overloaded function, it has 2 forms one accepts an argument and the other one just works on the value of the BigInteger variable.
For example:
Dim x as BigInteger = New BigInteger()
x = 3498537393423
If x.isProbablePrime() Then
MessageBox.Show("x is a probable prime.")
End If
The above example was with the function with no argument form.
For the other form the code would look something like this:
Dim x as BigInteger = New BigInteger()
x = 3498537393423
If x.isProbablePrime(200) Then
MessageBox.Show("x is a probable prime.")
End If
According to the page on code project the documentation for the isProbablePrime function looks like this:
In our BigInteger class, we provided two functions that performs probabilitic primality testing of an integer. The first method bool isProbablePrime(int confidence), uses Rabin-Miller's strong pseudoprime test to determine whether the integer is probably prime. The algorithm is described as follows.
Test the number for divisibility by prime numbers below 2000.
Perform strong pseudoprime test on the number using n random bases. The number of random bases used in the test depends on the confidence parameter.
The function returns true if the number passes both step 1 and 2.
The second primality test method bool isProbablePrime() does not require the specification of a confidence parameter. A brief description of the test is given as follows.
Test the number for divisibility by prime numbers below 2000.
Test whether the number is a strong pseudoprime to base 2. If the number passes this test, proceed on to the next step.
Test whether the number is a strong Lucas pseudoprime.
The function returns true if the number passes steps 1, 2 and 3.
I hope this solves your queries,
Amit
HolmesConan
Yeah, I saw in the documentation also that you could use a= New BigInteger("1333745321", 10), but the problem there is that i have to write the decimal expansion of the number, i can't write it in the form 2^a-1
it says it should support the operators +, -, *, /, %, >>, <<, ==, !=, >, <, >=, <=, &, |, ^, ++, --, ~, but i cant get them to work in Visual Basic.
Maybe i'm missing something like I have to call them or importing the library or something, but i don't know what.
CleverHans
I would doubt that would work. As its an Object I would suspect that there are properties and methods which need to be set.
You cant simply do what you trying as it wouldnt know which property of method you are trying to set these values to.
I would suggest that you look at the details on the usage of the component to find out what method/properties you can use.
msdn_haii
Mattias,
Can you let me know if you want to achieve this in a old VB 6 App or a VB.Net App
The reason behind this is Operator Overloading is not supported in VB.Net 2003 but it is in VB.Net 2005. For the VB6 App some work would be required to be done in the class itself. Let me know which path are you taking so that I can help you out.
Amit
LeRainieur
The Following line has new biginteger as it is a Reference Type such as Classes and not a Value Type such as some of the intrinsic data type Integer, boolean
Dim x as BigInteger = New BigInteger()
So what this line does is create a variable and then create a new instance of the class Biginteger creating an Object.
Pranay
rano
and it's also kind of wierd that only some functions show up in the intellisense. I can't get any explanation for this in the documentation.
svashchenko
I still don't understand why you have to write Dim x as BigInteger = New BigInteger() why wouldn't it be enough with just Dim x as BigInteger
Okey, so that's how you're supposed to do it. I thought you should write if isProbablePrime(x) then.
If I get this correct, x.isProbablePrime(200) is a stronger primability test than x.isProbablePrime(), because isProbablePrime() only test with base 2, while isProbablePrime(200) tests with more bases.
But how would one do if one wanted to add to numbers Some of the functions are "shared" and some are not. Why is that How come I can't see some functions when i'm writing the code
I'll try to paste in the new code and see if it works. You'll probably here from me again soon :)