What I am trying to do is when the one of the textboxes is empty the button is disabled, but once the two textboxes are filled-up it will enable the button.. What am I doing wrong? thank you in advance!
Public Class ModifiedLoanCalculatorFRM
Private Sub calculateBTN_Click(sender As Object, e As EventArgs) Handles calculateBTN.Click
If mortgageAmountTBX.Text.Equals("") Or interestRateTBX.Text.Equals("") Then
calculateBTN.Enabled = False
Else
calculateBTN.Enabled = True
End If
You're putting the code for testing the contents of the text boxes and then setting the enabled state of the button into the button click handler. That means that it's only ever going to fire when the button is clicked, and if it ever gets disabled, there's no bringing it back.
If your intent is to have the button enable or disable dynamically based on whether or not either of the text boxes is empty, you can move the code from your button click handler into its own subroutine, then make the "Changed" event on both of your text boxes, and your form's load event, call that subroutine:
Private Sub setButtonState()
If mortgageAmountTBX.Text.Equals("") Or interestRateTBX.Text.Equals("") Then
calculateBTN.Enabled = False
Else
calculateBTN.Enabled = True
End If
End Sub
Private Sub interestRateTBX_TextChanged(sender As Object, e As EventArgs) Handles interestRateTBX.TextChanged
setButtonState()
End Sub
Private Sub mortgageAmountTBX_TextChanged(sender As Object, e As EventArgs) Handles mortgageAmountTBX.TextChanged
setButtonState()
End Sub
Private Sub ModifiedLoanCalculatorFRM_Load(sender As Object, e As EventArgs) Handles MyBase.Load
setButtonState()
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With