Click here to Skip to main content
11,435,106 members (48,707 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB
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.
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 25-Sep-12 19:35pm
Edited 25-Sep-12 19:47pm
v2
Comments
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
Pankaj Nikam at 28-Sep-12 10:35am
   
Can the downvoter explain for the downvote? :(
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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?
  Permalink  
Comments
Pankaj Nikam at 28-Sep-12 10:53am
   
I will post the code soon.
WeinbergHere at 28-Sep-12 18:48pm
   
Thank you Pankaj
Pankaj Nikam at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.150428.2 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100