locked
How do I view Console.Writeline?

    Question

  •  

    I'm rather new to programming.

    I've read two VB Express books and everything that I could find concerning Console.Writeline, and yet I still cannot figure out how to view what I write to it.

    When I use Debug.Writeline, I can view what I write to it in the "Immediate" window.

    I guessed that I should be able to view Console.Writeline in the "Output" window.

    Is that correct?

    I tried things like the example below, and nothing appeared in any of the windows that I looked at:

    ' System.Console.WriteLine

    Imports Microsoft.VisualBasic
    Imports System

    Public Class TipCalculator
       Private Const tipRate As Double = 0.18
      
       Public Shared Sub Main()
          System.Environment.ExitCode = Calculator(System.Environment.GetCommandLineArgs())
       End Sub
      
       Public Shared Function Calculator(args() As String) As Integer
          Dim billTotal As Double
          If args.Length < 2 Then
             Console.WriteLine("usage: TIPCALC total")
             Return 1
          Else
             Try
                billTotal = Double.Parse(args(1))
             Catch
                Console.WriteLine("usage: TIPCALC total")
                Return 1
             End Try
             Dim tip As Double = billTotal * tipRate
             Console.WriteLine()
             Console.WriteLine("Bill total:" & vbTab & "{0,8:c}", billTotal)
             Console.WriteLine("Tip total/rate:" & vbTab & "{0,8:c} ({1:p1})", tip, tipRate)
             Console.WriteLine("".PadRight(24, "-"c))
             Console.WriteLine("Grand total:" & vbTab & "{0,8:c}", billTotal + tip)
             Return 0
          End If
       End Function 'Main
    End Class 'TipCalculator

    'Example Output:
    '---------------
    '
    'Bill total:       $52.23
    'Tip total/rate:    $9.40 (18.0 %)
    '------------------------
    'Grand total:      $61.63

    I'm probably going to kick myself when you tell me the answer, aren't I?

    Thanks for the help.

    -Nick-

    Tuesday, January 03, 2006 2:31 PM

Answers

  • hi,

    i guess the problem is this , the console is faster than what your eyes can see , it open and write all lines and find nothing else to do so it close, to keep it open add this to the end of your process

    Console.ReadLine()

    i guess your problem in that line because it suppose to perform your operation durig exist your process so you will not see it

    System.Environment.ExitCode = Calculator(System.Environment.GetCommandLineArgs())

    try it this way

    Public Sub Main()

    Dim billTotal As Double

    Console.WriteLine(" what is the bill total?")

    billTotal = Console.ReadLine()

     

    Dim tip As Double = billTotal * tipRate

    Console.WriteLine()

    Console.WriteLine("Bill total:" & vbTab & "{0,8:c}", billTotal)

    Console.WriteLine("Tip total/rate:" & vbTab & "{0,8:c} ({1:p1})", tip, tipRate)

    Console.WriteLine("".PadRight(24, "-"c))

    Console.WriteLine("Grand total:" & vbTab & "{0,8:c}", billTotal + tip)

    Console.ReadLine()

    End Sub

    hope it was helpfull

    Tuesday, January 03, 2006 4:29 PM

All replies

  • Tuesday, January 03, 2006 2:44 PM
  • I tried using the console, instead of a windows application, but I still can't seem to find where I can view "the standard output stream".

    Am I correct in thinking that it should be viewed in the "Output" window?

    I tried this code:

    Imports Microsoft.VisualBasic

    Imports System

    Module Module1

    Private Const tipRate As Double = 0.18

    Public Sub Main()

    System.Environment.ExitCode = Calculator(System.Environment.GetCommandLineArgs())

    End Sub

    Public Function Calculator(ByVal args() As String) As Integer

    Dim billTotal As Double

    If args.Length < 2 Then

    Console.WriteLine("usage: TIPCALC total")

    Return 1

    Else

    Try

    billTotal = Double.Parse(args(1))

    Catch

    Console.WriteLine("usage: TIPCALC total")

    Return 1

    End Try

    Dim tip As Double = billTotal * tipRate

    Console.WriteLine()

    Console.WriteLine("Bill total:" & vbTab & "{0,8:c}", billTotal)

    Console.WriteLine("Tip total/rate:" & vbTab & "{0,8:c} ({1:p1})", tip, tipRate)

    Console.WriteLine("".PadRight(24, "-"c))

    Console.WriteLine("Grand total:" & vbTab & "{0,8:c}", billTotal + tip)

    Return 0

    End If

    End Function 'Main

     

    'Example Output:

    '---------------

    '

    'Bill total: $52.23

    'Tip total/rate: $9.40 (18.0 %)

    '------------------------

    'Grand total: $61.63

    End Module

    Does that seem like it should work?

    Tuesday, January 03, 2006 3:31 PM
  • Put this in the sub main() section of your module:

    Dim x As Integer

    For x = 1 To 10000

    Console.WriteLine("hello there")

    Next

     

    It should open the console window long enough for you to view the ouput.

    Tuesday, January 03, 2006 4:17 PM
  • It is working, probably just too fast for you to see though.  I'd use debug.writeline for your samples.
    Tuesday, January 03, 2006 4:19 PM
  • hi,

    i guess the problem is this , the console is faster than what your eyes can see , it open and write all lines and find nothing else to do so it close, to keep it open add this to the end of your process

    Console.ReadLine()

    i guess your problem in that line because it suppose to perform your operation durig exist your process so you will not see it

    System.Environment.ExitCode = Calculator(System.Environment.GetCommandLineArgs())

    try it this way

    Public Sub Main()

    Dim billTotal As Double

    Console.WriteLine(" what is the bill total?")

    billTotal = Console.ReadLine()

     

    Dim tip As Double = billTotal * tipRate

    Console.WriteLine()

    Console.WriteLine("Bill total:" & vbTab & "{0,8:c}", billTotal)

    Console.WriteLine("Tip total/rate:" & vbTab & "{0,8:c} ({1:p1})", tip, tipRate)

    Console.WriteLine("".PadRight(24, "-"c))

    Console.WriteLine("Grand total:" & vbTab & "{0,8:c}", billTotal + tip)

    Console.ReadLine()

    End Sub

    hope it was helpfull

    Tuesday, January 03, 2006 4:29 PM
  • Hi,

    Console.Writeline would output the text in the Console or Command Window (DOS type). You must use the Debug.Write to send text to the output window.



    cheers,

    Paul June A. Domag
    Tuesday, January 03, 2006 4:30 PM
  • Thanks for the help, guys!

    (^,^)

    I just have one question for Paul...

    I tried using the debug.write method that you told me about like this:


    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim x As String = "Hello World"

    System.Diagnostics.Debug.Write(x)

    End Sub

    End Class


    Oddly, it's saying "Hello World" in the "Immediate" box, and not the "Output" box.

    Is this supposed to happen?

    If so, what's the point of the "Output" box? 

    Tuesday, January 03, 2006 5:42 PM
  • Hi,

    I see that this thread is two years old but . . .

     

    I've been working with Visual Studio since it was VS 2002 and output from Diagnostis.Debug and Diagnostics.Trace always went to the Output panel.  I've been using VS 2008 since it was Orcas Beta 2, same behavior. 

     

    This morning, after a reboot, it's all going to the Immediate panel instead.  Because it's a Monday?

     

    I did have to reinstall it a week ago after VS 2008 SP1 forced me to reimage my workstation (that's another story) and I can't say with certainty that I haven't had this "problem" since the reinstallation but seriously . . . what's going on?

     

    I post this mainly for anyone else who may be having the same issue and wonders if they're the only ones.

     

    Will D.

     

    "Everything you know is wrong." Firesign Theatre

     

    Monday, August 25, 2008 1:23 PM
  • Hi,

    I see that this is a very old post and there are several like it... but here is my experience:

    Not sure if there's a setting which affects this, but in my VS2010 SP1, 

    System.Console.Out.WriteLine
    

    writes to the Output window.  

    System.Console.WriteLine
    

    does not show in the output window - can't find it displayed anywhere, in fact.  

    I am aware that these are supposed to be equivalent, and in fact the Visual Studio help on System.Console says:

    "Note that calls to Console.Out.WriteLine methods are equivalent to calls to the corresponding WriteLine methods."

    but that's not what I'm seeing in my debugging sessions.

    Hope this helps

    Peter

     

     


    Peter Wood
    Monday, September 26, 2011 4:06 PM
  • First of all, Console methods are mainly used with Console applications, NOT with Windows Forms applications.  When you start a new project, you are presented with several options.  Select Console application and you will get an edit window but NO form.  You place your code between Module Module1/Sub Main and End Sub/End Module.  When you run the program, it displays the output on a black screen.  "Start Without Debugging" (Shift-F5) to run the program without it immediately reverting back to the edit screen.

     


    Solitaire
    Monday, September 26, 2011 10:31 PM