Results 1 to 6 of 6

Thread: Calculator problem !

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2013
    Posts
    30

    Calculator problem !

    Hey I am new to Visual basic, I learnt some things and I want to make a calculator I want it with buttons so I made the 9 buttons of the 9 numbers and I made 2 labels what I actually want is when I press Button "1" label = "1" then I press button "6" the next label be = "6" so I made this:

    Private Sub num3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles num3.Click
    If Number2.Text = Nothing Then
    Number2.Text = "3"
    End If
    Number1.Text = "3"
    End Sub

    and it's not working can someone help me please?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Calculator problem !

    You might try elaborating on "not working" by explaining exactly what you expect to see and exactly what you do see. That said, presumably you want an If...Else statement because you only want one or the other to be executed.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Calculator problem !

    What about zero?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2013
    Posts
    30

    Re: Calculator problem !

    okay what I actually want:

    I want when I press button1 it appears on label1 "1" then I press button5 so it appears on label2 "5"

    I tried a lot of times but when I press button1 it appeares on label1 "1" then I press button5 it appears on the same label1 "5"

  5. #5
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Calculator problem !

    if you set the label's text property equal to the number, then wouldn't you expect to be only contain that number? Rather than appending the number? It is possible to set the text property equal to itself with the additon of other text appended or prepended.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Calculator problem !

    Quote Originally Posted by Youssef View Post
    okay what I actually want:

    I want when I press button1 it appears on label1 "1" then I press button5 so it appears on label2 "5"

    I tried a lot of times but when I press button1 it appeares on label1 "1" then I press button5 it appears on the same label1 "5"
    As I said in my first replay, you need to use an If...Else statement. In the code you posted you are testing a condition and performing one task if it is True, then performing another task regardless. You need to perform one task if the condition is True and the other task if it's False, which is exactly what an If...Else statement does.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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