locked
Conversion from C# to vb.net RRS feed

  • Question

  • As i am using vb.net and Math3D(which can be used in C#) isn't defined in vb.net, then what could i replace Math3D.cube with ?
    I am trying to make a cube using vb.net

    "Private mainCube As Math3D.Cube"

    Please reply

    Thank you !
    Friday, January 2, 2009 4:52 PM

Answers

  • I found the original:

    http://www.codeproject.com/KB/GDI-plus/drawing3dgdi.aspx



    The project has two main classes frmRender, you have translated that one above, and ... Math3D. So translate the other class and add it to your VB.Net project.
    • Proposed as answer by Waleed El-Badry Friday, January 2, 2009 8:50 PM
    • Marked as answer by Xingwei Hu Friday, January 9, 2009 6:00 AM
    Friday, January 2, 2009 8:42 PM
  • Murt2003 said:

    Now i found the problem. I had one additional CompareTo1 function. I don't know why it was there, but i deleted it and added implements to CompareTo function and now i have it all working. Sorry for such a messy trouble :P.

    Thanx !


    This is a common IDE 'quirk'; when implementing an interface, it tries to be clever (which most of the time, it is) and add the signatures for you. If a method exists with the same name, it appends a '1' to the name. Additionally, I've seen an error where it states that a class must implement a specific method, which it does, but it's not recognized. Deleting it and allowing the IDE to recreate the signature - even though it's the same - often solves the issue.

    It's often a good idea to keep all the Implements statements close together so you can manually make sure everything is correct.


    Stephen J Whiteley
    • Marked as answer by Xingwei Hu Friday, January 9, 2009 6:00 AM
    Monday, January 5, 2009 9:00 PM
    Moderator

All replies

  • That's not part of the .Net framework, so to use it in C# you must be using an external library.

    Add a reference to the library from the VB.Net project.
    Friday, January 2, 2009 6:50 PM
  • Yes, i understad, but what could possibly work in vb.net as Math3D.cube works in C#? I was using this page to convert  the entire code from C# to VB.net .
    Entire code C#:

    using System; 
    using System.Collections; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Drawing.Drawing2D; 
    using System.Text; 
    using System.Windows.Forms; 
     
    namespace _DCubeNoGimbalLock 
        public partial class FrmRender : Form 
        { 
            [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")] 
            private static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, System.Int32 dwRop); 
     
            [System.Runtime.InteropServices.DllImportAttribute("user32.dll")] 
            public static extern IntPtr GetDC(IntPtr hwnd); 
     
            [System.Runtime.InteropServices.DllImportAttribute("user32.dll")] 
            public static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc); 
     
            public FrmRender() 
            { 
                InitializeComponent(); 
            } 
     
            Math3D.Cube mainCube; 
            Point drawOrigin; 
     
            private void FrmRender_Load(object sender, EventArgs e) 
            { 
                mainCube = new Math3D.Cube(200, 200, 200); 
                drawOrigin = new Point(pictureBox1.Width / 2, pictureBox1.Height / 2); 
            } 
     
            private void Render() 
            { 
                mainCube.RotateX = (float)tX.Value; 
                mainCube.RotateY = (float)tY.Value; 
                mainCube.RotateZ = (float)tZ.Value; 
     
                pictureBox1.Image = mainCube.DrawCube(drawOrigin); 
            } 
     
            private void tX_Scroll(object sender, EventArgs e) 
            { 
                this.Refresh(); 
            } 
     
            private void tY_Scroll(object sender, EventArgs e) 
            { 
                this.Refresh(); 
            } 
     
            private void tZ_Scroll(object sender, EventArgs e) 
            { 
                this.Refresh(); 
            } 
     
            private void btnReset_Click(object sender, EventArgs e) 
            { 
                tX.Value = 0
                tY.Value = 0
                tZ.Value = 0
     
                chWires.Checked = true
                chFront.Checked = false
                chBack.Checked = false
                chLeft.Checked = false
                chRight.Checked = false
                chTop.Checked = false
                chBottom.Checked = false
     
                mainCube = new Math3D.Cube(100, 200, 75); //Start over 
                this.Refresh(); 
            } 
     
            private void Form1_Paint(object sender, PaintEventArgs e) 
            { 
                Render(); 
            } 
     
            private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 
            { 
                System.Diagnostics.Process.Start("http://vckicks.110mb.com/"); 
            } 
     
            private void chWires_CheckedChanged(object sender, EventArgs e) 
            { 
                mainCube.DrawWires = chWires.Checked; 
                this.Refresh(); 
            }  
     
            private void chFront_CheckedChanged(object sender, EventArgs e) 
            { 
                mainCube.FillFront = chFront.Checked; 
                this.Refresh(); 
            } 
     
            private void chBack_CheckedChanged(object sender, EventArgs e) 
            { 
                mainCube.FillBack = chBack.Checked; 
                this.Refresh(); 
            } 
     
            private void chLeft_CheckedChanged(object sender, EventArgs e) 
            { 
                mainCube.FillLeft = chLeft.Checked; 
                this.Refresh(); 
            } 
     
            private void chRight_CheckedChanged(object sender, EventArgs e) 
            { 
                mainCube.FillRight = chRight.Checked; 
                this.Refresh(); 
            } 
     
            private void chTop_CheckedChanged(object sender, EventArgs e) 
            { 
                mainCube.FillTop = chTop.Checked; 
                this.Refresh(); 
            } 
     
            private void chBottom_CheckedChanged(object sender, EventArgs e) 
            { 
                mainCube.FillBottom = chBottom.Checked; 
                this.Refresh(); 
            } 
                  
        } 

    I needed some examples of creating 3D objects in vb and i only found an example written in C# and as I am using vb.net and i dont know much about C#, i needed to convert it. Now that page gave me everything i needed except that it didnt change Math3D.cube to a code used in vb.
    I hope you can help :P.

    Thank you very much !
    Friday, January 2, 2009 8:03 PM
  • I found the original:

    http://www.codeproject.com/KB/GDI-plus/drawing3dgdi.aspx



    The project has two main classes frmRender, you have translated that one above, and ... Math3D. So translate the other class and add it to your VB.Net project.
    • Proposed as answer by Waleed El-Badry Friday, January 2, 2009 8:50 PM
    • Marked as answer by Xingwei Hu Friday, January 9, 2009 6:00 AM
    Friday, January 2, 2009 8:42 PM
  • I still don't understand why you want to convert the project to C# rather than referencing it in your VB project, but if you must:  load it in SharpDevelop and Compile it.  Convert the project to VB and compile again.
    Friday, January 2, 2009 9:58 PM
  • I want to convert the project to vb.net, because i know nothing about C#. Then i would like to see the difficulties of such an application and I would learn from it as much as i can.

    Anyway, it seems like im not getting it to work.

    I just haven't done such things before and i don't seem like understanding any of what i am trying to do.
    If someone could convert the whole application into vb.net , then i would be very pleased. If not then... i understand :D, maybe this is quite much asked for.

    Thank you !
    Friday, January 2, 2009 10:25 PM
  • I have a conversion of the Math3D class (from Instant VB).  The online converters did not mark the methods implementing interface methods and also did not handle integer division nuances.  The conversion cannot be posted (it's too long for this forum), so contact me for the code.
    Convert between VB, C#, C++, and Java (http://www.tangiblesoftwaresolutions.com)
    Saturday, January 3, 2009 4:07 PM
  • If you convert it in SharpDevelop, to get rid of the error, change the CompareTo function to this:
     

    Public Function CompareTo(ByVal otherFace As Face) As Integer Implements IComparable(Of Face).CompareTo

    Saturday, January 3, 2009 7:04 PM
  • Now if i heard of it, i also tried SharpDevelop and it is a good program xD. To get rid of the error, it didn't work with that:

    Public Function CompareTo(ByVal otherFace As Face) As Integer Implements IComparable(Of Face).CompareTo


    Instead of this, i simply deleted the CompareTo function and the typed it again in the code and the error disappeared. Maybe a bug or something.


    Anyway, i got it working and I would like to thank you all for this.

    Thank you !
    Saturday, January 3, 2009 9:51 PM
  • Actually, my idea of deleting and retyping the CompareTo function gives some bugs. How could i get it work?
    JohnWein, this code gives me 120 errors of not declared and about the compareto funcntion it says it has multiple definitions with identical signatures.

    Need help :P

    Thanx

    • Edited by Murt2003 Sunday, January 4, 2009 11:24 AM
    Sunday, January 4, 2009 11:13 AM
  • Describe the difference in the operation of the C# version and the VB version.
    Sunday, January 4, 2009 11:23 AM
  • There doesn't seem to be any differences. Just the CompareTo function which gives an error.
    Sunday, January 4, 2009 11:33 AM
  • You've been editing.  I'll let the thread set for a few hours until you're finished.  Does the C# version do everything you want?
    Sunday, January 4, 2009 11:39 AM
  • Aaah, the one which gives an error is "Implements IComparable(Of Face)". Sorry for that.

    Yes, C# works great.  You should try my case - Convert the code to vb.net. Open the converted code with VB. Then find the "Implements IComparable(Of Face)" function which gives an error. Delete IComparab"le(Of Face)", so you must delete only that part "le(Of Face)". Then the options bar shows up, you still select the IComparable and then type "(Of Face)" by your own. After you have finished typing, press enter so it would get to the next line. If I didn't press the Enter button, the error didn't disappear. Then i got rid of the error and i could start the application(with bugs).

    Try it.
    Sunday, January 4, 2009 11:54 AM
  • I don't understand what you are doing.  When I run both the C# and the VB versions side-by-side, they perform identically.  All I had to do after SharpDevelop converted the C# code to VB was add the Implements statement to the CompareTo function.
    Sunday, January 4, 2009 3:00 PM
  • Now i found the problem. I had one additional CompareTo1 function. I don't know why it was there, but i deleted it and added implements to CompareTo function and now i have it all working. Sorry for such a messy trouble :P.

    Thanx !
    Sunday, January 4, 2009 9:19 PM
  • Murt2003 said:

    Now i found the problem. I had one additional CompareTo1 function. I don't know why it was there, but i deleted it and added implements to CompareTo function and now i have it all working. Sorry for such a messy trouble :P.

    Thanx !


    This is a common IDE 'quirk'; when implementing an interface, it tries to be clever (which most of the time, it is) and add the signatures for you. If a method exists with the same name, it appends a '1' to the name. Additionally, I've seen an error where it states that a class must implement a specific method, which it does, but it's not recognized. Deleting it and allowing the IDE to recreate the signature - even though it's the same - often solves the issue.

    It's often a good idea to keep all the Implements statements close together so you can manually make sure everything is correct.


    Stephen J Whiteley
    • Marked as answer by Xingwei Hu Friday, January 9, 2009 6:00 AM
    Monday, January 5, 2009 9:00 PM
    Moderator