| You are here: | About>Computing & Technology>Visual Basic> Using VB.NET> Disappearing Label Text |
![]() | Visual Basic |
Disappearing Label TextGraham, an About Visual Basic reader from the UK, has been sending me bugs that are so interesting that I just have to share. This one is about text that magically "disappears" when it's assigned to the Text property of a Label component. Graham had a Label component in his form that was filled in with a randomly generated character selected from the "symbols" part of the ASCII chart (decimal 33 to 42). This includes 033 or ! (exclamation mark) Graham said that the label was blank whenever a decimal 38 happened to be generated. To add confusion, when the same character was later concatenated into a string and assigned to a TextBox, it wasn't blank anymore. The code that created the TextBox.Text property looked like this: TextBox1.Text = Label1.Text & Label2.Text & Label3.Text Graham's question was, "Is it possible that you can't use a this character in a Label?" Doubting that this could actually be the problem, I added some debugging statements to test the code that generated the random character as follows: For Sign = 0 To 8 This made it easy to step through the program for a few additional steps and see what actually happened when decimal 38 was generated. I was forced to admit, it looked like you couldn't use decimal 38 in the Text property of a Label. I decided that was impossible so I checked the documentation at MSDN and discovered the UseMnemonic property. Athough this property has been part of Visual Basic since at least VB 6, I wasn't familiar with it. According to MSDN, UseMnemonic ... "True if the label doesn't display the ampersand character and underlines the character after the ampersand in its displayed text and treats the underlined character as an access key; otherwise, false if the ampersand character is displayed in the text of the control. The default is true." My emphasis added. Since decimal 38 happens to be &. This means that in a 1 character wide Text property, the default is for the displayed text to disappear altogether. Pretty sneaky, Microsoft! My new email pal Graham is beloved of most of the people in the UK due to his interesting program bugs. Check out another bug in an article inspired by one of his programs using the GoTo statement. Find out why "GoTo is considered harmful" at OOP and GoTo. |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


