Share via


How do code a button to calculate something in VB?

Question

Friday, September 26, 2014 5:44 AM

I have to do a assignment where I make a program for a "Pizza" company. I wanted to make it so when you press the accept button I could see the total price, but my only issue was I don't know how to do that. I was hoping you guys and girls know how to do that kind of thing! Thanks in advance :)

All replies (2)

Friday, September 26, 2014 10:21 AM ✅Answered

Hello SydSperrer,

I am considering that you are using Visual studio for your assignment.Create new windows form application and Drag the Button from the toolbox into your Form and double click on the Button (in your case accept button).

After double clicking, Form.vb page will occur displaying button click event. In that event write your code to calculate the total price.For Example,

Public Class Form4
    Dim a As Integer = 10 
    Dim b As Integer = 20
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim sum As Integer = a + b
        textbox1.text = sum
    End Sub
End Class

Have a nice day! 


Friday, September 26, 2014 11:10 AM ✅Answered

When you add a control like a button to the designer you can right click the button and select properties.  In the property window you can then change the NAME property before double clicking so the method name is meaningful.  So instead of getting "Button1_Click" you can get "AcceptOrder_Click".

jdweng