Results 1 to 10 of 10

Thread: [2005] Conversion of C code to VB.net

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Question [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.

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2005] Conversion of C# code to VB.net

    That code is actually in C not in C#.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Conversion of C# code to VB.net

    You are right; are there any tools for conversion...
    thanks

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    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



    Quote Originally Posted by RobDog888
    You might want to try a google search.

  6. #6
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Conversion of C# code to VB.net


  7. #7
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: [2005] Conversion of C# code to VB.net

    Quote 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).
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Conversion of C# code to VB.net

    Quote 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.

  9. #9
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: [2005] Conversion of C# code to VB.net

    Quote 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.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    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
  •  



Click Here to Expand Forum to Full Width