none
"Debug" or console output in Windows Form application RRS feed

  • Question

  • Hi,

    Is there a way to display console output in Visual Studio Windows Forms application?

            Dim myAL As New ArrayList()
            myAL.Add("Hello")
            myAL.Add("World")
            myAL.Add("!")
    
    
            ' Displays the properties and values of the ArrayList.
            Console.WriteLine("myAL")
            Console.WriteLine("    Count:    {0}", myAL.Count)
            Console.WriteLine("    Capacity: {0}", myAL.Capacity)
            Console.Write("    Values:")

    I recall that in VBA there is something called "intermediate window" which could output Debug information. Since console outputs are frequently used for debugging purposes, can it get displayed, or is there an analogue of Debug and a corresponding window to show similar information?

    Bob

    Saturday, March 3, 2012 5:59 PM

Answers

  • Hi Bob,

    Are you developing this in Visual Studio Tools for Office?

    This is the Visual Basic for Applications Forum, so in case you are using VSTO, I can move your thread to that particular forum for you.

    Thanks,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer as an answer when your question is being answered.

    • Marked as answer by Bob Sun Sunday, March 4, 2012 9:50 AM
    Saturday, March 3, 2012 10:14 PM
    Moderator
  • Daniel,

    I found that it can be solved using "Debug.WriteLine". So this is now solved.

    Bob

    Sunday, March 4, 2012 9:50 AM
  • Hi Bob,

    Welcome to the MSDN forum!

    You can take a look at AllocConsole() and FreeConsole() methods.

    The following code attach a console window to the Windows Form:

        Declare Function AllocConsole Lib "kernel32" () As Integer
        Declare Function FreeConsole Lib "kernel32" () As Integer
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim mydata As String
            If Convert.ToBoolean(AllocConsole()) Then
                Console.WriteLine("This is a test!")
                Console.WriteLine()
                Console.Write("Now enter some data:  ")
                mydata = Console.ReadLine
                Console.WriteLine("You wrote:  " & mydata)
                Console.WriteLine()
                Console.WriteLine("Press any key to Clear")
                Console.ReadKey()
                Console.Clear()
                Console.WriteLine("THE CONSOLE WAS CLEARED")
                Console.WriteLine("Press any key to close console")
                Console.ReadKey()
                FreeConsole()
    
                'System.Environment.Exit(1)		'ends entire application
            End If
        End Sub

    You may refer to the following link for more details:

    Attaching a Console to a WinForms application
    http://www.codeproject.com/Tips/319901/Attaching-a-Console-to-a-WinForms-application.aspx 

    Have a nice day!

    yoyo


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Bob Sun Sunday, March 11, 2012 3:59 PM
    Wednesday, March 7, 2012 4:27 AM
    Moderator

All replies

  • Hi Bob,

    Are you developing this in Visual Studio Tools for Office?

    This is the Visual Basic for Applications Forum, so in case you are using VSTO, I can move your thread to that particular forum for you.

    Thanks,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer as an answer when your question is being answered.

    • Marked as answer by Bob Sun Sunday, March 4, 2012 9:50 AM
    Saturday, March 3, 2012 10:14 PM
    Moderator
  • Daniel,

    I found that it can be solved using "Debug.WriteLine". So this is now solved.

    Bob

    Sunday, March 4, 2012 9:50 AM
  • Hi Bob,

    Welcome to the MSDN forum!

    You can take a look at AllocConsole() and FreeConsole() methods.

    The following code attach a console window to the Windows Form:

        Declare Function AllocConsole Lib "kernel32" () As Integer
        Declare Function FreeConsole Lib "kernel32" () As Integer
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim mydata As String
            If Convert.ToBoolean(AllocConsole()) Then
                Console.WriteLine("This is a test!")
                Console.WriteLine()
                Console.Write("Now enter some data:  ")
                mydata = Console.ReadLine
                Console.WriteLine("You wrote:  " & mydata)
                Console.WriteLine()
                Console.WriteLine("Press any key to Clear")
                Console.ReadKey()
                Console.Clear()
                Console.WriteLine("THE CONSOLE WAS CLEARED")
                Console.WriteLine("Press any key to close console")
                Console.ReadKey()
                FreeConsole()
    
                'System.Environment.Exit(1)		'ends entire application
            End If
        End Sub

    You may refer to the following link for more details:

    Attaching a Console to a WinForms application
    http://www.codeproject.com/Tips/319901/Attaching-a-Console-to-a-WinForms-application.aspx 

    Have a nice day!

    yoyo


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Bob Sun Sunday, March 11, 2012 3:59 PM
    Wednesday, March 7, 2012 4:27 AM
    Moderator
  • Yoyo,

    Thanks for the suggestion.

    Bob

    Sunday, March 11, 2012 3:59 PM