Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Ok,
So I got all of the calculator buttons to work properly and display them in a txt so that I could use the values for the click of the product buttons, only problem is I can't get the thing to work properly. I cant figure out how to make the button clicks reset so i can use say 1$ bottle of beer along with 2$ bottle and a 3$ cocktail and have it tell me 6$ total but still give me a total of 3 button clicks. On the buttons for beer and call drinks I have tried two different approaches that you can look at. Any help would be greatly appreciated.
VB
Public Class frmBar

    Private Sub Button1_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub LblTitle_Click(sender As Object, e As EventArgs) Handles LblTitle.Click

    End Sub

    Private Sub ButtonNum9_Click(sender As Object, e As EventArgs) Handles btnNum9.Click
        txtPriceFirst.Text = txtPriceFirst.Text & btnNum9.Text
    End Sub

    Private Sub btnHHWell_Click(sender As Object, e As EventArgs) Handles btnHHWell.Click

    End Sub

    Private Sub btnNum0_Click(sender As Object, e As EventArgs) Handles btnNum0.Click
        txtPriceFirst.Text = txtPriceFirst.Text & btnNum0.Text
    End Sub

    Private Sub btnNum1_Click(sender As Object, e As EventArgs) Handles btnNum1.Click
        txtPriceFirst.Text = txtPriceFirst.Text & btnNum1.Text
    End Sub

    Private Sub btnNum2_Click(sender As Object, e As EventArgs) Handles btnNum2.Click
        txtPriceFirst.Text = txtPriceFirst.Text & btnNum2.Text
    End Sub

    Private Sub btnNum3_Click(sender As Object, e As EventArgs) Handles btnNum3.Click
        txtPriceFirst.Text = txtPriceFirst.Text & btnNum3.Text
    End Sub

    Private Sub btnNum4_Click(sender As Object, e As EventArgs) Handles btnNum4.Click
        txtPriceFirst.Text = txtPriceFirst.Text & btnNum4.Text
    End Sub

    Private Sub btnNum5_Click(sender As Object, e As EventArgs) Handles btnNum5.Click
        txtPriceFirst.Text = txtPriceFirst.Text & btnNum5.Text
    End Sub

    Private Sub btnNum6_Click(sender As Object, e As EventArgs) Handles btnNum6.Click
        txtPriceFirst.Text = txtPriceFirst.Text & btnNum6.Text
    End Sub

    Private Sub btnNum7_Click(sender As Object, e As EventArgs) Handles btnNum7.Click
        txtPriceFirst.Text = txtPriceFirst.Text & btnNum7.Text
    End Sub

    Private Sub btnNum8_Click(sender As Object, e As EventArgs) Handles btnNum8.Click
        txtPriceFirst.Text = txtPriceFirst.Text & btnNum8.Text
    End Sub

    Private Sub btnNumDot_Click(sender As Object, e As EventArgs) Handles btnNumDot.Click
        txtPriceFirst.Text = txtPriceFirst.Text & btnNumDot.Text
    End Sub

    Private Sub btnNumClr_Click(sender As Object, e As EventArgs) Handles btnNumClr.Click
        txtPriceFirst.Text = ""
    End Sub

    Dim intBtnClkCount1 As Integer = 0
    Dim decPriceFirst As Decimal = 0
    Dim decPriceFinal As Decimal = 0

    Private Sub btnBottle_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBottle.Click
        decPriceFirst = CType(txtPriceFirst.Text, Decimal)
        decPriceFinal = CType(txtPriceFinal.Text, Decimal)
        intBtnClkCount1 += 1
        If String.IsNullOrEmpty(txtPriceFinal.Text) Then
            txtPriceFinal.Text = (intBtnClkCount1 * decPriceFirst)
        Else
            txtPriceFinal.Text = (intBtnClkCount1 * decPriceFirst) + decPriceFinal
        End If
        txtTotal.Text = intBtnClkCount1 + intBtnClkCount2 + intBtnClkCount3 + intBtnClkCount4
    End Sub

    Dim intBtnClkCount2 As Integer = 0
    Private Sub btnWine_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnWine.Click
        decPriceFirst = CType(txtPriceFirst.Text, Decimal)
        intBtnClkCount2 += 1
        txtPriceFinal.Text = (intBtnClkCount2 * decPriceFirst)
        txtTotal.Text = intBtnClkCount1 + intBtnClkCount2 + intBtnClkCount3 + intBtnClkCount4
    End Sub

    Dim intBtnClkCount3 As Integer = 0
    Private Sub btnCall_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCall.Click
        decPriceFirst = CType(txtPriceFirst.Text, Decimal)
        intBtnClkCount3 += 1
        txtPriceFinal.Text = (intBtnClkCount3 * decPriceFirst) + decPriceFinal
        txtTotal.Text = intBtnClkCount1 + intBtnClkCount2 + intBtnClkCount3 + intBtnClkCount4
    End Sub

    Dim intBtnClkCount4
    Private Sub btnWell_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnWell.Click
        decPriceFirst = CType(txtPriceFirst.Text, Decimal)
        intBtnClkCount4 += 1
        txtPriceFinal.Text = (intBtnClkCount4 * decPriceFirst) + decPriceFinal
        txtTotal.Text = intBtnClkCount1 + intBtnClkCount2 + intBtnClkCount3 + intBtnClkCount4
    End Sub
End Class


http://s18.postimage.org/ah7ygirrt/Capture.png[^]
Posted
Updated 25-Sep-12 18:47pm
v2
Comments
Sergey Alexandrovich Kryukov 26-Sep-12 1:05am    
It's hard to understand what can help here. This is not programming. Everything is repeated. In proper code it never happens. I just don't know... you need to gain some understanding of programming and confidence. The whole idea to do it in VB... (sight...)
--SA

Try the SendKeys.Send method for passing the keystrokes. You also need to track the textbox which is focused currently. First focus the proper textbox and then use the method to pass the keystrokes. It would be like a virtual keyboard thing (though not complete).

Get more information about it here[^]

The solution for the same his available here[^].

Please note that I have provided this as a sample only. In your application you may need something more than what I have provided. This is only for demonstration purposes.
 
Share this answer
 
v2
Comments
Pankaj Nikam 28-Sep-12 10:35am    
Can the downvoter explain for the downvote? :(
Thanks for getting back so soon, Im not really understanding the SendKeys.Send method, is there anyway you can give me an example using what i have?
 
Share this answer
 
Comments
Pankaj Nikam 28-Sep-12 10:53am    
I will post the code soon.
WeinbergHere 28-Sep-12 18:48pm    
Thank you Pankaj
Pankaj Nikam 29-Sep-12 10:44am    
Check out the updated answer. It has a sample. Do mark my answer as answer if it helps you. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900