This is a program that enables the user to input the coefficients of a cubic function and draw its graph. The cubic function takes the form f(x)=ax3+bx2+cx+d. We need to create the cubic function with some modifications and the coordinates in computer screen starts from top left, therefore instead of x we used a certain number to minus x. As we define the width of the graph as 10, so we used 5-x so that the graph starts plotting from the center. In VB, the cubic function takes the following form:
Private Function f(x As Variant)
f = a * (5 - x) ^ 3 + b * (5 - x) ^ 2 + c * (5 - x) + d
To draw the graph, we use built-in function PSet.
In this program, you need to insert four text boxes for the user to enter the four coefficients, a picture box and two command buttons, one is to draw the graph and the other one to clear the inputs. Name the picture box as pic_graph, the draw button cmd_draw and the clear button as cmd_Clear.
Dim a, b, c, d As Integer