Resolved Console vs Debug

Dennis Hining

Member
Joined
Jun 7, 2021
Messages
12
Programming Experience
Beginner
I know this is probably a pretty stupid question but I have never used the Console.Print before and am confused as to where the output of a Console.Write (FileName). I run the code in the code window and see nothing on the screen.

Console Write:
Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim OpenFileDialog1 As New System.Windows.Forms.OpenFileDialog
        Dim lst As String
        '**************************************************************************************************
        With OpenFileDialog1
            .Filter = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*"
            .FilterIndex = 1
        End With
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            lst = OpenFileDialog1.FileName
        Else
            lst = 
        End If

        Dim extension As String = Path.GetExtension(lst)
        Dim filename As String = Path.GetFileName(lst)
        Dim filenameNotExtension As String = Path.GetFileNameWithoutExtension(lst)
        Dim root As String = Path.GetPathRoot(lst)
        Dim c As Char()

        Console.Write(filename)
        Console.Write(root)
        

    End Sub

End Class
 
It goes to Output window normally, unless you have enabled option to redirect all Output Window text to Immediate Window.

In a forms project it is not common to write to Console, for debug output use Debug.Write.
 
One point to note with Debug.WriteLine is that you can leave it in your code and, when you create a Release build, it will simply be ignored. That means that you can leave your debug logging code in and it will have no effect on your final build.

That said, the output from Debug.WriteLine doesn't appear immediately, where that from Console.WriteLine does. I assume that it has something to do with how the VS threading model handles the debugger but, regardless, if it's important that you see your logging output when the code is executed then go with Console.WriteLine, but be sure to remove it before creating a Release build.
 
It goes to Output window normally, unless you have enabled option to redirect all Output Window text to Immediate Window.

In a forms project it is not common to write to Console, for debug output use Debug.Write.
Thanks. I'll stick with Debug which does write to the Immediate Window. I did show the Output window but nothing was written to it. I would like to know how to redirect all Output Window to the Immediate Window.
 
One point to note with Debug.WriteLine is that you can leave it in your code and, when you create a Release build, it will simply be ignored. That means that you can leave your debug logging code in and it will have no effect on your final build.

That said, the output from Debug.WriteLine doesn't appear immediately, where that from Console.WriteLine does. I assume that it has something to do with how the VS threading model handles the debugger but, regardless, if it's important that you see your logging output when the code is executed then go with Console.WriteLine, but be sure to remove it before creating a Release build.
I can't see any output to either the Immediate Window or the Output window when I use the Console.Wrteline. I even tried Console.Read with nothing showing. How do I get the Console to show on my screen.
 
I know this is probably a pretty stupid question but I have never used the Console.Print before and am confused as to where the output of a Console.Write (FileName). I run the code in the code window and see nothing on the screen.

Console Write:
Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim OpenFileDialog1 As New System.Windows.Forms.OpenFileDialog
        Dim lst As String
        '**************************************************************************************************
        With OpenFileDialog1
            .Filter = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*"
            .FilterIndex = 1
        End With
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            lst = OpenFileDialog1.FileName
        Else
            lst =
        End If

        Dim extension As String = Path.GetExtension(lst)
        Dim filename As String = Path.GetFileName(lst)
        Dim filenameNotExtension As String = Path.GetFileNameWithoutExtension(lst)
        Dim root As String = Path.GetPathRoot(lst)
        Dim c As Char()

        Console.Write(filename)
        Console.Write(root)
       

    End Sub

End Class
I finally got it to write to the Output window. However when I try to read input from the console, lst = Console.ReadLine(), I am not ask for any input.
 
I finally got it to write to the Output window. However when I try to read input from the console, lst = Console.ReadLine(), I am not ask for any input.
Why would you be trying to read input from the Console in the first place? It's a WinForms app. You can use Console.WriteLine to provide information to you - the developer - while debugging. It's not for providing information to the user and it's certainly not for getting input. That's what the GUI is for in a GUI app.
 
I am just trying to learn and an article on the internet suggested I try reading a line using Console.Readline in my quest to see how to view the console. Can you advise as to WHY I can't see the console and read a line, independent of why I want to do it!
 
Create a Console Application to play with the console, instead of a GUI application like Windows Forms .
 
Back
Top