home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch06 / graphs / graph.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-20  |  5.4 KB  |  172 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Function Graphs"
  4.    ClientHeight    =   4500
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   6855
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   4500
  10.    ScaleWidth      =   6855
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Command3 
  13.       Caption         =   "Draw both functions"
  14.       BeginProperty Font 
  15.          Name            =   "Tahoma"
  16.          Size            =   9.75
  17.          Charset         =   0
  18.          Weight          =   400
  19.          Underline       =   0   'False
  20.          Italic          =   0   'False
  21.          Strikethrough   =   0   'False
  22.       EndProperty
  23.       Height          =   405
  24.       Left            =   4575
  25.       TabIndex        =   3
  26.       Top             =   3915
  27.       Width           =   2085
  28.    End
  29.    Begin VB.CommandButton Command2 
  30.       Caption         =   "Draw second function"
  31.       BeginProperty Font 
  32.          Name            =   "Tahoma"
  33.          Size            =   9.75
  34.          Charset         =   0
  35.          Weight          =   400
  36.          Underline       =   0   'False
  37.          Italic          =   0   'False
  38.          Strikethrough   =   0   'False
  39.       EndProperty
  40.       Height          =   405
  41.       Left            =   2385
  42.       TabIndex        =   2
  43.       Top             =   3915
  44.       Width           =   2085
  45.    End
  46.    Begin VB.CommandButton Command1 
  47.       Caption         =   "Draw first function"
  48.       BeginProperty Font 
  49.          Name            =   "Tahoma"
  50.          Size            =   9.75
  51.          Charset         =   0
  52.          Weight          =   400
  53.          Underline       =   0   'False
  54.          Italic          =   0   'False
  55.          Strikethrough   =   0   'False
  56.       EndProperty
  57.       Height          =   405
  58.       Left            =   210
  59.       TabIndex        =   1
  60.       Top             =   3915
  61.       Width           =   2085
  62.    End
  63.    Begin VB.PictureBox Picture1 
  64.       BackColor       =   &H00FFFFFF&
  65.       Height          =   3480
  66.       Left            =   165
  67.       ScaleHeight     =   228
  68.       ScaleMode       =   3  'Pixel
  69.       ScaleWidth      =   430
  70.       TabIndex        =   0
  71.       Top             =   135
  72.       Width           =   6510
  73.    End
  74. Attribute VB_Name = "Form1"
  75. Attribute VB_GlobalNameSpace = False
  76. Attribute VB_Creatable = False
  77. Attribute VB_PredeclaredId = True
  78. Attribute VB_Exposed = False
  79. Function FunctionEval1(ByVal X As Double) As Double
  80.     FunctionEval1 = Exp(2 / X) * Cos(2 * X)
  81. End Function
  82. Function FunctionEval2(ByVal X As Double) As Double
  83.     FunctionEval2 = Cos(3 * X) * Sin(5 * X)
  84. End Function
  85. Private Sub Command1_Click()
  86. Dim t As Double
  87. Dim XMin, XMax, YMin, YMax As Double
  88. YMin = 1E+101
  89. YMax = -1E+101
  90. XMin = 2
  91. XMax = 10
  92. Picture1.Cls
  93. Picture1.ScaleMode = 3
  94. XPixels = Picture1.ScaleWidth - 1
  95. ' Calculate Min and Max for Y axis
  96. For i = 1 To XPixels
  97.     t = XMin + (XMax - XMin) * i / XPixels
  98.     functionVal = FunctionEval1(t)
  99.     If functionVal > YMax Then YMax = functionVal
  100.     If functionVal < YMin Then YMin = functionVal
  101. ' Set up a user defined scale mode
  102. Picture1.Scale (XMin, YMin)-(XMax, YMax)
  103. Picture1.ForeColor = RGB(0, 0, 255)
  104. ' Moce to the first point
  105. Picture1.PSet (XMin, FunctionEval1(XMin))
  106. ' Plot the function
  107. For i = 0 To XPixels
  108.     t = XMin + (XMax - XMin) * i / XPixels
  109.     'Picture1.PSet (t, FunctionEval2(t))
  110.     Picture1.Line -(t, FunctionEval1(t))
  111. End Sub
  112. Private Sub Command2_Click()
  113. Dim t As Double
  114. Dim XMin, XMax, YMin, YMax As Double
  115. YMin = 1E+101
  116. YMax = -1E+101
  117. XMin = 2
  118. XMax = 10
  119. Picture1.Cls
  120. Picture1.ScaleMode = 3
  121. XPixels = Picture1.ScaleWidth - 1
  122. ' Calculate Min and Max for Y axis
  123. For i = 0 To XPixels
  124.     t = XMin + (XMax - XMin) * i / XPixels
  125.     functionVal = Cos(3 * t) * Sin(5 * t)
  126.     If functionVal > YMax Then YMax = functionVal
  127.     If functionVal < YMin Then YMin = functionVal
  128. ' Set up a user defined scale mode
  129. Picture1.Scale (XMin, YMin)-(XMax, YMax)
  130. Picture1.ForeColor = RGB(255, 0, 0)
  131. ' Plot the function
  132. For i = 0 To XPixels - 1
  133.     t = XMin + (XMax - XMin) * i / XPixels
  134.     functionVal = Cos(3 * t) * Sin(5 * t)
  135.     'Picture1.PSet (t, functionVal)
  136.     Picture1.Line -(t, functionVal)
  137. End Sub
  138. Private Sub Command3_Click()
  139. Dim t As Double
  140. Dim XMin, XMax, YMin, YMax As Double
  141. YMin = 1E+101
  142. YMax = -1E+101
  143. XMin = 2
  144. XMax = 10
  145. Picture1.Cls
  146. Picture1.ScaleMode = 3
  147. XPixels = Picture1.ScaleWidth - 1
  148. ' Calculate Min and Max for Y axis
  149. For i = 1 To XPixels
  150.     t = XMin + (XMax - XMin) * i / XPixels
  151.     functionVal = FunctionEval1(t)
  152.     If functionVal > YMax Then YMax = functionVal
  153.     If functionVal < YMin Then YMin = functionVal
  154. ' Set up a user defined scale mode
  155. Picture1.Scale (XMin, YMin)-(XMax, YMax)
  156. Picture1.ForeColor = RGB(0, 0, 255)
  157. ' Moce to the first point
  158. Picture1.PSet (XMin, FunctionEval1(XMin))
  159. ' Plot the function
  160. For i = 0 To XPixels
  161.     t = XMin + (XMax - XMin) * i / XPixels
  162.     'Picture1.PSet (t, FunctionEval2(t))
  163.     Picture1.Line -(t, FunctionEval1(t))
  164. Picture1.ForeColor = RGB(255, 0, 0)
  165. Picture1.PSet (XMin, FunctionEval2(XMin))
  166. ' Plot the function
  167. For i = 0 To XPixels
  168.     t = XMin + (XMax - XMin) * i / XPixels
  169.     'Picture1.PSet (t, FunctionEval2(t))
  170.     Picture1.Line -(t, FunctionEval2(t))
  171. End Sub
  172.