Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Visual Basic 2010 calculator help?

I'm making a calculator from Visual Basic 2010 but i couldn't quite get things going as i hoped. I'm trying to get the backspace button working so that it deletes the last digit (ones column).

I'm not sure why it isn't working but here's my code:

Dim str As String

str = lblDisplay.Text.Chars(lblDisplay.Text.Length - 1)

lblDisplay.Text = str

It gets rid off all the digits besides the last one (ones column) and this is really starting to fustrate me.

Any help would be appreciated, thanks.

Update:

The cut off 'Le...' was Length.

Update 2:

texasmaverick, no the code doesn't work.

Gardener the code works but if you try backspace until it ends up with no text and press backspace once more the program crashes. Going to try work that out but if you find it before please post it up.

Update 3:

Don't worry i got it, code was:

Dim str As String

str = lblDisplay.Text

lblDisplay.Text = str.Substring(1, str.Length - 1)

If lblDisplay.Text = "" Then

lblDisplay.Text = "0"

End If

3 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Yahoo kind of chopped up your code there. Can't read it.

    Edit:

    You might try something like this:

    Dim str As String

    str = lblDisplay.Text

    lblDisplay.Text = str.Substring(1,str.Length - 1)

    Personally though I would just make the label a textbox and add in some code in the keypress event handler to make sure no letters got entered.

    Source(s): VB.NET Programmer
  • 1 decade ago

    Try replacing the two lines in question with the following code:

    str=lblDisplay.Text

    lblDisplay.Text=Left(str,Len(str)-1)

    This might work. It is some of the earlier versions of VB code.

  • 5 years ago

    Documentation for seen easy is freely obtainable from Microsoft on the MSDN internet site. BTW, people who use the term "aspects codes" are recognized as glaring beginners and not taken heavily. "source code" is the uncompiled programming training. The term "source codes" means that there is a few "secret code" to programming or some such nonsense.

Still have questions? Get your answers by asking now.