Results 1 to 4 of 4

Thread: entering value for scale using textboxes

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    7

    entering value for scale using textboxes

    Hello..i have a programm that can plot a sin and tan graph.now i want the user to be able to enter the scale value,in my case is Xa,Xe,Ya,Ye by typing in the value in the textboxes.i have created 4 textboxes,1 comboBox and 1 button.but now it wont run anymore.can some one help me??thanx..i have two forms.Form2 is used to plot the graph(sin or tan) and Form1 is used for the user to enter the value in the textboxes.

    ------------------------------------------------------------------------

    FORM2:
    VB Code:
    1. Imports System.Drawing.Printing
    2. Imports System.IO
    3. Public Class Form2
    4.     Inherits System.Windows.Forms.Form
    5.     Dim int_X0, int_Y0, int_i As Integer
    6.     Dim single_Xa, single_Xe, single_Ya, single_Ye As Integer
    7.     Dim x_Array(), y_Array(), Xa, Xe, Ya, Ye As Single
    8.     Dim int_color As System.Drawing.Pen
    9.    
    10.   Private Sub Drawing_load(ByVal sender As Object,ByValAsSystem.EventArgs) Handles Me.Load
    11.  
    12.         XA = Val(Form1.TextBox1.Text)
    13.         Xe = Val(Form1.TextBox2.Text)
    14.         Ya = Val(Form1.TextBox3.Text)
    15.         Ye = Val(Form1.TextBox4.Text)
    16.  
    17.         If Form1.ComboBox1.Text = "Sinus" Then
    18.             main()
    19.         ElseIf Form1.ComboBox1.Text = "Tan" Then
    20.             main1()
    21.  
    22.         End If
    23.         'PictureBox1.Image = bmp
    24.     End Sub
    25.    
    26.    Sub main()
    27.         ReDim x_Array(628), y_Array(628)
    28.         For int_i = 0 To UBound(x_Array) Step 1
    29.             x_Array(int_i) = int_i / 100 - 5
    30.         Next
    31.         Sinus(x_Array)
    32.         'Tan(x_Array)
    33.         Plot(x_Array, y_Array, Pens.Gold, Xa, Xe, Ya, Ye)
    34.     End Sub
    35.    
    36.     Sub main1()
    37.         ReDim x_Array(628), y_Array(628)
    38.  
    39.         For int_i = 0 To UBound(x_Array) Step 1
    40.             x_Array(int_i) = int_i / 100 - 5
    41.         Next
    42.         Tan(x_Array)
    43.         Plot(x_Array, y_Array, Pens.Gold, Xa, Xe, Ya, Ye)
    44.     End Sub
    45.  
    46. Function Tan(ByVal x_Array)
    47.         For int_i = 0 To UBound(x_Array) Step 1
    48.             y_Array(int_i) = Math.Tan(x_Array(int_i))
    49.         Next
    50.         Return y_Array
    51.     End Function
    52.  
    53. Function Sinus(ByVal x_Array)
    54.         For int_i = 0 To UBound(x_Array) Step 1
    55.             y_Array(int_i) = Math.Sin(x_Array(int_i))
    56.         Next
    57.         Return y_Array
    58.     End Function
    59.  
    60. Function Plot(ByVal x_Array, ByVal y_Array, ByVal int_color, ByVal single_Xa, ByVal single_Xe, ByVal single_Ya, ByVal single_Ye)
    61.         Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
    62.         Dim g As System.Drawing.Graphics = Graphics.FromImage(bmp)
    63.         int_X0 = 50
    64.         int_Y0 = 600
    65.         g.TranslateTransform(int_X0, int_Y0)
    66.         Dim P1 As New System.Drawing.Point(0, 0)
    67.         Dim P2 As New System.Drawing.Point(600, 0)
    68.         Dim P3 As New System.Drawing.Point(0, -600)
    69.         g.DrawLine(New Pen(Color.Black, 2), P1, P2)
    70.         g.DrawLine(New Pen(Color.Black, 2), P1, P3)
    71.         Dim z1 As Single = 600 \ (single_Xe - single_Xa)
    72.         For int_i = 0 To 600 Step z1
    73.             g.DrawLine(New Pen(Color.AliceBlue, 1), int_i + z1, 0, int_i + z1, -600)
    74.             g.DrawLine(New Pen(Color.Black, 2), int_i, 0, int_i, -10)
    75.             g.DrawLine(New Pen(Color.Black, 1), int_i + z1 \ 2, 0, int_i + z1 \ 2, -5)
    76.             g.DrawString(int_i \ z1 + single_Xa, New Font("Arial", 10), Brushes.Black, int_i - 5, 0)
    77.         Next
    78.         Dim z2 As Single = 600 \ (single_Ye - single_Ya)
    79.  
    80.         For int_i = 0 To -600 Step -z2
    81.             g.DrawLine(New Pen(Color.AliceBlue, 1), 0, int_i - z2, 600, int_i - z2)
    82.             g.DrawLine(New Pen(Color.Black, 2), 0, int_i, 10, int_i)
    83.             g.DrawLine(New Pen(Color.Black, 1), 0, int_i - z2 \ 2, 5, int_i - z2 \ 2)
    84.             g.DrawString(-(int_i \ z2 - single_Ya), New Font("Arial", 10), Brushes.Black, -20, int_i - 7)
    85.         Next
    86.  
    87.         If single_Xa > x_Array(0) Then
    88.             For int_i = 0 To UBound(x_Array) - 1 Step 1
    89.                 If x_Array(int_i) > single_Xa Then
    90.                     If y_Array(int_i) > -single_Ye Then
    91.                         If y_Array(int_i) < single_Ye Then
    92.                             g.DrawLine(int_color, x_Array(int_i) * z1 - z1 * single_Xa, -y_Array(int_i) * z2 + z2 * single_Ya, x_Array(int_i + 1) * z1 - z1 * single_Xa, -y_Array(int_i + 1) * z2 + z2 * single_Ya)
    93.                         End If
    94.                     End If
    95.                 End If
    96.             Next
    97.         Else
    98.             For int_i = 0 To UBound(x_Array) - 1 Step 1
    99.                 If y_Array(int_i) > -single_Ye Then
    100.                     If y_Array(int_i) < single_Ye Then
    101.                         g.DrawLine(int_color, x_Array(int_i) * z1 - z1 * single_Xa, -y_Array(int_i) * z2 + z2 * single_Ya, x_Array(int_i + 1) * z1 - z1 * single_Xa, -y_Array(int_i + 1) * z2 + z2 * single_Ya)
    102.                     End If
    103.                 End If
    104.             Next
    105.         End If
    106.         PictureBox1.Image = bmp
    107.         Return single_Xa
    108.     End Function
    109.  
    110. End Class
    -------------------------------------------------------------------------
    FORM1
    VB Code:
    1. Public Class Form1
    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         Dim neu As New Form2
    4.         neu.BringToFront()
    5.         neu.Show()
    6.  
    7.     End Sub
    8.  
    9.     Private Sub ComboBox1_Selectedindexchanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    10.         Dim str As String = "Sinus"
    11.         Select Case str
    12.             Case "Sinus"
    13.                 Form2.main()
    14.             Case "Tan"
    15.        Form2.main1()
    16.         End Select
    17.  
    18.     End Sub
    Last edited by newbies; Nov 8th, 2006 at 05:16 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width