Results 1 to 11 of 11

Thread: [RESOLVED] Where are my dots ?

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,424

    Resolved [RESOLVED] Where are my dots ?

    Hi,

    Here is a short extract from a fully working project. Everything works exactly as it ought except...
    Lines 5 and 6 do not display the final full stop (period).

    vb.NET Code:
    1. For i = 0 To spt.Length - 1
    2.      chk = spt(i).Trim : If chk.Length <> 5 Then Continue For
    3.      TextBox1.Text &= chk.ToLower & ", "
    4.      lst1.Add(chk)
    5.      Opener.Label2.Text = i.ToString("###,###: Words checked in.")
    6.      Opener.Label3.Text = lst1.Count.ToString("###,###: Words verified.")
    7.      Opener.Refresh()
    8.   Next

    Why not ?

    There is ample room in the length of both Labels.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Where are my dots ?

    This is a "me being too lazy to look up to see for sure" shot at it. The period is probably being treated as a formatting parameter and not as a literal character, so I would try something like escaping it by putting a \ immediately before it.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Where are my dots ?

    I just opened the documentation for the Int32.ToString method that you're using. A couple of links later, I was reading the information specifically relevant to this question.

    https://learn.microsoft.com/en-us/do...om-specifier-1
    The "." custom format specifier inserts a localized decimal separator into the result string. The first period in the format string determines the location of the decimal separator in the formatted value; any additional periods are ignored.
    https://learn.microsoft.com/en-us/do...acter-literals
    Format specifiers that appear in a custom numeric format string are always interpreted as formatting characters and never as literal characters.
    There are two ways to indicate that characters are to be interpreted as literal characters and not as formatting characters, so that they can be included in a result string or successfully parsed in an input string:

    By escaping a formatting character. For more information, see The "" escape character.

    By enclosing the entire literal string in quotation apostrophes.
    ALWAYS read the relevanht documentation.

  4. #4

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,424

    Re: Where are my dots ?

    Thanks guys,
    (Why am I not getting 'your thread has been answered' emails ? )

    I'd forgotten that I'd posted this question, I'd found the relevant documentation, and I'd figured-out the probable answer prior to that.

    The 'fix' I used was to remove the dot from the string and add & "." to the end of the line.
    Code:
         Opener.Label2.Text = i.ToString("###,###: Words checked in") & "."
    Poppa.
    Last edited by Poppa Mintin; Sep 25th, 2022 at 06:04 AM. Reason: Typo
    Along with the sunshine there has to be a little rain sometime.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Where are my dots ?

    Quote Originally Posted by Poppa Mintin View Post
    Thanks guys,
    (Why am I not getting 'your thread has been answered' emails ? )

    I'd forgotten that I'd posted this question, I'd found the relevant documentation, and I'd figured-out the probable answer prior to that.

    The 'fix' I used was to remove the dot from the string and add & "." to the end of the line.
    Code:
         Opener.Label2.Text = i.ToString("###,###: Words checked in") & "."
    Poppa.
    If you were going to do that then it would make more sense to take out everything that wasn't specifically for the number. In fact, I wouldn't call ToString on the number there in the first place. If you want to incorporate a number or date or the like into a longer string, use string interpolation:
    vb.net Code:
    1. Opener.Label2.Text = $"{i:###,###}: Words checked in."
    Also, your format specifier is overly verbose. "#,#" and "n0" would have the same effect.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Where are my dots ?

    Quote Originally Posted by Poppa Mintin View Post
    (Why am I not getting 'your thread has been answered' emails ? )
    There is currently an issue with that, the admins are dealing with it:
    https://www.vbforums.com/showthread....meone-responds

  7. #7

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,424

    Re: Where are my dots ?

    Quote Originally Posted by si_the_geek View Post
    There is currently an issue with that, the admins are dealing with it:
    https://www.vbforums.com/showthread....meone-responds
    Thanks for the explanation Si.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  8. #8

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,424

    Re: Where are my dots ?

    Quote Originally Posted by jmcilhinney View Post
    If you were going to do that then it would make more sense to take out everything that wasn't specifically for the number. In fact, I wouldn't call ToString on the number there in the first place. If you want to incorporate a number or date or the like into a longer string, use string interpolation:
    vb.net Code:
    1. Opener.Label2.Text = $"{i:###,###}: Words checked in."
    Also, your format specifier is overly verbose. "#,#" and "n0" would have the same effect.
    Thanks John,

    Sadly at my age, I like to stick with stuff I think I understand.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  9. #9
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: [RESOLVED] Where are my dots ?

    @Poppa Mintin - JMcIlhinney's example uses String interpolation which is essentially calling String.Format (documentation) under the hood.

    In other words, his example is functionally equivalent to this:
    Code:
    Opener.Label2.Text = String.Format("{0}: Words checked in.", i.ToString("###,###"))
    The difference is that with String interpolation you do not need to keep track of the index in relation to the parameter, instead you inject it right there into the String. A more subtle difference is that since the variable you're using in String interpolation is going to be implicitly converted to a String, you can pass the formatting by using the : character.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [RESOLVED] Where are my dots ?

    Quote Originally Posted by dday9 View Post
    A more subtle difference is that since the variable you're using in String interpolation is going to be implicitly converted to a String, you can pass the formatting by using the : character.
    You can do that with String.Format too:
    vb.net Code:
    1. Opener.Label2.Text = String.Format("{0:###,###}: Words checked in.", i)
    I tend to use string interpolation as a first choice these days but there are times that I prefer String.Format for specific reasons. Sometimes using string interpolation can produce a long line of code where String.Format allows you to use a shorter pattern and put the parameters on separate lines. Also, if you use the same expression multiple times then you'd have to evaluate it multiple times or introduce an extra variable using string interpolation, where String.Format lets you use it once directly.
    vb.net Code:
    1. Dim s1 = $"some text here {someExpression} some more text here {someOtherExpression} yet more text here {someExpression} OMG even more text here"
    2.  
    3. 'or
    4.  
    5. Dim s1 = String.Format("some text here {0} some more text here {1} yet more text here {0} OMG even more text here",
    6.                        someExpression,
    7.                        someOtherExpression)

  11. #11
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: [RESOLVED] Where are my dots ?

    That makes sense and since strings are immutable I can see situations where it would be more performant to use String.Format.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

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