home *** CD-ROM | disk | FTP | other *** search
/ Computerworld 1996 March / Computerworld_1996-03_cd.bin / idg_cd3 / aplikace / cad / wplot211 / vbdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-23  |  6.3 KB  |  176 lines

  1. VERSION 2.00
  2. Begin Form vbdemo 
  3.    AutoRedraw      =   -1  'True
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "WPLOTCMD.DLL DEMO"
  6.    ClientHeight    =   2775
  7.    ClientLeft      =   1170
  8.    ClientTop       =   1545
  9.    ClientWidth     =   5940
  10.    Height          =   3210
  11.    Left            =   1095
  12.    LinkTopic       =   "vbdemo"
  13.    ScaleHeight     =   2775
  14.    ScaleWidth      =   5940
  15.    Top             =   1185
  16.    Width           =   6090
  17.    Begin CommandButton butok 
  18.       Caption         =   "OK"
  19.       Height          =   375
  20.       Left            =   2640
  21.       TabIndex        =   1
  22.       Top             =   1920
  23.       Width           =   735
  24.    End
  25.    Begin Label laby 
  26.       Caption         =   " "
  27.       Height          =   255
  28.       Left            =   3240
  29.       TabIndex        =   3
  30.       Top             =   2400
  31.       Width           =   1455
  32.    End
  33.    Begin Label labx 
  34.       Caption         =   " "
  35.       Height          =   255
  36.       Left            =   1680
  37.       TabIndex        =   2
  38.       Top             =   2400
  39.       Width           =   1335
  40.    End
  41.    Begin Label labprompt 
  42.       Alignment       =   2  'Center
  43.       BorderStyle     =   1  'Fixed Single
  44.       Caption         =   " "
  45.       Height          =   255
  46.       Left            =   120
  47.       TabIndex        =   0
  48.       Top             =   1560
  49.       Width           =   5655
  50.    End
  51. ' VBDEMO.FRM - Visual Basic Demo of using WPLOTCMD.DLL to send commands & data
  52. ' to WPlot.  Windows must know the path to WPLOTCMD.DLL, i.e., the DLL file
  53. ' must be in the Windows directory or the application's working directory or
  54. ' the path to the DLL file must be specified in the declarations of the DLL
  55. ' functions.  WPlot must be in the path specified as a parameter to the
  56. ' StartWPlot function.  This demo specifies a path of "c:\wplot\" for both
  57. ' WPlot and WPLOTCMD.DLL. Programmers: William G. Hood & Eric A. Hood, 9-16-95
  58. Option Explicit
  59. ' Can use just "wplotcmd.dll" if the DLL file is in the Windows directory
  60. Declare Function StartWPlot Lib "c:\wplot\wplotcmd.dll" (ByVal id As Integer, ByVal path As String) As Integer
  61. Declare Function WPlotcmd Lib "c:\wplot\wplotcmd.dll" (ByVal id As Integer, ByVal pcmd As String, ByVal nocheck As Integer) As Integer
  62. Const id = 1
  63. Dim state As Integer
  64. Dim errmes(4) As String
  65. Dim ydata(8) As Integer
  66. Sub butok_Click ()
  67.   Dim errcode As Integer
  68.   Dim i As Integer
  69.   Dim x As Double
  70.   Dim y As Double
  71.   Select Case state
  72.     Case 1
  73.       ' Launch WPlot from the specified path (use "" for default directory)
  74.       errcode = StartWPlot(id, "c:\wplot\")
  75.       If errcode > 0 Then
  76.         If errcode > 5 Then errcode = 5
  77.         MsgBox errmes(errcode - 1), 16, "ERROR"
  78.         End
  79.       End If
  80.        
  81.       send id, "winpos 0.5 45.0"  ' Set window position
  82.       send id, "plotsize 1"    ' Set small plot size
  83.       
  84.       labprompt.Caption = " Press the OK button to see a plot of data sent to WPlot."
  85.       state = 2
  86.     Case 2
  87.       send id, "title Demo of Controlling WPlot"
  88.       send id, "xlabel X-Axis"
  89.       send id, "ylabel Y-Axis"
  90.       send id, "xstart 0"
  91.       send id, "xend 10"
  92.       send id, "xstep 1"
  93.       send id, "ystart 0"
  94.       send id, "yend 1000"
  95.       send id, "ystep 200"
  96.       send id, "grids"
  97.       send id, "read 9"     ' Data points can be sent after a READ command
  98.       For i = 0 To 8
  99.         send id, Str$(i + 1) + " " + Str$(ydata(i))
  100.       Next i
  101.       send id, "curve 1"    ' The data set will be plotted as a smooth curve.
  102.       send id, "symbols"    ' A symbol will be plotted at each data point.
  103.       send id, "plot"       ' Plot previously read data points.
  104.       labprompt.Caption = " Press the OK button to plot data points as they are calculated."
  105.       state = 3
  106.     Case 3
  107.   ' Some special commands were added to WPlot for real-time data display:
  108.   ' rtplot         - Displays axes, title and labels even if no data.
  109.   ' rtdata   m     - Allocates memory for a maximum of m data points.
  110.   ' rtpoint  x  y  - Inputs and plots point (x,y).
  111.   ' rtend          - Terminates real-time plot & frees Windows resources.
  112.       send id, "rtdata 51"
  113.       For i = 0 To 50
  114.         x = i / 5#
  115.         y = x ^ 3 + 2# * x ^ 2 - 30# * x + 90
  116.         y = y + 20# * (2# * Rnd - 1)
  117.         labx.Caption = " X = " + Format(x, "0.00")
  118.         laby.Caption = " Y = " + Format(y, "0.00")
  119.         send id, "rtpoint " + Str$(x) + " " + Str$(y)
  120.       Next i
  121.       send id, "rtend"
  122.       labprompt.Caption = " Press the OK button to make a polynomial curve fit."
  123.       state = 4
  124.     Case 4
  125.       send id, "poly 3"
  126.       send id, "title Polynomial Curve Fit"
  127.       send id, "plot"
  128.       labprompt.Caption = " Press the OK button to exit."
  129.       labx.Caption = ""
  130.       laby.Caption = ""
  131.       state = 5
  132.     Case 5
  133.       send id, "exit"
  134.       End
  135.   End Select
  136. End Sub
  137. Sub Form_Load ()
  138.   left = 2   ' Position form at upper left corner of screen
  139.   top = 2
  140.   state = 1
  141.   errmes(0) = " Out of Memory"
  142.   errmes(1) = " Invalid ID"
  143.   errmes(2) = " File WPLOT.EXE not found"
  144.   errmes(3) = " Path to WPLOT.EXE not found"
  145.   errmes(4) = " Unspecified error"
  146.   ydata(0) = 125  ' Example data
  147.   ydata(1) = 175
  148.   ydata(2) = 350
  149.   ydata(3) = 750
  150.   ydata(4) = 900
  151.   ydata(5) = 750
  152.   ydata(6) = 350
  153.   ydata(7) = 175
  154.   ydata(8) = 125
  155.   Print
  156.   Print "  WPlot can be used to plot data collected, calculated, or"
  157.   Print "  processed by a user written C or Visual Basic program."
  158.   Print
  159.   Print "  This is an example of a Visual Basic program that plots data"
  160.   Print "  by sending the data and plot commands to WPlot using the"
  161.   Print "  functions in the Dynamic Link Library WPLOTCMD.DLL."
  162.   labprompt.ForeColor = QBColor(12)  ' Light Red
  163.   labprompt.Caption = " Press the OK button to start WPlot."
  164. End Sub
  165. Sub send (id As Integer, cmd As String)
  166. ' Sends command in string pcmd to WPLOTCMD.DLL using buffer #id.
  167. ' The routine keeps trying until the DLL is ready to accept the command.
  168. ' It displays an error message and terminates if it times out after 30 seconds.
  169.   Dim tstart As Long
  170.   tstart = Timer
  171.     If WPlotcmd(id, cmd, 0) = 0 Then Exit Sub
  172.   Loop While Timer - tstart < 30
  173.   MsgBox "WPlot is not responding", 16, "ERROR"
  174.   End
  175. End Sub
  176.