home *** CD-ROM | disk | FTP | other *** search
/ WDR Computer Club Digital 1994 October / COMPUTER_CLUB_1094.BIN / share / wnplot / dde_demo.frm < prev    next >
Text File  |  1994-08-18  |  16KB  |  474 lines

  1. VERSION 2.00
  2. Begin Form frmDDEDemo 
  3.    BackColor       =   &H00FFFFFF&
  4.    Caption         =   "WinPLOT DDE Demo"
  5.    ClientHeight    =   3030
  6.    ClientLeft      =   690
  7.    ClientTop       =   5760
  8.    ClientWidth     =   6315
  9.    Height          =   3435
  10.    Left            =   630
  11.    ScaleHeight     =   3030
  12.    ScaleWidth      =   6315
  13.    Top             =   5415
  14.    Width           =   6435
  15.    Begin HScrollBar hsbSpeed 
  16.       Height          =   255
  17.       Left            =   3840
  18.       Max             =   50
  19.       Min             =   1
  20.       TabIndex        =   9
  21.       Top             =   120
  22.       Value           =   1
  23.       Width           =   915
  24.    End
  25.    Begin CommandButton cmdNext 
  26.       Caption         =   " >"
  27.       Height          =   315
  28.       Left            =   1620
  29.       TabIndex        =   7
  30.       Top             =   60
  31.       Width           =   315
  32.    End
  33.    Begin Frame Frame2 
  34.       Caption         =   "Commands (no data)"
  35.       FontBold        =   0   'False
  36.       FontItalic      =   0   'False
  37.       FontName        =   "MS Sans Serif"
  38.       FontSize        =   8.25
  39.       FontStrikethru  =   0   'False
  40.       FontUnderline   =   0   'False
  41.       Height          =   1635
  42.       Left            =   3420
  43.       TabIndex        =   5
  44.       Top             =   1320
  45.       Width           =   2835
  46.       Begin TextBox txtCmd 
  47.          BorderStyle     =   0  'None
  48.          FontBold        =   0   'False
  49.          FontItalic      =   0   'False
  50.          FontName        =   "Courier New"
  51.          FontSize        =   8.25
  52.          FontStrikethru  =   0   'False
  53.          FontUnderline   =   0   'False
  54.          Height          =   1335
  55.          Left            =   60
  56.          MultiLine       =   -1  'True
  57.          TabIndex        =   6
  58.          Top             =   240
  59.          Width           =   2715
  60.       End
  61.    End
  62.    Begin Frame Frame1 
  63.       BackColor       =   &H00FFFFFF&
  64.       Caption         =   "Data file (commands && data)"
  65.       FontBold        =   0   'False
  66.       FontItalic      =   0   'False
  67.       FontName        =   "MS Sans Serif"
  68.       FontSize        =   8.25
  69.       FontStrikethru  =   0   'False
  70.       FontUnderline   =   0   'False
  71.       ForeColor       =   &H00000000&
  72.       Height          =   1635
  73.       Left            =   60
  74.       TabIndex        =   3
  75.       Top             =   1320
  76.       Width           =   3255
  77.       Begin TextBox txtData 
  78.          BorderStyle     =   0  'None
  79.          FontBold        =   0   'False
  80.          FontItalic      =   0   'False
  81.          FontName        =   "Courier New"
  82.          FontSize        =   8.25
  83.          FontStrikethru  =   0   'False
  84.          FontUnderline   =   0   'False
  85.          Height          =   1335
  86.          Left            =   60
  87.          MultiLine       =   -1  'True
  88.          TabIndex        =   4
  89.          Top             =   240
  90.          Width           =   3135
  91.       End
  92.    End
  93.    Begin CheckBox chkPause 
  94.       Caption         =   "Pause"
  95.       Height          =   195
  96.       Left            =   2700
  97.       TabIndex        =   2
  98.       Top             =   120
  99.       Width           =   915
  100.    End
  101.    Begin Timer Timer1 
  102.       Left            =   5820
  103.       Top             =   0
  104.    End
  105.    Begin CommandButton cmdDemo 
  106.       Caption         =   "Start Demo"
  107.       Height          =   315
  108.       Left            =   60
  109.       TabIndex        =   0
  110.       Top             =   60
  111.       Width           =   1395
  112.    End
  113.    Begin Label Label2 
  114.       Caption         =   "Speed"
  115.       Height          =   195
  116.       Left            =   4800
  117.       TabIndex        =   10
  118.       Top             =   120
  119.       Width           =   615
  120.    End
  121.    Begin Label Label1 
  122.       Caption         =   "Next"
  123.       Height          =   255
  124.       Left            =   1980
  125.       TabIndex        =   8
  126.       Top             =   120
  127.       Width           =   555
  128.    End
  129.    Begin Label lblDemoStatus 
  130.       BackColor       =   &H00FFFFFF&
  131.       Height          =   795
  132.       Left            =   60
  133.       TabIndex        =   1
  134.       Top             =   480
  135.       Width           =   6135
  136.    End
  137. End
  138. Option Explicit             ' use only defined vars only
  139.  
  140. Const w = 6.283185307       ' w=2*pi
  141. Const NONE = 0              ' No DDE
  142. Const MANUAL = 2            ' Manual DDE link
  143. Const AUTOMATIC = 1         ' Automatic DDE Link
  144. Const WHITE = &HFFFFFF      ' non selected background color
  145. Const GREEN = &H808000      ' selected background color
  146.  
  147. Dim crlf As String * 2      ' hold the crlfLF string combo
  148.  
  149. Dim nsamp As Integer        ' total number of samples
  150. Dim fs  As Single           ' sample frequency (Hz)
  151. Dim start As Integer        ' app startup flag
  152. Dim n As Integer            ' current sample # index
  153. Dim t As Single             ' current time of sample
  154. Dim x As Single
  155. Dim y1 As Single
  156. Dim y2 As Single
  157.  
  158. Dim cmd$                    ' used to build data
  159. Dim con$                    ' used as DDE connection name
  160.  
  161. '   Used to build up a command string
  162. '
  163. Sub AddCommand (t$)
  164.     cmd = cmd + t$ + crlf
  165. End Sub
  166.  
  167. '    used to pause demo if checked
  168. '
  169. Sub chkPause_Click ()
  170. End Sub
  171.  
  172. '   Main program loop - Once pressed the demo just loops
  173. '
  174. '   All demo link and command code is contained here
  175. '
  176. '   Basic mode of operation:
  177. '       1) Establish link                           (LinkTopic\Item\Mode)
  178. '       2) Send data file with necessary header     (LinkPoke)
  179. '       3) Send control commands                    (LinkExecute)
  180. '
  181. '
  182. Sub cmdDemo_Click ()
  183.   Do
  184.     lblDemoStatus = ""
  185.     DemoStatus "Welcome to the WinPLOT Demo using DDE control"
  186.     DemoStatus "Start WinPLOT for DDE if necessary"
  187.     start = True                                ' signal that you are starting a new instance of WinPLOT
  188.     con$ = "Demo"                               ' link connection instance name
  189.     On Error GoTo StartApp                      ' if connection failure then attempt to start
  190.     txtData.LinkMode = NONE
  191.     txtData.LinkTopic = "WinPLOT|" + con$       ' the connection string must be unique to this instance
  192.     txtData.LinkItem = "DDEData"                ' the actual name of the item in WinPLOT that accepts the data
  193.     txtData.LinkMode = MANUAL                   ' all operations will be manually issued
  194.     
  195. ' ----------------------------------------------------------------------------------------
  196.     DemoStatus "Generate a Sinc function data file and set all the default items."
  197.     DemoStatus "Then send the file off to WinPLOT to draw"
  198.     nsamp = 128      ' number of samples
  199.     fs = 80          ' sample frequency Hz
  200.     cmd = ""
  201.     AddCommand "DATASET=Demo"                       ' build the data header - all of the look and feel keywords are used here
  202.     AddCommand "SIGNAL=Sin(X)/X"
  203.     AddCommand "SAMPLE=X,sec.," + Str$(nsamp)
  204.     AddCommand "INTERVAL=" + Str$(1 / fs)           ' Note: This is a automatic X
  205.     AddCommand "DISPLAY=0,0,300,300"
  206.     AddCommand "PLOT_TYPE=rect"
  207.     AddCommand "SYMB_COLOR=blue,red"
  208.     AddCommand "SYMB_POINT=square,circle"
  209.     AddCommand "SYMB_LINE=solid,solid"
  210.     AddCommand "SET_X"                              ' shut off LOGs
  211.     AddCommand "SET_Y"
  212.     AddCommand "DATA"
  213.     t = -nsamp / 2 / fs
  214.     For n = 1 To nsamp                              ' build the data
  215.         t = t + 1 / fs
  216.         cmd = cmd + Str$(Sin(3 * w * t) / (3 * w * t)) + crlf   ' sinc function
  217.     Next n
  218.     txtCmd.BackColor = WHITE                        '
  219.     txtData.BackColor = GREEN                       ' show data as active window
  220.     txtData = cmd
  221.     txtData.LinkPoke                                ' send off data & header
  222.     Call subDelay(15)                               ' wait
  223. ' ----------------------------------------------------------------------------------------
  224.     lblDemoStatus = ""
  225.     DemoStatus "WinPLOT also supports Polar plots ..."
  226.     DemoStatus "Note the Keyword commands that are used."
  227.     DemoStatus "The ACTIVE and AUTO are off to aviod unnecessary actions."
  228.     cmd = ""
  229.     AddCommand "ACTIVE=off"
  230.     AddCommand "AUTO=off"
  231.     AddCommand "PLOT_TYPE=polar"
  232.     AddCommand "SET_X=-.1,1"
  233.     AddCommand "SET_Y=-.1,1"
  234.     AddCommand "DATASET=Polar"
  235.     AddCommand "REDRAW"
  236.     txtData.BackColor = WHITE
  237.     txtCmd.BackColor = GREEN
  238.     txtCmd = cmd
  239.     txtData.LinkExecute txtCmd                      ' Note LinkExecute is for commands
  240.     Call subDelay(15)
  241. ' ----------------------------------------------------------------------------------------
  242.     lblDemoStatus = ""
  243.     DemoStatus "WinPLOT can also preform some data transformations"
  244.     DemoStatus "Here is the frequency spectrum of the Sinc functions"
  245.     DemoStatus "Note the Y axis is LOG scale and the X-axis is Hz "
  246.     
  247.     cmd = ""
  248.     AddCommand "OPERATION=spec"
  249.     AddCommand "DATASET=Spectrum"
  250.     AddCommand "PLOT_TYPE=rect"
  251.     AddCommand "RESCALE"               ' force rescale on X
  252.     AddCommand "SET_Y=.001,100,log"    ' force log-Y
  253.     AddCommand "REDRAW"
  254.     txtCmd = cmd
  255.     txtData.LinkExecute txtCmd
  256.     Call subDelay(15)
  257. ' ----------------------------------------------------------------------------------------
  258.     lblDemoStatus = ""
  259.     DemoStatus "WinPLOT can handle can handle a number of signals"
  260.     cmd = ""
  261.     nsamp = 64
  262.     fs = nsamp / (4 * w)
  263.     AddCommand "DATASET=Multi Signal Interactive"
  264.     AddCommand "SIGNAL=Sin(X)/X,diff(Y1)"
  265.     AddCommand "SET_Y"
  266.     AddCommand "AUTO=on"   ' for next markers ??
  267.     AddCommand "ACTIVE=on"
  268.     AddCommand "DATA"
  269.     t = -nsamp / 2 / fs
  270.     For n = 1 To nsamp
  271.         t = t + 1 / fs                             ' t=1/f
  272.         y1 = Sin(t) / t                            ' sinc(t)
  273.         y2 = y1 - Sin(t - 1 / fs) / (t - 1 / fs)   ' diff(sinc(t))
  274.         cmd = cmd + Str$(t) + "," + Str$(y1) + "," + Str$(y2) + crlf    ' output signal
  275.     Next n
  276.     txtCmd.BackColor = WHITE
  277.     txtData.BackColor = GREEN
  278.     txtCmd = ""                                     ' just to show that the command window is not being used
  279.     txtData = cmd
  280.     txtData.LinkPoke
  281.     Call subDelay(5)
  282.     
  283. ' ----------------------------------------------------------------------------------------
  284.     DemoStatus "Interactive operation is via mouse or keyboard"
  285.     DemoStatus "Note the X & Y values being displayed"
  286.     cmd = ""
  287.     AddCommand "ACTIVE=on"
  288.     AddCommand "AUTO=off"
  289.     AddCommand "MARKER=25,1"
  290.     txtData.BackColor = WHITE
  291.     txtCmd.BackColor = GREEN
  292.     txtCmd = cmd
  293.     txtData.LinkExecute txtCmd
  294.     Call subDelay(1)
  295.     
  296.     For n = 1 To 10
  297.         cmd = ""
  298.         AddCommand "MARKER=" + Str$(25 + n) + ",1"
  299.         txtCmd = cmd
  300.         txtData.LinkExecute txtCmd
  301.         Call subDelay(.3)
  302.     Next n
  303.     DemoStatus "Now lets switch to signal #2"
  304.     Call subDelay(1)
  305.     For n = 1 To 10
  306.         cmd = ""
  307.         AddCommand "MARKER=" + Str$(35 - n) + ",2"
  308.         txtCmd = cmd
  309.         txtData.LinkExecute txtCmd
  310.         Call subDelay(.3)
  311.     Next n
  312.     Call subDelay(2)
  313. ' ----------------------------------------------------------------------------------------
  314.     lblDemoStatus = ""
  315.     DemoStatus "We can Zoom In"
  316.     cmd = ""
  317.     AddCommand "SET_X=-5,0.5"
  318.     AddCommand "SET_Y=-.3,.55"
  319.     AddCommand "REDRAW"
  320.     txtCmd = cmd
  321.     txtData.LinkExecute txtCmd
  322.     Call subDelay(3)
  323.     
  324.     DemoStatus "Change Signal colors and types "
  325.     DemoStatus "Also minimize plot "
  326.     cmd = ""
  327.     AddCommand "SYMB_COLOR=green, purple"
  328.     AddCommand "SYMB_LINE=dash, none"
  329.     AddCommand "DISPLAY=0,0,1,1"
  330.     AddCommand "REDRAW"
  331.     txtCmd = cmd
  332.     txtData.LinkExecute txtCmd
  333.     Call subDelay(10)
  334.  
  335. ' ----------------------------------------------------------------------------------------
  336.     lblDemoStatus = ""
  337.     txtCmd = ""
  338.     txtCmd.BackColor = WHITE
  339.     txtData.BackColor = GREEN
  340.     DemoStatus "WinPlot can also start up multiple windows"
  341.     con$ = "Demo2"                  ' a new instance
  342.     start = True
  343.     On Error GoTo StartApp
  344.     txtData.LinkMode = NONE
  345.     txtData.LinkTopic = "WinPLOT|" + con$
  346.     txtData.LinkItem = "DDEData"
  347.     txtData.LinkMode = MANUAL
  348.     txtData.LinkPoke
  349.     Call subDelay(3)
  350.     
  351.     DemoStatus "Start a second window ..."
  352.     DemoStatus "And position it below first"
  353.     cmd = ""
  354.     AddCommand "DISPLAY=0,170,1,1"
  355.     AddCommand "OPERATION=integ"
  356.     AddCommand "DATASET=Integration"
  357.     txtData.BackColor = WHITE
  358.     txtCmd.BackColor = GREEN
  359.     txtCmd = cmd
  360.     txtData.LinkExecute txtCmd
  361.     Call subDelay(4)
  362.     
  363. ' ----------------------------------------------------------------------------------------
  364.     lblDemoStatus = ""
  365.     DemoStatus "These are just some of the features available in WinPLOT"
  366.     DemoStatus "This VB DDE DemoStatus program is provided in the file 'DDE_DemoStatus.FRM'"
  367.     DemoStatus "See the on-line help for details. "
  368.     Call subDelay(20)
  369.     
  370.     DemoStatus "Now close this window"
  371.     cmd = ""
  372.     AddCommand "AUTO=off"
  373.     AddCommand "EXIT"           ' this will cause this instance of WinPLOT to terminate
  374.     txtCmd = cmd
  375.     txtData.LinkExecute txtCmd
  376.     Call subDelay(.1)
  377.     
  378.     txtCmd.BackColor = WHITE
  379.     txtData.BackColor = GREEN
  380.     txtCmd = ""
  381.   Loop
  382.  
  383. '       if WinPLOT has is not running then an error is generated
  384. '       note that with app.path DDE_DEMO must be in the same directory as WinPLOT
  385. StartApp:
  386.     If start = True Then start = Shell(app.Path + "\WINPLOT.EXE '" + con$ + "'", 1) ' shell only once if start is true to avoid instance errors
  387.     DoEvents                        ' give the system time to do something
  388.     If Err = 293 Then
  389.         Resume Next   ' if DDE lost connection then must have Exited
  390.     Else
  391.         Resume        ' other faliure then keep going until success
  392.     End If
  393. End Sub
  394.  
  395. '   used to bypass the delay function
  396. '
  397. Sub cmdNext_Click ()
  398.     cmdNext.Tag = "Clicked" ' used to tell the timmer fuction to continue
  399. End Sub
  400.  
  401. '   This sub is used to display the Demo Text Display
  402. '
  403. Sub DemoStatus (t$)
  404.     lblDemoStatus = lblDemoStatus + t$ + crlf
  405.     DoEvents            ' allow to be displayed when busy
  406. End Sub
  407.  
  408. '   This is a VB program which Demonstrates the use of Dynamic Data Exchange to Control WinPLOT.
  409. '   See the on-line help for full details on the available commands
  410. '
  411. '   The demo will highlight the box that is controlling
  412. '
  413. '   You can pause this demo and issue your own data & commands by typing in the boxes and then double ckicking on the box
  414. '
  415. '   NOTE: This program will not work with a unregistered copy of WinPLOT.
  416. '         The Link Topic of an unregistered copy is set to a hidden predetermined name.
  417. '         The compiled demo program (DDE_DEMO.EXE) will work because it was compiled with this special name.
  418. '
  419. '   >> Program starts here
  420. '
  421. Sub Form_Load ()
  422.     frmDDEDemo.Top = 360 * 15   ' position form  in bottom left corner
  423.     frmDDEDemo.Left = 0
  424.     crlf = Chr$(13) + Chr$(10)  ' carrage return & line feed characters
  425.     hsbSpeed.Value = 5          ' set default Demo speed
  426. End Sub
  427.  
  428. '    used for demo speed control
  429. '
  430. Sub hsbSpeed_Change ()
  431. End Sub
  432.  
  433. '   This sub is used as a general delay
  434. '   It works in conjunction with the Next, Pause and Delay controls
  435. '
  436. Sub subDelay (d As Single)
  437.     timer1.Interval = d * 1000 * 5 / hsbSpeed.Value ' delay in seconds adjusted
  438.     timer1.Tag = ""                                 ' clear the timer flag
  439.     timer1.Enabled = True                           ' start the timer
  440.     While (timer1.Tag = "" Or chkPause = 1) And cmdNext.Tag = ""
  441.         ' wait until any of the above occurs
  442.         DoEvents
  443.     Wend
  444.     cmdNext.Tag = ""
  445.     timer1.Enabled = False
  446. End Sub
  447.  
  448. '   Timer object used for delay function
  449. '
  450. Sub Timer1_Timer ()
  451.     timer1.Tag = "Done" ' When the timer is done
  452. End Sub
  453.  
  454. Sub txtCmd_DblClick ()
  455. '    On Error GoTo ErrHand
  456.     txtData.LinkExecute txtCmd
  457. '    Exit Sub
  458. 'ErrHand:
  459. '    Resume Next    ' for End command
  460.  
  461. End Sub
  462.  
  463. Sub txtData_DblClick ()
  464. '    On Error GoTo PokeError
  465.     txtData.LinkPoke
  466. '    Exit Sub
  467. 'PokeError:
  468. '    DoEvents
  469.     
  470. '    Resume
  471.  
  472. End Sub
  473.  
  474.