Create trigonometry with visual basic


Code:

Dim th As Double

Dim scal As Integer

Dim op1 As Integer

Dim op2 As Integer

Dim num1 As Double

Dim num2 As Double

Dim x As Double

Dim y As Double

Dim step As Double

Private Sub drawgraph()

GraphCls

For th = -3.2 To 3.2 Step step

Select Case op1

Case 0

x = Sin(num1 * th)

Case 1

x = Cos(num1 * th)

Case 2

x = Tan(num1 * th)

End Select

Select Case op2

Case 0

y = Sin(num2 * th)

Case 1

y = Cos(num2 * th)

Case 2

y = Tan(num2 * th)

End Select

SetPixel graph.hdc, 200 + scal * x, 200 – scal * y, RGB(0, 0, 0)

Next th

graph.Refresh

End Sub

Private Sub cmdnum1d_Click()

If num1 > 1 Then txtnum1 = txtnum1 – 1

End Sub

Private Sub cmdnum1p_Click()

If num1 < 50 Then txtnum1 = txtnum1 + 1

End Sub

Private Sub cmdnum2d_Click()

If num2 > 1 Then txtnum2 = txtnum2 – 1

End Sub

Private Sub cmdnum2p_Click()

If num2 < 20 Then txtnum2 = txtnum2 + 1

End Sub

Private Sub cmdchange_Click()

Form1.Hide

Form2.Top = Form1.Top

Form2.Left = Form1.Left

Form2.Show

End Sub

Private Sub form_load()

GraphCls

step = 0.001

scal = 100

End Sub

Private Sub GraphCls()

graph.Cls

graph.Line (200, 0)-(200, 400), RGB(255, 0, 0)

graph.Line (0, 200)-(400, 200), RGB(255, 0, 0)

End Sub

Private Sub Form_Unload(Cancel As Integer)

End

End Sub

Private Sub menuabout2_Click()

frmAbout.Show

End Sub

Private Sub menuchange_Click()

cmdchange_Click

End Sub

Private Sub menuexit_Click()

End

End Sub

Private Sub optopt1_Click(Index As Integer)

op1 = Index

drawgraph

End Sub

Private Sub optopt2_Click(Index As Integer)

op2 = Index

drawgraph

End Sub

Private Sub sldnum1_Scroll()

txtnum1.Text = sldnum1.Value

End Sub

Private Sub sldnum2_Scroll()

txtnum2.Text = sldnum2.Value

End Sub

Private Sub pull()

num1 = txtnum1.Text

num2 = txtnum2.Text

sldnum1.Value = num1

sldnum2.Value = num2

drawgraph

End Sub

Private Sub sldscale_Scroll()

scal = sldscale.Value * 50

drawgraph

End Sub

Private Sub Timerstart_Timer()

pull

drawgraph

Timerstart.Enabled = False

End Sub

Private Sub txtnum1_Change()

pull

End Sub

Private Sub txtnum2_Change()

pull

End Sub

Module:

Public Declare Function SetPixel Lib “gdi32” (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal Color As Long) As Long

Upload Document Here

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s