0

I currently have a Visual Basic .NET program that uses COM to communicate to some software I am automating. Part of the program requires reading a file line by line, checking for certain keywords, and storing some into String objects to be used by the software.

My problem lies with the slow speed of visual basic in reading and performing these tasks. I have been able to write exponentially faster functions in Visual C++ in order to complete these tasks but I know no way of connecting the two.

Is it possible to call VB .NET's Shell method to run my C++ code and return the three strings?

Something along the lines of:

    Shell("cplusplus_Program.exe " + filename)
//and somehow return three strings

Would there be a better way? I have no experience in creating .dll's, but would this be more suited for my task?

EDIT 1: I have been told that VB.NET should work fine/quick to meet my goals if I use it correctly, so I went back and changed from the old COM object I was using to StreamReader. I use the ReadLine method and it is still very slow. From my research I have seen many fast ways to stream the whole text document at once, but I need to go line by line, as each string line I receive needs to be checked and possibly fixed (though my test case never actually needs fixing). In case it might play a large role with the speed, I check each string using the .IndexOf method

Heathcliff
  • 101
  • 4
  • 1
    VB.Net should be plenty fast enough for this type of task. – Ben Jan 26 '16 at 16:21
  • 1
    Yes, it's possible to launch the process and then read it's output. See my answer [this question](http://stackoverflow.com/questions/11504981/reading-and-writing-to-a-command-prompt-console-using-vb-net/11506296#11506296) for an example. However, a DLL would certainly be faster and make more sense. However, if the problem is the your VB code is too slow, perhaps you simply need to refactor your VB code to make it perform better. If it's just a matter of you doing it in a suboptimal way, it would be far easier to just fix that rather than involve another language/library/process. – Steven Doggart Jan 26 '16 at 16:25
  • 'Dim openFile = CreateObject("Scripting.FileSystemObject") Dim read = openFile.OpenTextFile(filename)' ...I use 'read' and it's '.ReadLine' method. For a text file of ~22,000 lines, this is taking around 9 seconds. Similar C++ functions were well under a second. Some of the files will be millions of lines, so speed is important. Do you have any suggestions for faster objects I could use? – Heathcliff Jan 26 '16 at 16:31
  • That's an old COM class. Just use the managed `System.IO` classes, such as `FileStream` or `File`. – Steven Doggart Jan 26 '16 at 16:33
  • I had no idea (pretty new to VB.NET)! I will look into `FileStream` as I need to read and store line by line. Thanks! – Heathcliff Jan 26 '16 at 16:37
  • On a side note, while I'll be the first to defend VB.NET against naysayers claiming that it's a toy language, it does seem strange that you would be choosing to use VB at all. If you are more familiar with C++, I'd think you'd be more comfortable with C#'s syntax. – Steven Doggart Jan 26 '16 at 16:38
  • I am using a COM type library for some engineering software. The API documentation is geared towards VB (all examples on how to correctly and efficiently use objects), so I went with VB as well. I have been using C# for another unrelated project recently and I think that you might be right, it feels much more native to me! – Heathcliff Jan 26 '16 at 17:12

0 Answers0