Question

I need help with this problem in Visual Basic 2012: Write a program that allows the...

I need help with this problem in Visual Basic 2012:

Write a program that allows the user to specify two numbers and then adds, subtracts, multiplies, or divides them when the user clicks on the appropriate button. The output should give the type of arithmetic performed and the result. Whenever one of the numbers in an input text box is changed, the output text box should be cleared. Also, if the number 0 is entered into the second text box, the division button should be disabled.

Here is my code so far. The button disabling is what's troubling me the most.

Option Strict On
Public Class FrmCalculator

Private Sub TxtFirstNum_TextChanged(sender As Object, e As EventArgs) Handles TxtFirstNum.TextChanged
TxtSolution.Clear()
End Sub

Private Sub TxtSecondNum_TextChanged(sender As Object, e As EventArgs) Handles TxtSecondNum.TextChanged
TxtSolution.Clear()
End Sub


Private Sub BtnAdd_Click(sender As Object, e As EventArgs) Handles BtnAdd.Click
If (IsNumeric(TxtFirstNum.Text)) And (IsNumeric(TxtSecondNum.Text)) Then
Dim num1 As Double = CDbl(TxtFirstNum.Text)
Dim num2 As Double = CDbl(TxtSecondNum.Text)
Dim sum As Double = CDbl(num1 + num2)
TxtSolution.Text = CStr(num1 & "+" & num2 & "=" & sum)
ElseIf Not (IsNumeric(TxtFirstNum.Text)) And Not (IsNumeric(TxtSecondNum.Text)) Then
BtnAdd.Enabled = False
End If
End Sub

Private Sub BtnSubtract_Click(sender As Object, e As EventArgs) Handles BtnSubtract.Click
Dim num1 As Double = CDbl(TxtFirstNum.Text)
Dim num2 As Double = CDbl(TxtSecondNum.Text)
Dim difference As Double = CDbl(num1 - num2)
TxtSolution.Text = CStr(num1 & "-" & num2 & "=" & difference)
End Sub

Private Sub BtnMultiply_Click(sender As Object, e As EventArgs) Handles BtnMultiply.Click
Dim num1 As Double = CDbl(TxtFirstNum.Text)
Dim num2 As Double = CDbl(TxtSecondNum.Text)
Dim product As Double = CDbl(num1 * num2)
TxtSolution.Text = CStr(num1 & "x" & num2 & "=" & product)
End Sub

Private Sub BtnDivide_Click(sender As Object, e As EventArgs) Handles BtnDivide.Click
Dim num1 As Double = CDbl(TxtFirstNum.Text)
Dim num2 As Double = CDbl(TxtSecondNum.Text)
Dim quotient As Double = CDbl(num1 / num2)
TxtSolution.Text = CStr(num1 & "/" & num2 & "=" & quotient)
If CDbl(TxtSecondNum.Text) = 0 Then
BtnDivide.Enabled = False
End If
End Sub


End Class

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
I need help with this problem in Visual Basic 2012: Write a program that allows the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • so im trying to make a grade program and idk what im doing wrong actually if...

    so im trying to make a grade program and idk what im doing wrong actually if someone can help? (heres the lines of code i have so far if its wrong let me know how to fix them Option Strict On Option Explicit On Public Class Form1 Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim lblscore1 As Double Dim lblscore2 As Double Dim lblscore3 As Double lblscore1 = CDbl(Txtscore1.Text) lblscore2 = CDbl(Txtscore2.Text) lblscore3 = CDbl(Txtscore3.Text) lblaverage =...

  • Program using visual basic.net You will create a very simple two numbers calculator with save options;...

    Program using visual basic.net You will create a very simple two numbers calculator with save options; here is the specifications for the application. Create a form divided vertically in two halves with right and left panels 1- In the left panel you will create the following control, the label or the value of the control will be in "" and the type of the control will in [] a- "First Number" [textbox] b- "Second number" [texbox] c- "Result" [textbox] -...

  • Project 2 – Memory Match Game Purpose This Windows Classic Desktop application plays a simple matching game. The game si...

    Project 2 – Memory Match Game Purpose This Windows Classic Desktop application plays a simple matching game. The game simulates a card game where the cards a placed face down and the player flips over pairs of cards in an attempt to find matching cards.   Program Procedure Display a 4x4 grid of “face down” cards. Assign the letters A through H randomly to the cards in pairs. Allow the user to click on a card to “flip” it over and...

  • I really need some help fixing a code error in Visual Basic I was wondering if...

    I really need some help fixing a code error in Visual Basic I was wondering if anyone could help fix the error that I'm about to provide in bold thanks so much! I'll also tell what the error is. Public Class MainForm Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click Me.Close() End Sub Dim img As Image = Image.FromFile("C:\Users\Pranesh\Pictures\11599264.jpg") house1PictureBox.Image = img house2PictureBox.Image = img house3PictureBox.Image = img house4PictureBox.Image = img house1PictureBox.Visible = False house2PictureBox.Visible = False house3PictureBox.Visible...

  • WITH THIS CODE, ADD TO THE EXIT BUTTON THAT ALLOWS THE USER TO SEE UPON EXITING,...

    WITH THIS CODE, ADD TO THE EXIT BUTTON THAT ALLOWS THE USER TO SEE UPON EXITING, HOW MANY QUESTIONS THEY GOT RIGHT AND WRONG. Public Class Form1 Dim r As Random = New Random Dim no1, no2 As Integer Private Sub rdbAdd_CheckedChanged(sender As Object, e As EventArgs) Handles rdbAdd.CheckedChanged txtAnswer.Clear() txtAnswer.BackColor = Color.White no1 = randomInt() no2 = randomInt() lblOperation.Text = "+" txtNumber1.Text = no1.ToString() txtNumber2.Text = no2.ToString() End Sub Public Function randomInt() As Integer Return r.Next(20, 120) End Function...

  • The Murach's Visual Basic 2015 Book And Visual Studio Exercise 7-2 Enhance the Invoice Total application...

    The Murach's Visual Basic 2015 Book And Visual Studio Exercise 7-2 Enhance the Invoice Total application If you did exercise 6-1 in the last chapter, this exercise asks you to add data validation and exception handling to it. 1. Copy the Invoice Total application from your C:\VB 2015\Chapter 06 directory to your Chapter 07 directory. This should be your solution to exercise 6-1 of the last chapter. 2. If your application has both a Sub procedure and a Function procedure...

  • I am new to programming (2 weeks of playing with it) I have written code for...

    I am new to programming (2 weeks of playing with it) I have written code for a timer in Visual Studio 2013. I am wondering if someone can show me how to write code/what the code would look like in a MODULE1.vb. I was thinking that for this timer I could create MsgBox using a DO UNTIL LOOP that would pop up every 20 seconds that says "hurry up!" until 1 minute has passed. As I said I am just...

  • Public Class Form1     Private Sub CompleteReport_Click(sender As Object, e As EventArgs) Handles CompleteReport.Click         Dim...

    Public Class Form1     Private Sub CompleteReport_Click(sender As Object, e As EventArgs) Handles CompleteReport.Click         Dim room As Double 'Assigns room as double         Dim rate As Double 'Assigns rate as double         Dim room2 As Double 'Assigns room as double         Dim overallRate As Double 'Assigns overall as double         Dim a As Integer 'Assign a as an integer         For a = 1 To 8 'Assign a as an 1 to 8 for all 8 floors             With...

  • Assume you have a form containing a listbox, lstDogs. Write code for the button handler that...

    Assume you have a form containing a listbox, lstDogs. Write code for the button handler that will use an Input Box to ask the user to enter a dog breed such as Cocker Spaniel, Collie, etc. The program should keep asking for dogs until the user hits the Enter key with no input or clicks the "Cancel" button. (This is easier than you might think). Private Sub btnRun_Click(sender As Object, e As EventArgs) Handles btnRun.Click <========= your code goes here...

  • Visual Basic: Create an application that simulates a tic tac toe game. The form uses 9...

    Visual Basic: Create an application that simulates a tic tac toe game. The form uses 9 large labels to display the x's and o's. The application should use a two dimensional integer array to simulate the game board in memory. When the user clicks the "New Game" button the application should step throguh the array storing a random number of 0 to 1 in each element. The numer 0 represent the letter o and the number 1 reprsents the letter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT