home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / disabl1r / sinewave.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-03-30  |  12.3 KB  |  396 lines

  1. VERSION 5.00
  2. Begin VB.Form frmSineWave 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   5265
  6.    ClientLeft      =   105
  7.    ClientTop       =   675
  8.    ClientWidth     =   8865
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    Moveable        =   0   'False
  13.    ScaleHeight     =   351
  14.    ScaleMode       =   3  'Pixel
  15.    ScaleWidth      =   591
  16.    StartUpPosition =   2  'CenterScreen
  17.    Begin VB.TextBox txXUnit 
  18.       BeginProperty Font 
  19.          Name            =   "MS Sans Serif"
  20.          Size            =   9.75
  21.          Charset         =   0
  22.          Weight          =   400
  23.          Underline       =   0   'False
  24.          Italic          =   0   'False
  25.          Strikethrough   =   0   'False
  26.       EndProperty
  27.       Height          =   360
  28.       Left            =   7875
  29.       MaxLength       =   4
  30.       TabIndex        =   15
  31.       Text            =   "35"
  32.       Top             =   4875
  33.       Width           =   900
  34.    End
  35.    Begin VB.TextBox txXMult 
  36.       BeginProperty Font 
  37.          Name            =   "MS Sans Serif"
  38.          Size            =   9.75
  39.          Charset         =   0
  40.          Weight          =   400
  41.          Underline       =   0   'False
  42.          Italic          =   0   'False
  43.          Strikethrough   =   0   'False
  44.       EndProperty
  45.       Height          =   360
  46.       Left            =   5700
  47.       MaxLength       =   4
  48.       TabIndex        =   7
  49.       Text            =   "1"
  50.       Top             =   4500
  51.       Width           =   900
  52.    End
  53.    Begin VB.CommandButton cmdGo 
  54.       Caption         =   "&Go"
  55.       Default         =   -1  'True
  56.       BeginProperty Font 
  57.          Name            =   "MS Sans Serif"
  58.          Size            =   8.25
  59.          Charset         =   0
  60.          Weight          =   700
  61.          Underline       =   0   'False
  62.          Italic          =   0   'False
  63.          Strikethrough   =   0   'False
  64.       EndProperty
  65.       Height          =   360
  66.       Left            =   7875
  67.       TabIndex        =   6
  68.       Top             =   4500
  69.       Width           =   915
  70.    End
  71.    Begin VB.PictureBox pctGraph 
  72.       AutoRedraw      =   -1  'True
  73.       BackColor       =   &H00C0C0C0&
  74.       ClipControls    =   0   'False
  75.       Height          =   3990
  76.       Left            =   75
  77.       ScaleHeight     =   262
  78.       ScaleMode       =   3  'Pixel
  79.       ScaleWidth      =   577
  80.       TabIndex        =   0
  81.       Top             =   75
  82.       Width           =   8715
  83.    End
  84.    Begin VB.TextBox txWide 
  85.       BeginProperty Font 
  86.          Name            =   "MS Sans Serif"
  87.          Size            =   9.75
  88.          Charset         =   0
  89.          Weight          =   400
  90.          Underline       =   0   'False
  91.          Italic          =   0   'False
  92.          Strikethrough   =   0   'False
  93.       EndProperty
  94.       Height          =   360
  95.       Left            =   3525
  96.       MaxLength       =   4
  97.       TabIndex        =   4
  98.       Text            =   "1"
  99.       Top             =   4500
  100.       Width           =   900
  101.    End
  102.    Begin VB.ComboBox cbWaveName 
  103.       BeginProperty Font 
  104.          Name            =   "MS Sans Serif"
  105.          Size            =   9.75
  106.          Charset         =   0
  107.          Weight          =   400
  108.          Underline       =   0   'False
  109.          Italic          =   0   'False
  110.          Strikethrough   =   0   'False
  111.       EndProperty
  112.       Height          =   360
  113.       ItemData        =   "SineWave.frx":0000
  114.       Left            =   5700
  115.       List            =   "SineWave.frx":0016
  116.       TabIndex        =   3
  117.       Text            =   "SIN"
  118.       Top             =   4875
  119.       Width           =   900
  120.    End
  121.    Begin VB.TextBox txHigh 
  122.       BeginProperty Font 
  123.          Name            =   "MS Sans Serif"
  124.          Size            =   9.75
  125.          Charset         =   0
  126.          Weight          =   400
  127.          Underline       =   0   'False
  128.          Italic          =   0   'False
  129.          Strikethrough   =   0   'False
  130.       EndProperty
  131.       Height          =   360
  132.       Left            =   3525
  133.       MaxLength       =   4
  134.       TabIndex        =   2
  135.       Text            =   "1"
  136.       Top             =   4875
  137.       Width           =   900
  138.    End
  139.    Begin VB.TextBox txYPos 
  140.       BeginProperty Font 
  141.          Name            =   "MS Sans Serif"
  142.          Size            =   9.75
  143.          Charset         =   0
  144.          Weight          =   400
  145.          Underline       =   0   'False
  146.          Italic          =   0   'False
  147.          Strikethrough   =   0   'False
  148.       EndProperty
  149.       Height          =   360
  150.       Left            =   1350
  151.       MaxLength       =   4
  152.       TabIndex        =   1
  153.       Text            =   "0"
  154.       Top             =   4875
  155.       Width           =   900
  156.    End
  157.    Begin VB.TextBox txXPos 
  158.       BeginProperty Font 
  159.          Name            =   "MS Sans Serif"
  160.          Size            =   9.75
  161.          Charset         =   0
  162.          Weight          =   400
  163.          Underline       =   0   'False
  164.          Italic          =   0   'False
  165.          Strikethrough   =   0   'False
  166.       EndProperty
  167.       Height          =   360
  168.       Left            =   1350
  169.       MaxLength       =   4
  170.       TabIndex        =   5
  171.       Text            =   "0"
  172.       Top             =   4500
  173.       Width           =   900
  174.    End
  175.    Begin VB.Label Label7 
  176.       Alignment       =   1  'Right Justify
  177.       AutoSize        =   -1  'True
  178.       BackStyle       =   0  'Transparent
  179.       Caption         =   "X Unit (pixels):"
  180.       Height          =   195
  181.       Left            =   6825
  182.       TabIndex        =   16
  183.       Top             =   4875
  184.       Width           =   1005
  185.    End
  186.    Begin VB.Label lblScale 
  187.       AutoSize        =   -1  'True
  188.       BackStyle       =   0  'Transparent
  189.       Height          =   195
  190.       Left            =   75
  191.       TabIndex        =   14
  192.       Top             =   4125
  193.       Width           =   45
  194.    End
  195.    Begin VB.Label Label6 
  196.       Alignment       =   1  'Right Justify
  197.       AutoSize        =   -1  'True
  198.       BackStyle       =   0  'Transparent
  199.       Caption         =   "Wave Type:"
  200.       Height          =   195
  201.       Left            =   4770
  202.       TabIndex        =   13
  203.       Top             =   4875
  204.       Width           =   885
  205.    End
  206.    Begin VB.Label Label5 
  207.       Alignment       =   1  'Right Justify
  208.       AutoSize        =   -1  'True
  209.       BackStyle       =   0  'Transparent
  210.       Caption         =   "Width Multiplier:"
  211.       Height          =   195
  212.       Left            =   4530
  213.       TabIndex        =   12
  214.       Top             =   4500
  215.       Width           =   1125
  216.    End
  217.    Begin VB.Label Label4 
  218.       Alignment       =   1  'Right Justify
  219.       AutoSize        =   -1  'True
  220.       BackStyle       =   0  'Transparent
  221.       Caption         =   "X Axis Position:"
  222.       Height          =   195
  223.       Left            =   225
  224.       TabIndex        =   11
  225.       Top             =   4500
  226.       Width           =   1080
  227.    End
  228.    Begin VB.Label Label3 
  229.       Alignment       =   1  'Right Justify
  230.       AutoSize        =   -1  'True
  231.       BackStyle       =   0  'Transparent
  232.       Caption         =   "Wavelength:"
  233.       Height          =   195
  234.       Left            =   2565
  235.       TabIndex        =   10
  236.       Top             =   4500
  237.       Width           =   915
  238.    End
  239.    Begin VB.Label Label2 
  240.       Alignment       =   1  'Right Justify
  241.       AutoSize        =   -1  'True
  242.       BackStyle       =   0  'Transparent
  243.       Caption         =   "Amplitude:"
  244.       Height          =   195
  245.       Left            =   2745
  246.       TabIndex        =   9
  247.       Top             =   4875
  248.       Width           =   735
  249.    End
  250.    Begin VB.Label Label1 
  251.       Alignment       =   1  'Right Justify
  252.       AutoSize        =   -1  'True
  253.       BackStyle       =   0  'Transparent
  254.       Caption         =   "Y Axis Position:"
  255.       Height          =   195
  256.       Left            =   225
  257.       TabIndex        =   8
  258.       Top             =   4875
  259.       Width           =   1080
  260.    End
  261. Attribute VB_Name = "frmSineWave"
  262. Attribute VB_GlobalNameSpace = False
  263. Attribute VB_Creatable = False
  264. Attribute VB_PredeclaredId = True
  265. Attribute VB_Exposed = False
  266. Option Explicit
  267. Sub Graph()
  268. Dim i As OrderedPair
  269. Dim Pt1 As OrderedPair, Pt2 As OrderedPair
  270. Dim Began As Boolean, NextSwp As Boolean
  271. Dim Start As OrderedPair
  272.     On Error GoTo Infinite
  273.     pctGraph.DrawWidth = 1
  274.     pctGraph.ForeColor = vbGreen
  275.     Start.X = CInt(-CenterPoint.X * 180 / PixelUnit)
  276.     Start.Y = CInt((pctGraph.ScaleWidth - CenterPoint.X) * 180 / PixelUnit)
  277.     For i.X = Start.X To Start.Y
  278.         If NextSwp = True Then
  279.             NextSwp = False
  280.             Began = False
  281.         End If
  282.         i.Y = GetWaveY(i.X)
  283.         Pt1.X = 2 * WvWide * (WvXMult * i.X + WvXPos) * PixelUnit / 180
  284.         Pt1.Y = i.Y + (-WvYPos * PixelUnit)
  285.         Pt1 = GetGraphPos(Pt1)
  286.         If Abs(Wave(i.X)) > ScaleHeight Then
  287.             If NextSwp = False Then
  288.                 Pt1.Y = ScaleHeight * GetSign(Pt1.Y)
  289.             End If
  290.             NextSwp = True
  291.         End If
  292.         If Began Then
  293.             pctGraph.Line (Pt1.X, Pt1.Y)-(Pt2.X, Pt2.Y)
  294.         End If
  295.         If Not Began Then Began = True
  296.         Pt2 = Pt1
  297.     Next i.X
  298.     Exit Sub
  299. Infinite:
  300.     NextSwp = True
  301.     Resume Next
  302. End Sub
  303. Sub DrawGraph()
  304. Dim Location As OrderedPair, i As Integer
  305. Dim CX As Currency, CY As Currency
  306.     pctGraph.Cls
  307.     pctGraph.ForeColor = vbBlack
  308.     If PixelUnit = 0 Then PixelUnit = 35
  309.     CX = CenterPoint.X / PixelUnit
  310.     CY = CenterPoint.Y / PixelUnit
  311.     Squares.X = Int(pctGraph.ScaleWidth / PixelUnit) + 1 + 1 * Abs(Int(GetFraction(CenterPoint.X / PixelUnit) > 0))
  312.     Squares.Y = Int(pctGraph.ScaleWidth / PixelUnit) + 1 + 1 * Abs(Int(GetFraction(CenterPoint.Y / PixelUnit) > 0))
  313.     Debug.Print Squares.X
  314.     Location.X = GetFraction(CX) * PixelUnit
  315.     Location.Y = GetFraction(CY) * PixelUnit
  316.     DrawLines Location, True
  317.     DrawLines Location, False
  318.     DrawAxis
  319.     DisplayInf
  320. End Sub
  321. Private Sub DrawLines(Beginning As OrderedPair, XMode As Boolean)
  322. Dim i As Long, POS As Currency
  323. Dim Finished As Boolean
  324.     i = -1
  325.     DrawWidth = 1
  326.     ForeColor = vbBlack
  327.     Do Until Finished = True
  328.         i = i + 1
  329.         If XMode Then
  330.             POS = Beginning.X + (i * PixelUnit)
  331.             pctGraph.Line (POS, 0)-(POS, pctGraph.ScaleHeight)
  332.             Finished = (i > pctGraph.ScaleWidth)
  333.         Else
  334.             POS = Beginning.Y + (i * PixelUnit)
  335.             pctGraph.Line (0, POS)-(pctGraph.ScaleWidth, POS)
  336.             Finished = (i > pctGraph.ScaleWidth)
  337.         End If
  338.     Loop
  339. End Sub
  340. Sub DrawAxis()
  341.     pctGraph.DrawWidth = 1
  342.     pctGraph.ForeColor = vbMagenta
  343.     pctGraph.Line (0, CenterPoint.Y)-(pctGraph.ScaleWidth, CenterPoint.Y)
  344.     pctGraph.ForeColor = vbCyan
  345.     pctGraph.Line (CenterPoint.X, 0)-(CenterPoint.X, pctGraph.ScaleHeight)
  346. End Sub
  347. Private Sub cmdGo_Click()
  348.     WvType = GetType(cbWaveName.Text)
  349.     WvHigh = Val(txHigh)
  350.     WvWide = Val(txWide)
  351.     WvXPos = Val(txXPos)
  352.     WvYPos = Val(txYPos)
  353.     WvXMult = Val(txXMult)
  354.     PixelUnit = Val(txXUnit)
  355.     DrawGraph
  356.     Graph
  357.     DisplayInf
  358. End Sub
  359. Sub DisplayInf()
  360.     Caption = "y = " & WvYPos & " + " & WvHigh & " " & WaveName & " " & WvXMult & " [ (" & WvWide & ") X + " & WvXPos & " ]"
  361.     lblScale = "(Box Scale = 90 x 1)"
  362. End Sub
  363. Private Sub pctGraph_DblClick()
  364.     WvWide = -0.25
  365.     WvHigh = -1
  366.     WvXPos = 2
  367.     WvYPos = -5
  368.     WvType = Int(Rnd * 3)
  369.     CenterPoint.X = pctGraph.ScaleWidth / 2
  370.     CenterPoint.Y = pctGraph.ScaleHeight / 2
  371.     PixelUnit = 25
  372.     DrawGraph
  373.     Graph
  374. End Sub
  375. Function GetFraction(Number As Currency) As Currency
  376.     GetFraction = Number - Int(Number)
  377. End Function
  378. Function GetInteger(Number As Currency) As Integer
  379.     GetInteger = Number - (Number - (Int(Number)))
  380. End Function
  381. Private Sub pctGraph_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  382.     If Button <> 2 Then Exit Sub
  383.     CenterPoint.X = X
  384.     CenterPoint.Y = Y
  385.     DrawGraph
  386.     Graph
  387. End Sub
  388. Sub FitText(Ctl As Control)
  389. Dim Blink As Integer
  390.     Blink = Ctl.SelStart
  391.     Ctl.SelText = ""
  392.     Ctl.SelStart = 0
  393.     PositionLabels
  394.     Ctl.SelStart = Blink
  395. End Sub
  396.