Results 1 to 3 of 3

Thread: Can anyone modify this VB code to C++ please?

  1. #1

    Thread Starter
    Fanatic Member Flashbond's Avatar
    Join Date
    Jan 2013
    Location
    Istanbul
    Posts
    646

    Can anyone modify this VB code to C++ please?

    Hi Guys!

    I am very very new to C++. This is a code written in vb.NET previously.
    This is a button click command:
    Code:
    Dim p As New List(Of Long)
                k = 3
                m = 2
                p.Add(m)
                For n = 1 To k
                    For l = 0 To n
                        If m Mod p(l) = 0 Then
                            m = m + 1
                        End If
                    Next l
                    p.Add(m)
                Next n
                Beep()
                Me.TextBox2.Text = m
    I wrote:
    Code:
    				
    				int k = 3;
    				int m = 2;
    				std::list<int> p;
    				p.push_back(m);
    				for( int n = 1; n < k; n++ ) {
    				for( int l = 0; l < n; l++ ) {
    					if ( m % p(l) == 0 );
    					{
                        m = m + 1;
    					};
    };
    					
    				p.push_back(m); 
    				};
    				System::String^ b = m.ToString(); 
    			 textBox2->Text = b;
    	};
    I am sure I am using functions wrong like "push_back".
    Ofcourse it's not working. Can you help me?
    Thanks a lot!
    Last edited by Flashbond; Feb 24th, 2013 at 10:45 PM.

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

    Re: Can anyone modify this VB code to C++ please?

    Code:
    #include <vector>
    
    std::vector<long long> p = std::vector<long long>();
    k = 3;
    m = 2;
    p.push_back(m);
    for (int n = 1; n <= k; n++)
    {
    	for (int l = 0; l <= n; l++)
    	{
    		if (m % p[l] == 0)
    		{
    			m = m + 1;
    		}
    	}
    	p.push_back(m);
    }
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  3. #3

    Thread Starter
    Fanatic Member Flashbond's Avatar
    Join Date
    Jan 2013
    Location
    Istanbul
    Posts
    646

    Re: Can anyone modify this VB code to C++ please?

    Thanks David! It did help much

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