Results 1 to 3 of 3

Thread: Console.WriteLine arguments?

  1. #1
    TechTeach is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Jan 2013
    Posts
    4
    Reputation
    0

    Console.WriteLine arguments?

    Hello All,

    I have been researching and trying to figure out why the first WriteLine isn't printing out the entire line when I debug the code. I'm sure I am missing something really silly but I just can't figure it out. Can somebody please explain to me why the C in the first line isn't printing out when I debug ... System.Console.WriteLine("The answer is", C)


    Code:
    Module Module1
    
        Sub Main()
    
    
            Dim A As Integer = 2
            Dim B As Integer = 10
            Dim C As Integer
    
    
            Try
                C = B / A
                System.Console.WriteLine("The answer is", C)
                System.Console.WriteLine(C)
                System.Console.WriteLine("Press Enter to continue...")
                Console.ReadLine()
            Catch e As OverflowException
                System.Console.WriteLine("An overflow exception occured.")
                System.Console.WriteLine("Press Enter to continue...")
                System.Console.ReadLine()
            End Try
    
    
        End Sub
    
    
    End Module

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,767
    Reputation
    1702
    Because that overload of WriteLine takes a format string and values to insert into that format string. Your format string contains no parameter place-holders so the value you specify will not be inserted into it. That code should keep using the same overload and include a place-holder to replace with the value:
    Code:
    Console.WriteLine("The answer is {0}.", C)
    or it should use a different overload that simply takes a single string to be output as is:
    Code:
    Console.WriteLine("The answer is " & C & ".")

  3. #3
    TechTeach is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Jan 2013
    Posts
    4
    Reputation
    0
    Thank you so much for explaining that to me! Have a wonderful weekend!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •