|
-
Jul 9th, 2007, 02:15 AM
#1
Thread Starter
Hyperactive Member
[2005] Conversion of C code to VB.net
I found the following code posted by Louisda16th at http://www.dreamincode.net/code/snippet533.htm
I am wondering if anyone can help me convert the following code to VB.NET..
I will be thankful for any response..
Code:
/*Created by Louisda16th/Ashwith*/
#include<stdio.h>
#include<math.h>
struct complx solvequad( long double p, long double q, long double r, long double s, long double t);
struct complx
{
long double real;
long double img;
int iscomplex; //0=False, 1 = True
};
void main()
{
int y;
long double a,b,c,d,x1,x2;
struct complx x3;
printf("\n a?");/*Find Coefficients of the equation*/
scanf("%lf",&a);
printf("\n b?");
scanf("%lf",&b);
printf("\n c?");
scanf("%lf",&c);
printf("\n d?");
scanf("%lf",&d);
if (d != 0)
{
x1=0;
/*The for loop finds an approximate solution
for the equation by using Newton-Raphson Method:
x1=x0-(f(x0)/f'(x0))
x2=x1-(f(x1)/f'(x1))
...
...
the solution is more accurate with more iterations*/
for(y=0;y<=100;y++)
{
x2=x1-(((a*x1*x1*x1)+(b*x1*x1)+(c*x1)+d)/((3*a*x1*x1)+(2*b*x1)+c));
x1=x2;
}
printf("\n x1=%lf",x2);
}
else
printf("\n x1=0");
/*After one root has been found, we're left
with a quadratic equation which can easily be solved
using the formula*/
x3 = solvequad(a,b,c,d,x2);
if (x3.iscomplex == 0)
printf("\n x2=%lf\n x3=%lf\n", x3.real +x3.img, x3.real - x3.img);
else
printf("\n x2=%lf+i%lf\n x3=%lf-i%lf\n",x3.real, x3.img,x3.real,x3.img);
}
struct complx solvequad( long double p, long double q, long double r, long double s, long double t)
{
long double a,b,c,i;
struct complx x;
a=p;
b=q+(t*p);
c=(-s)/t;
x.real =((-b)/(2*a));
i=((b*b)-(4*a*c));
if (i>=0)
{
x.img =(sqrt(i))/(2*a);
x.iscomplex = 0;
}
else
{
x.img =(sqrt(-i))/(2*a);
x.iscomplex = 1;
}
return x;
}
Last edited by surya; Jul 9th, 2007 at 09:54 AM.
-
Jul 9th, 2007, 02:19 AM
#2
Re: [2005] Conversion of C# code to VB.net
That code is actually in C not in C#.
-
Jul 9th, 2007, 02:28 AM
#3
Thread Starter
Hyperactive Member
Re: [2005] Conversion of C# code to VB.net
You are right; are there any tools for conversion...
thanks
-
Jul 9th, 2007, 02:30 AM
#4
Re: [2005] Conversion of C# code to VB.net
You might want to try a google search.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 9th, 2007, 03:11 AM
#5
Thread Starter
Hyperactive Member
Re: [2005] Conversion of C# code to VB.net
I checked on google, and found www.tangiblesoftwaresolutions.com.
It doesnt seem to be converting struct properly.
Wondering if you know any sites what would convert the code..
thanks
 Originally Posted by RobDog888
You might want to try a google search.
-
Jul 9th, 2007, 08:05 AM
#6
Re: [2005] Conversion of C# code to VB.net
-
Jul 9th, 2007, 09:34 AM
#7
Re: [2005] Conversion of C# code to VB.net
 Originally Posted by surya
I checked on google, and found www.tangiblesoftwaresolutions.com.
It doesnt seem to be converting struct properly.
Wondering if you know any sites what would convert the code..
thanks
Conversion from C++ to VB is difficult, so there will be adjustments to make after any automatic conversion. Note that the C++ struct is not equivalent to the VB Structure - is this the problem you're referring to? (There is a bug in the current version of C++ to VB Converter which causes the 'struct' keyword to remain on the method header, but this will be fixed on today's build).
-
Jul 9th, 2007, 09:45 AM
#8
Thread Starter
Hyperactive Member
Re: [2005] Conversion of C# code to VB.net
 Originally Posted by David Anton
Conversion from C++ to VB is difficult, so there will be adjustments to make after any automatic conversion. Note that the C++ struct is not equivalent to the VB Structure - is this the problem you're referring to? (There is a bug in the current version of C++ to VB Converter which causes the 'struct' keyword to remain on the method header, but this will be fixed on today's build).
Hi,
Yes, I had this struct problem.
Trust the latest update will convert the code perfectly now...
It will be nice if you can run your latest build on the sample code posted in this thread...
thanks
Last edited by surya; Jul 9th, 2007 at 09:56 AM.
-
Jul 9th, 2007, 09:58 AM
#9
Re: [2005] Conversion of C# code to VB.net
 Originally Posted by surya
Hi,
Yes, I had this struct problem.
Trust the latest update will convert the code perfectly now...
It will be nice if you can run your latest code on my sample code...
thanks
The update later today will certainly not convert the code perfectly (I'm sure you were being funny...).
I will test your sample code and we'll do all we can to produce the best conversion, but the nature of C++ to VB conversion is that only the most contrived examples will convert perfectly. It will save you some grunt work though.
-
Jul 9th, 2007, 10:01 AM
#10
Thread Starter
Hyperactive Member
Re: [2005] Conversion of C code to VB.net
thanks alot david;
it will save lot of my time as I am not very familiar with c...
Last edited by surya; Jul 9th, 2007 at 10:48 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|