VB to C++ conversion

Discussion in 'C++' started by Alex, Dec 3, 2004.

  1. Alex

    Alex Guest

    I need to transfer a Visual Basic program to C++ (stop laughing at the
    use of VB, as I didn't write it). The program in question is ~3500
    lines long, so it would be VERY unpleasant to convert it by hand. In
    adition, only the sintax on a line to line basis needs be transfered as
    this program is almost entirely computational, no UI or anything more
    complicated than If, For, Case and While statements. Essentially, I am
    looking for a sintax converter. Does anyone know of any?
     
    Alex, Dec 3, 2004
    #1
    1. Advertising

  2. Alex

    Phlip Guest

    Alex wrote:

    > I need to transfer a Visual Basic program to C++ (stop laughing at the
    > use of VB, as I didn't write it). The program in question is ~3500
    > lines long, so it would be VERY unpleasant to convert it by hand. In
    > adition, only the sintax on a line to line basis needs be transfered as
    > this program is almost entirely computational, no UI or anything more
    > complicated than If, For, Case and While statements. Essentially, I am
    > looking for a sintax converter. Does anyone know of any?


    If the program is purely computational, follow this strategy. Download a
    light C++ unit test rig, such as NanoCppUnit or CppUnitLite.

    (CppUnit itself is hard to use, and somewhat derivative.)

    Write a test case that calls system() or popen(), and calls the legacy VB
    program's executable.

    Pass to that program its simplest possible input. Collect the output into a
    string, or something, and parse out its numbers.

    (At this point, if you are completely adept at ActiveX, you could build a
    DLL in VB and call it from ATL in C++, but don't even start without at least
    a year's experience in COM in C++...)

    Now your test case is going to call a new C++ function, that does not exist
    yet. Pass into the function that same simplest input, and collect its
    output. Write an ASSERT_EQUAL() statement that matches the new output to the
    legacy output.

    Run the test and predict failure.

    Now add the minimum amount of C++ code required to pass that test.

    Write another test case, and repeat this procedure for each of the source
    code's abilities.

    Stop occassionally to refactor the C++, running the tests after the fewest
    possible edits. Extract duplicated statements into new methods. Along this
    process, objects may appear. They might not be the same as the objects in
    the legacy VB code. This is a good thing.

    I used that technique, between BASIC and Ruby, to extract an old LParser
    algorithm and produce this project:

    http://flea.sourceforge.net/

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Dec 3, 2004
    #2
    1. Advertising

  3. Alex wrote:

    > I need to transfer a Visual Basic program to C++ (stop laughing at the
    > use of VB, as I didn't write it). The program in question is ~3500
    > lines long, so it would be VERY unpleasant to convert it by hand. In
    > adition, only the sintax on a line to line basis needs be transfered as
    > this program is almost entirely computational, no UI or anything more
    > complicated than If, For, Case and While statements. Essentially, I am
    > looking for a sintax converter. Does anyone know of any?



    If your program is written in VB .NET, then you may encapsulate it to a
    class (if it isn't), and make it a .NET dll which will be callable from
    C++ (and any other .NET language).

    Then you can continue developing it in C++.




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Dec 3, 2004
    #3
  4. Alex

    Phlip Guest

    Ioannis Vranos wrote:

    > > I need to transfer a Visual Basic program to C++ (stop laughing at the
    > > use of VB, as I didn't write it). The program in question is ~3500
    > > lines long, so it would be VERY unpleasant to convert it by hand. In
    > > adition, only the sintax on a line to line basis needs be transfered as
    > > this program is almost entirely computational, no UI or anything more
    > > complicated than If, For, Case and While statements. Essentially, I am
    > > looking for a sintax converter. Does anyone know of any?

    >
    >
    > If your program is written in VB .NET, then you may encapsulate it to a
    > class (if it isn't), and make it a .NET dll which will be callable from
    > C++ (and any other .NET language).
    >
    > Then you can continue developing it in C++.


    Doesn't that give you the choice of either Managed C++ or #import and all
    the COM wrapper stuff?

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Dec 3, 2004
    #4
  5. * Alex:
    > I need to transfer a Visual Basic program to C++ (stop laughing at the
    > use of VB, as I didn't write it). The program in question is ~3500
    > lines long, so it would be VERY unpleasant to convert it by hand. In
    > adition, only the sintax on a line to line basis needs be transfered as
    > this program is almost entirely computational, no UI or anything more
    > complicated than If, For, Case and While statements. Essentially, I am
    > looking for a sintax converter. Does anyone know of any?


    Since nobody's mentioned this yet, there are VB to Java converters, and
    there are Java to C++ converters. Google (I did, earlier, but got
    sidetracked by something else). Probably it won't work but might be
    worth a try -- let us know... :)

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Dec 3, 2004
    #5
  6. Phlip wrote:

    > Doesn't that give you the choice of either Managed C++ or #import and all
    > the COM wrapper stuff?



    I did not understand the question. May you explain what do you mean?

    As a note, "Managed C++" is not the official term (although this term is
    also used even in some MS sites). The official term is "managed extensions".

    In the current version of VS, ISO C++ code compiles in CLR mode, however
    you can not use all ISO C++ features on managed types.

    Things will improve in VS 2005 (templates will be able to be used on
    managed types along with generics), and vastly improve in the release
    after that.


    In any case, ISO C++ code compiles everywhere including .NET.




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Dec 3, 2004
    #6
  7. Ioannis Vranos wrote:

    > I did not understand the question. May you explain what do you mean?



    I rechecked it and I think you mean that it leaves us with either
    "managed extensions" (and upcoming C++/CLI which will replace them), or
    COM and other unmanaged stuff.

    Actually this is not exactly the case. It leaves us with either "managed
    extensions" *and* ISO C++, or ISO C++ and the other unmanaged stuff.

    More precisely, the other unmanaged stuff can also be compiled in
    managed mode.


    However ISO C++ can be entirely managed and this will be the case in the
    upcoming releases, since also C++ becomes the systems programming
    language of .NET!

    An example using the current Beta of VC++ 2005:


    inline int add(int x, int y) { return x+y; }


    int main()
    {
    int a=add(1,2);
    }


    C:\c>cl /clr:safe temp.cpp
    Microsoft (R) C/C++ Optimizing Compiler Version 14.00.41013
    for Microsoft (R) .NET Framework version 2.00.41013.0
    Copyright (C) Microsoft Corporation. All rights reserved.

    temp.cpp
    Microsoft (R) Incremental Linker Version 8.00.41013
    Copyright (C) Microsoft Corporation. All rights reserved.

    /out:temp.exe
    temp.obj

    C:\c>




    The /clr:safe means that this code is 100% CLR verified and thus is
    binary portable to all CLI VMs (Mono, DotGNU, etc). That is, it is pure
    CLI bytecode.


    It does not contain any native code.




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Dec 3, 2004
    #7
  8. Alex

    Phlip Guest

    Ioannis Vranos wrote:

    > It does not contain any native code.


    I just meant that either the OP must learn the old-fashioned #import stuff,
    commonly called "ATL", or they must bond their application with .NET just to
    get a link between a VB module and a C++ one.

    OTOH it sounds like Microsoft _finally_ invented a p-code they can live
    with...

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Dec 3, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luc Bisson

    Framework 1.0 to 1.1 conversion

    Luc Bisson, Nov 4, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    641
    Jim Blizzard [MSFT]
    Nov 19, 2003
  2. Amka
    Replies:
    8
    Views:
    555
    Jay B. Harlow [MVP - Outlook]
    Jan 28, 2004
  3. Thomas Bartzick
    Replies:
    0
    Views:
    2,283
    Thomas Bartzick
    Jun 26, 2003
  4. Troels Smit

    Conversion 1QN -> 2'Complement

    Troels Smit, Jun 30, 2003, in forum: VHDL
    Replies:
    1
    Views:
    4,269
    Troels Smit
    Jul 1, 2003
  5. , India
    Replies:
    2
    Views:
    506
    Fraser Ross
    Sep 15, 2009
Loading...

Share This Page