Private Sub btnMCS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMCS.Click Dim a As Integer Dim b As Integer Dim x As Double Dim func As Double Dim total As Double Dim result As Double Dim j As Integer Dim N As Integer a = txtboxA.Text b = txtboxB.Text N = txtboxST.Text For j = 1 To N 'Generate a new number between a and b x = (b - a) * Rnd() 'Evaluate function at new number func = (x ^ 2) + (2 * x) + 1 'Add to previous value total = total + func Next j result = (total / N) * (b - a) txtboxApprox.Text = result End Sub

I tried the code and it works for the interval [1,0]. I tried other intervals, and it doesn't work right. What did I do wrong? Any help is appreciated.