-2

I have application made from 2 solutions. One made in Visual Basics other in C# which is console-application.

I'm trying to remake that program into windows form application, however, all output is made using Console.WriteLine() commands. Output from C# I could quite easily get with richTextBox.AppendText().

When trying to output from Visual basic part, I can't do that, as I understand it's due to that fact that it is reference. What I could do to solve this?

atilas1
  • 391
  • 2
  • 3
  • 11
  • 1
    https://msdn.microsoft.com/en-us/library/system.console.setout(v=vs.110).aspx – Hans Passant Mar 13 '17 at 12:51
  • Do you have access to the code? Are you making a new app that has the other two apps as references or are you launching them as exes within your application? – pstrjds Mar 13 '17 at 12:52
  • I have access to the code – atilas1 Mar 13 '17 at 12:54
  • You could add an event to the VB code and then replace all of the Console.WriteLine calls with a call to raise an event with the text as the argument. You could follow the suggestion of set the console output to something else. There are many different approaches to take depending on the code and what your end goal is. – pstrjds Mar 13 '17 at 12:59
  • The problem for me now is that I have no idea how to output from VB.net part of my program into windows form and I couldn't find anything abut it. Currently reading SetOut method though, hope that helps :) – atilas1 Mar 13 '17 at 13:10
  • @atilas1 - You said you have access to the code, so why not add an event to the class and replace the writeline calls with a call to raise the event and then consume the event in your c# code? – pstrjds Mar 13 '17 at 13:18
  • @pstrjds Due to the lack of knowledge, my programming skills are quite basic. Thanks for pointers where to look – atilas1 Mar 13 '17 at 13:21
  • 1
    @atilas1, I was suggesting you to start by learning how to create a basic windows form application and from here trying to create the application based on the 2 applications you mentioned by yourself. There are no shortcuts, you need a basic understanding to achieve this task, it is not a matter of a specific issue that we could help you.You will probably encounter many other problems during this achievement, then you could ask a specific question. Good luck! – ehh Mar 13 '17 at 13:56

1 Answers1

-1

You can do it in the VisualBasic part like this (it shows it in C# but it's quite similar in VisualBasic): take a StringBuilder and add all your old statements there and then put it in the TextBox as once:

//// Your old code:
//Console.WriteLine("xyz1");
//// Do anything...
//Console.WriteLine("xyz2");
//// Do anything...
//Console.WriteLine("xyz3");
//// Your new code:
StringBuilder sb = new StringBuilder();
sb.AppendLine("xyz1");
//// Do anything...
sb.AppendLine("xyz2");
//// Do anything...
sb.AppendLine("xyz3");
this.textbox1.Multiline = true;
this.textbox1.Text = sb.ToString();

=> This code will work, if you will need only the results of the Console.WriteLine() Messages: if you need the Messages immediately, you will probably need a splash screen, like this: Making a splash screen, or How to build splash screen in windows forms application? or a ProgressBar maybe could help you: How to use WinForms progress bar?

Community
  • 1
  • 1
Adelphos
  • 83
  • 7
  • Rather than a `List` and then combining all of that (including a += on a string which is in general not recommended practice in .Net), this would be better as a `StringBuilder` with calls `AppendLine`. – pstrjds Mar 13 '17 at 13:57
  • It's only a performance problem if you have a lot of elemets in the `List`, if it is only a few: there is no performance problem. But ok, I changed the code, so that it is now with `StringBuilder`. – Adelphos Mar 13 '17 at 16:08
  • re: your response to my earlier comment - the issue was not necessarily the performance of the +=, but rather the fact that you were using a List to hold strings so you could then loop over them and combine them into a final string, when StringBuilder is designed for these type of situations. 2 - Why would the OP need a splash screen or a progress bar if they need the messages immediately? If they are needed as they arrive then that would be a good place to raise an event and then the consumer can register a handler for the event and then consume the messages as they are generated? – pstrjds Mar 13 '17 at 20:54