How do I view Console.Writeline?

 

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-




Answer this question

How do I view Console.Writeline?

  • twistedinferno

    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


  • Corey Wirun

    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.


  • Robert Campbell

    It is working, probably just too fast for you to see though.  I'd use debug.writeline for your samples.
  • mhammingh

    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  



  • Michael Boehm

  • Omar Khan

    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



  • Maorik

    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



  • How do I view Console.Writeline?