How do I autoCalculate in VB2008 without using a Button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Arevin
    New Member
    • Sep 2010
    • 5

    #1

    How do I autoCalculate in VB2008 without using a Button

    Hey all, I'm working on a VB program that is a cashout sheet. In this sheet, there are about 23 fields where information is being input. What I am trying to do is create the program so that when the user presses tab, enter or down arrow key it goes to the next field in the tabindex and then continues to add all the fields that are associated with each of the totals textboxes.

    I know that this can be done with with a button, but I don't want the user to have to click the button everytime they want to update the total field.

    For example, my deposits' Totals field has the following code, am I way out in left field in thinking that this can be done "on the fly"?:
    Code:
    Private Sub TotalsTextBox_Cursorchange(ByVal sender As Object, ByVal e As System.EventArgs) Handles TotalsTextBox.CursorChanged
            Dim num1, num2, num3, num4, num5, num6, num7, num8, TotalDeposit As Decimal
            num1 = Val(BDepositTextBox.Text)
            num2 = Val(ChargeTextBox.Text)
            num3 = Val(DebitTextBox.Text)
            num4 = Val(CreditTextBox.Text)
            num5 = Val(CouponsTextBox.Text)
            num6 = Val(CertificatesTextBox.Text)
            num7 = Val(Received_On_AccountTextBox.Text)
            num8 = Val(DErrorTextBox.Text)
            TotalDeposit = num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8
            TotalsTextBox.Text = Val(TotalDeposit)
        End Sub
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    in VB6 You can use the CHANGE procedure like: 3 textboxes , enter a value in Text1 and Text2 and each time the value changes in one of them then Text3 gives immediately the result

    Code:
    Private Sub Text1_Change()
    Text3 = Val(Text1) + Val(Text2)
    End Sub
    
    Private Sub Text2_Change()
    Text3 = Val(Text1) + Val(Text2)
    End Sub

    Comment

    • Arevin
      New Member
      • Sep 2010
      • 5

      #3
      Unfortunately, this does not work for me. I'm using VB2008 Express. Sorry if I am in the wrong forum. It's been a LONG time since I used VB. Anyway, I've also tried to do this in Access 2010, but the problem that i've come across there is that I have a field in one table that compares a field in its table to another field in a different table and access doesn't like that either :S.

      Comment

      Working...