Public Class Form1 Private a, b, c, d As Double Private paper As Graphics Private mypen As Pen = New Pen(Color.Black) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TrackBar1.Minimum = -5 TrackBar1.Maximum = 5 TrackBar2.Minimum = -5 TrackBar2.Maximum = 5 TrackBar3.Minimum = -5 TrackBar3.Maximum = 5 TrackBar4.Minimum = -5 TrackBar4.Maximum = 5 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click paper = PictureBox1.CreateGraphics() drawgraph() End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged End Sub Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged End Sub Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click End Sub Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click End Sub Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click End Sub Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click End Sub Private Sub Draw() Dim x, y, nextX, nextY As Double Dim xPixel, yPixel, nextXPixel, nextYPixel As Integer For xPixel = 0 To PictureBox1.Width x = scaleX(xPixel) y = thefunction(x) yPixel = scaleY(y) nextXPixel = xPixel + 1 nextX = scaleX(nextXPixel) nextY = thefunction(nextX) nextYPixel = scaleY(nextY) paper.DrawLine(mypen, xPixel, yPixel, nextXPixel, nextYPixel) Next End Sub Private Sub drawgraph() a = CDbl(TextBox1.Text) Label1.Text = "a = " & CStr(a) b = CDbl(TextBox2.Text) Label2.Text = "b = " & CStr(b) c = CDbl(TextBox3.Text) Label3.Text = "c = " & CStr(c) d = CDbl(TextBox4.Text) Label4.Text = "d = " & CStr(d) paper.Clear(Color.White) Draw() End Sub Private Function thefunction(ByVal x As Double) As Double 'Return x * (x * (a * x + b) + c) + d Return Math.Log(x + 6.0) End Function Private Function scaleX(ByVal xPixel As Integer) As Double Dim xStart As Double = -5, xEnd As Double = 5 Dim xScale As Double = PictureBox1.Width / (xEnd - xStart) Return (xPixel - (PictureBox1.Width / 2)) / xScale End Function Private Function scaleY(ByVal y As Double) As Integer Dim yStart As Double = -5, yEnd As Double = 5 Dim pixelCoord As Integer Dim yScale As Double = PictureBox1.Height / (yEnd - yStart) pixelCoord = CInt(-y * yScale) + _ CInt(PictureBox1.Height / 2) Return pixelCoord End Function Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll TextBox1.Text = TrackBar1.Value paper = PictureBox1.CreateGraphics() drawgraph() End Sub Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll TextBox2.Text = TrackBar2.Value paper = PictureBox1.CreateGraphics() drawgraph() End Sub Private Sub TrackBar3_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar3.Scroll TextBox3.Text = TrackBar3.Value paper = PictureBox1.CreateGraphics() drawgraph() End Sub Private Sub TrackBar4_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar4.Scroll TextBox4.Text = TrackBar4.Value paper = PictureBox1.CreateGraphics() drawgraph() End Sub End Class