Results 1 to 5 of 5

Thread: Debug.WriteLine syntax

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    165

    Debug.WriteLine syntax

    I do not have much experience in Debug syntax and can't find in any book or tutorial. I am only going to present the code line for the Debug.WriteLine. The Project runs fine. My problem is to understand the Debug syntax.

    1. Debug code line:

    Code:
    Debug.WriteLine("a1) sb1.Length = {0}, sb1.Capacity = {1}", sb1.Length,sb1.Capacity)

    2. Result:

    a1) sb1.Length = 3, sb1.Capacity = 16

    2. What is the meaning (or roll) of:

    Code:
    "a1) sb1.Length = {0}, sb1.Capacity = {1}"
    And of:

    {0}

    and

    {1}
    Last edited by ebellounisoft; Aug 17th, 2017 at 09:11 AM.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,538

    Re: Debug.WriteLine syntax

    1) you posted in the wrong forum... I'll ask the mods to move it.
    2) Did you look at the documentation?

    .WriteLine uses a format string, like what String.Format uses. {0} is a place holder. It tells the formatter that the first item in the parameter array is to go into that spot. {1} Means the next item goes in that spot and so on. You can also apply other formatting to the objects depending on what they are, for example, if it is a number, you can indicate if decimals are to be displayed, how many, currency symbol, and so on.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    165

    Re: Debug.WriteLine syntax

    The Code for the example is in language Visual Basic.NET from MSN:
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Thank you for your answer.
    Last edited by ebellounisoft; Aug 17th, 2017 at 09:31 AM.

  4. #4
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Debug.WriteLine syntax

    This isn't a special "debug syntax" but instead a more general "string formatting" syntax that many parts of the .NET framework use. I did a sort of mini-tutorial in another thread, but it wasn't focused on explaining the syntax.

    Console.WriteLine(), Debug.WriteLine(), and String.Format() use a syntax MS calls "composite formatting" to help you format strings. By way of quick example, these two lines do the same thing:
    Code:
    Dim example As String = "Hello " & someVariable & "!"
    Dim example As String = String.Format("Hello {0}!", someVariable")
    To make a "format string", you type out a normal string. In places where you want to substitute a variable, you insert an {n} symbol, that is, a curly brace, a number, and a closing curly brace. The numbers should start at 0 and get bigger as the string goes on.

    Any method that expects a format string also takes parameters at the end. Parameters are substituted into the string, in order, replacing the {n} symbols you made.

    So if you need to put in two symbols:
    Code:
    Console.WriteLine("Hello, {0} {1}!", firstName, lastName)
    You can also repeat them:
    Code:
    Console.WriteLine("Hello, {0}{1}{0}{2}", Environment.NewLine, firstName, lastName)
    There are some other neat things you can do, but you can read about them in depth at your leisure.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    165

    Re: Debug.WriteLine syntax

    Now I get it !!!. Thank you.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width