Originally Posted by fumei
"i have created a form and 2 buttons and 2 textboxes"
TWO textboxes.
Your code uses THREE textboxes (TextBox1, TextBox2 and txtOutput). Thus..."Run-Time Error '424': object required". ONE of the textboxes (in your code) is not there...and is required, since you coded it.
If I duplicate your userform with these three, your code works fine.
Some comments.
General good practice is to declare all your variable at the top, like this:[vba] Private Sub CommandButton2_Click()
Dim flag As Boolean
Dim age As Integer
Dim restingRate As Integer
flag = True
age = TextBox1.Text
restingRate = TextBox2.Text
txtOutput.Text = CStr(TrainingHeartRate(age, restingRate, flag))
End Sub[/vba]Also, as your are using the SAME variables in all the procedures, why not use the same ones as Public, like this:[vba]Option Explicit
Public flag As Boolean
Public age As Integer
Public restingRate As Integer[/vba]That way your procedure do not have to declare them at all, like this:[vba] Private Sub CommandButton2_Click()
flag = True
age = TextBox1.Text
restingRate = TextBox2.Text
txtOutput.Text = CStr(TrainingHeartRate(age, restingRate, flag))
End Sub[/vba]
Check your userform. It works if you actually use the correct number of textboxes. Correctly named of course. One last thing, generally speaking it is better to name controls (textboxes) with a useful name.
Instead of TextBox1 use txtAge.[vba]age = txtAge.Text[/vba]