Calling R From VB6 VBA

If you've been looking for a way to call R from your Visual Basic and VBA code, this sample project will show you how to interface to the mt4r.dll to access the R terminal. The cMT4R interface is an easy way to gain access to the R statistical computing environment from VB6 and VBA.

A bit of history: MT4R is a project that allows access to R through a Windows DLL interface that interfaces with the R terminal. The interface was originally written for access from Metatrader to R. However, I quickly realized that mt4R.dll could also be a useful tool to link other programming environments such as VB6 to R, as well as C# .NET to R. I created a simple class that translates and adapts the Metatrader interface found in mt4R.mqh so that Visual Basic users may access the mt4R dll and thus access the power of the R statistical computing environment from Visual Basic / VBA.

    1. Download the demo project (below) and change the default R path in the cMT4R class, Start_R method to match your actual R installation.
    2. Download the mt4r.dll found at the R for Metatrader site and place it in your \Windows\System\ directory.
    3. Run the demo project to verify that you can link VB to perform calculations in R, and transfer data back and forth.
    4. Study the mt4R documentation to understand how it works.
    5. Read the comments in the code (found in cMT4R).

If you have any questions, comments or suggestions for cMT4R, please post a comment. Enjoy!

Attached is a zipped project folder containing TestMT4RVB, which shows how to use cMT4R. You may freely add cMT4R to your VB6 and VBA projects.