home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / alexrk / alex.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  28.6 KB  |  958 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Alex's Rocket Programmer "
  5.    ClientHeight    =   6330
  6.    ClientLeft      =   120
  7.    ClientTop       =   1635
  8.    ClientWidth     =   9570
  9.    ForeColor       =   &H80000001&
  10.    Height          =   7020
  11.    Icon            =   ALEX.FRX:0000
  12.    Left            =   60
  13.    LinkMode        =   1  'Source
  14.    LinkTopic       =   "Form1"
  15.    ScaleHeight     =   6330
  16.    ScaleWidth      =   9570
  17.    Top             =   1005
  18.    Width           =   9690
  19.    Begin TextBox SlopeBox 
  20.       Height          =   360
  21.       Left            =   135
  22.       TabIndex        =   28
  23.       Top             =   5920
  24.       Width           =   510
  25.    End
  26.    Begin Frame Frame1 
  27.       Caption         =   "Colors"
  28.       Height          =   2295
  29.       Left            =   120
  30.       TabIndex        =   12
  31.       Top             =   3270
  32.       Width           =   1095
  33.       Begin OptionButton White 
  34.          Caption         =   "White"
  35.          ForeColor       =   &H00FFFFFF&
  36.          Height          =   380
  37.          Left            =   120
  38.          TabIndex        =   17
  39.          Top             =   1680
  40.          Width           =   855
  41.       End
  42.       Begin OptionButton Black 
  43.          Caption         =   "Black"
  44.          ForeColor       =   &H80000007&
  45.          Height          =   380
  46.          Left            =   120
  47.          TabIndex        =   16
  48.          Top             =   1320
  49.          Width           =   855
  50.       End
  51.       Begin OptionButton Red 
  52.          Caption         =   "Red"
  53.          ForeColor       =   &H80000001&
  54.          Height          =   380
  55.          Left            =   120
  56.          TabIndex        =   15
  57.          Top             =   960
  58.          Width           =   855
  59.       End
  60.       Begin OptionButton Green 
  61.          Caption         =   "Green"
  62.          ForeColor       =   &H80000004&
  63.          Height          =   380
  64.          Left            =   120
  65.          TabIndex        =   14
  66.          Top             =   600
  67.          Width           =   855
  68.       End
  69.       Begin OptionButton Blue 
  70.          Caption         =   "Blue"
  71.          Height          =   380
  72.          Left            =   120
  73.          TabIndex        =   13
  74.          Top             =   240
  75.          Value           =   -1  'True
  76.          Width           =   735
  77.       End
  78.    End
  79.    Begin OptionButton Option5 
  80.       Caption         =   "50"
  81.       ForeColor       =   &H80000001&
  82.       Height          =   375
  83.       Left            =   225
  84.       TabIndex        =   10
  85.       Top             =   2880
  86.       Value           =   -1  'True
  87.       Width           =   615
  88.    End
  89.    Begin OptionButton Option4 
  90.       Caption         =   "40"
  91.       ForeColor       =   &H80000001&
  92.       Height          =   375
  93.       Left            =   240
  94.       TabIndex        =   9
  95.       Top             =   2475
  96.       Width           =   615
  97.    End
  98.    Begin OptionButton Option3 
  99.       Caption         =   "30"
  100.       ForeColor       =   &H80000001&
  101.       Height          =   495
  102.       Left            =   240
  103.       TabIndex        =   8
  104.       Top             =   1995
  105.       Width           =   615
  106.    End
  107.    Begin OptionButton Option2 
  108.       Caption         =   "20"
  109.       ForeColor       =   &H80000001&
  110.       Height          =   375
  111.       Left            =   240
  112.       TabIndex        =   7
  113.       Top             =   1680
  114.       Width           =   615
  115.    End
  116.    Begin TextBox ProgramBox 
  117.       Height          =   4820
  118.       Left            =   7440
  119.       MultiLine       =   -1  'True
  120.       ScrollBars      =   2  'Vertical
  121.       TabIndex        =   24
  122.       Top             =   1460
  123.       Width           =   1935
  124.    End
  125.    Begin PictureBox Picture1 
  126.       ForeColor       =   &H80000004&
  127.       Height          =   4820
  128.       Left            =   1440
  129.       ScaleHeight     =   4785
  130.       ScaleWidth      =   5985
  131.       TabIndex        =   11
  132.       Top             =   1460
  133.       Width           =   6015
  134.    End
  135.    Begin OptionButton Option1 
  136.       Caption         =   "10"
  137.       ForeColor       =   &H80000001&
  138.       Height          =   375
  139.       Left            =   240
  140.       TabIndex        =   6
  141.       Top             =   1275
  142.       Width           =   615
  143.    End
  144.    Begin TextBox TestBox 
  145.       Height          =   360
  146.       Left            =   7440
  147.       TabIndex        =   26
  148.       Top             =   1100
  149.       Width           =   1935
  150.    End
  151.    Begin CommandButton Quit 
  152.       Caption         =   "Quit"
  153.       Height          =   380
  154.       Left            =   8280
  155.       TabIndex        =   30
  156.       Top             =   600
  157.       Width           =   1215
  158.    End
  159.    Begin CommandButton Run_Program 
  160.       Caption         =   "Run Program"
  161.       Height          =   380
  162.       Left            =   6855
  163.       TabIndex        =   19
  164.       Top             =   600
  165.       Width           =   1215
  166.    End
  167.    Begin CommandButton Diag_DnL 
  168.       Caption         =   "Diag Dn-L"
  169.       Height          =   380
  170.       Left            =   5520
  171.       TabIndex        =   23
  172.       Top             =   620
  173.       Width           =   1095
  174.    End
  175.    Begin CommandButton Diag_DnR 
  176.       Caption         =   "Diag Dn-R"
  177.       Height          =   380
  178.       Left            =   4200
  179.       TabIndex        =   21
  180.       Top             =   600
  181.       Width           =   1095
  182.    End
  183.    Begin CommandButton Down_50 
  184.       Caption         =   "&Down"
  185.       Height          =   380
  186.       Left            =   2880
  187.       TabIndex        =   5
  188.       Top             =   600
  189.       Width           =   1095
  190.    End
  191.    Begin CommandButton Up_50 
  192.       Caption         =   "&Up"
  193.       Height          =   380
  194.       Left            =   1560
  195.       TabIndex        =   4
  196.       Top             =   600
  197.       Width           =   1095
  198.    End
  199.    Begin CommandButton Clr 
  200.       Caption         =   "Clear"
  201.       Height          =   380
  202.       Left            =   240
  203.       TabIndex        =   1
  204.       Top             =   600
  205.       Width           =   1095
  206.    End
  207.    Begin CommandButton ColorFill 
  208.       Caption         =   "Color Fill"
  209.       Height          =   380
  210.       Left            =   8280
  211.       TabIndex        =   18
  212.       Top             =   120
  213.       Width           =   1215
  214.    End
  215.    Begin CommandButton Scribble 
  216.       Caption         =   "Scribble"
  217.       Height          =   380
  218.       Left            =   6840
  219.       TabIndex        =   25
  220.       Top             =   120
  221.       Width           =   1215
  222.    End
  223.    Begin CommandButton Diag_UpL 
  224.       Caption         =   "Diag Up-L"
  225.       Height          =   380
  226.       Left            =   5520
  227.       TabIndex        =   22
  228.       Top             =   120
  229.       Width           =   1095
  230.    End
  231.    Begin CommandButton Diag_UpR 
  232.       Caption         =   "Diag Up-R"
  233.       Height          =   380
  234.       Left            =   4200
  235.       TabIndex        =   20
  236.       Top             =   120
  237.       Width           =   1095
  238.    End
  239.    Begin CommandButton Backward_50 
  240.       Caption         =   "&Backward"
  241.       Height          =   380
  242.       Left            =   2880
  243.       TabIndex        =   3
  244.       Top             =   120
  245.       Width           =   1095
  246.    End
  247.    Begin CommandButton Forward_50 
  248.       Caption         =   "&Forward"
  249.       Height          =   380
  250.       Left            =   1575
  251.       TabIndex        =   2
  252.       Top             =   120
  253.       Width           =   1095
  254.    End
  255.    Begin CommandButton Draw_A_Star 
  256.       Caption         =   "Draw a &Star"
  257.       Height          =   380
  258.       Left            =   240
  259.       TabIndex        =   0
  260.       Top             =   120
  261.       Width           =   1095
  262.    End
  263.    Begin Label Label2 
  264.       Caption         =   "Slope"
  265.       Height          =   300
  266.       Left            =   120
  267.       TabIndex        =   29
  268.       Top             =   5655
  269.       Width           =   1155
  270.    End
  271.    Begin Label Label3 
  272.       Caption         =   "Single Line Entry"
  273.       Height          =   300
  274.       Left            =   5535
  275.       TabIndex        =   31
  276.       Top             =   1140
  277.       Width           =   1845
  278.    End
  279.    Begin Label Label1 
  280.       Caption         =   "Distance"
  281.       Height          =   255
  282.       Left            =   120
  283.       TabIndex        =   27
  284.       Top             =   1035
  285.       Width           =   1215
  286.    End
  287.    Begin Menu FilePrint 
  288.       Caption         =   "File"
  289.       Begin Menu OpenCmdFile 
  290.          Caption         =   "Open Command File"
  291.       End
  292.       Begin Menu SaveCmdFile 
  293.          Caption         =   "Save Command File"
  294.       End
  295.    End
  296.    Begin Menu DisplayHelp 
  297.       Caption         =   "Help (F1)"
  298.       Begin Menu HelpQuickTour 
  299.          Caption         =   "Quick Tour"
  300.          Visible         =   0   'False
  301.       End
  302.       Begin Menu HelpCommands 
  303.          Caption         =   "Commands"
  304.          Shortcut        =   {F1}
  305.       End
  306.       Begin Menu HelpRegistration 
  307.          Caption         =   "Registration"
  308.          Visible         =   0   'False
  309.       End
  310.       Begin Menu HelpAbout 
  311.          Caption         =   "About "
  312.          Visible         =   0   'False
  313.       End
  314.    End
  315. Dim Color As String
  316. Dim TextBoxLine As Integer
  317. Dim NL As String
  318. Dim CommandLine As String
  319. Dim CommandWord(0 To 2) As String
  320. ' arrays used for testing parsing procedure
  321. Dim aarray(0 To 10)
  322. Dim jarray(0 To 10)
  323. Dim karray(0 To 10)
  324. Dim marray(0 To 10)
  325. Dim narray(0 To 10)
  326. Dim Dis As Integer
  327. Dim j As Integer
  328. Dim k As Integer
  329. Dim l As Integer
  330. Dim m As Integer
  331. Dim n As Integer
  332. Dim DrawNow As Integer
  333. Dim ScribbleOn As Integer
  334. Dim LC As Integer
  335. Dim LineNumber As Long
  336. Dim CharPos As Long
  337. Dim FileNum As Integer
  338. Dim NametoUse As String
  339. Dim ErrorCode As Integer
  340. Declare Function GetFocus% Lib "user" ()
  341. Declare Function SendMessage% Lib "user" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, ByVal lParam As Any)
  342. Sub Backward ()
  343. Old_X = X
  344. Old_Y = Y
  345. Rem ** Move to left **
  346. For I = 0 To Distance Step .5
  347.     Picture1.PSet ((Max((X - I), MinNum)), Y)
  348.     Next
  349.  X = Max((X - I), MinNum)
  350.  Y = Old_Y
  351. End Sub
  352. Sub Backward_50_Click ()
  353. Backward
  354. WriteToProgramBox ("B")
  355. End Sub
  356. Sub Black_Click ()
  357. Form1.Picture1.ForeColor = RGB(0, 0, 0)
  358. Color$ = "Black"
  359. End Sub
  360. Sub Blue_Click ()
  361. Form1.Picture1.ForeColor = RGB(0, 0, 255)
  362. Color$ = "Blue"
  363. End Sub
  364. Sub Clr_Click ()
  365.  Picture1.Cls
  366.  X = DefaultX
  367.  Y = DefaultY
  368. End Sub
  369. Sub ColorFill_Click ()
  370. If BLUE.Value = True Then
  371. Form1.Picture1.BackColor = RGB(0, 0, 255)
  372. ElseIf GREEN.Value = True Then
  373.    Form1.Picture1.BackColor = RGB(0, 255, 0)
  374. ElseIf RED.Value = True Then
  375.    Form1.Picture1.BackColor = RGB(255, 0, 0)
  376. ElseIf Black.Value = True Then
  377.    Form1.Picture1.BackColor = RGB(0, 0, 0)
  378. ElseIf White.Value = True Then
  379.    Form1.Picture1.BackColor = RGB(255, 255, 255)
  380. End If
  381. End Sub
  382. Sub Command2_Click ()
  383. Form1.Cls
  384. End Sub
  385. Sub Diag_DnL_Click ()
  386. DiagDownLeft
  387. WriteToProgramBox ("DDL")
  388. End Sub
  389. Sub Diag_DnR_Click ()
  390. DiagDownRight
  391. WriteToProgramBox ("DDR")
  392. End Sub
  393. Sub Diag_UpL_Click ()
  394. DiagUpLeft
  395. WriteToProgramBox ("DUL")
  396. End Sub
  397. Sub Diag_UpR_Click ()
  398. DiagUpRight
  399. WriteToProgramBox ("DUR")
  400. End Sub
  401. Sub DiagDownLeft ()
  402. Picture1.drawwidth = 3
  403. Old_X = X
  404. Old_Y = Y
  405. Slope = Val(SlopeBox.Text)
  406. Dim EndOfFrameReached As String
  407. ' ** upper left to lower right (-x,+y)  **
  408. ' ** 2X slope - 1.0 / .5 **
  409.  For I = 0 To Distance Step .2
  410.     Picture1.PSet ((Max((X - (I * (1 / Slope))), MinNum)), (Min((Y + I), MaxNum)))
  411.     'stop loop if end of picture frame is reached
  412.     'min X (far left of frame)
  413.     If Max((X - (I * (1 / Slope))), MinNum) = MinNum Then
  414.        New_Y = Y + I
  415.        New_X = MinNum
  416.        EndOfFrameReached = "TRUE"
  417.     End If
  418.     'max Y (bot of frame)
  419.     If Min((Y + I), MaxNum) = MaxNum Then
  420.        New_X = X - (I * (1 / Slope))
  421.        New_Y = MaxNum
  422.        EndOfFrameReached = "TRUE"
  423.     End If
  424.     ' Can't reset value of I until positions of x and y are
  425.     ' checked, otherwise setting I in first if statement
  426.     ' may cause second if statement to execute also
  427.     If EndOfFrameReached = "TRUE" Then
  428.        I = Distance + 1
  429.        X = New_X
  430.        Y = New_Y
  431.     End If
  432. ' reset both points to full distance only if edges of frame not reached
  433. If X <> MinNum And Y <> MaxNum Then
  434.    X = Max((X - (I * (1 / Slope))), MinNum)
  435.    Y = Min((Y + I), MaxNum)
  436. End If
  437. Picture1.drawwidth = 4
  438. End Sub
  439. Sub DiagDownRight ()
  440. Picture1.drawwidth = 3
  441. Old_X = X
  442. Old_Y = Y
  443. Slope = Val(SlopeBox.Text)
  444. Dim EndOfFrameReached As String
  445. ' ** upper left to lower right (+x,+y)  **
  446. ' ** 2X slope - 1.0 / .5 **
  447.  For I = 0 To Distance Step .2
  448.     Picture1.PSet ((Min((X + (I * (1 / Slope))), MaxNum)), (Min((Y + I), MaxNum)))
  449.     'stop loop if end of picture frame is reached
  450.     'min X (far right of frame)
  451.     If Min((X + (I * (1 / Slope))), MaxNum) = MaxNum Then
  452.        New_Y = Y + I
  453.        New_X = MaxNum
  454.        EndOfFrameReached = "TRUE"
  455.     End If
  456.     'max Y (bot of frame)
  457.     If Min((Y + I), MaxNum) = MaxNum Then
  458.        New_X = X + (I * (1 / Slope))
  459.        New_Y = MaxNum
  460.        EndOfFrameReached = "TRUE"
  461.     End If
  462.     ' Can't reset value of I until positions of x and y are
  463.     ' checked, otherwise setting I in first if statement
  464.     ' may cause second if statement to execute also
  465.     If EndOfFrameReached = "TRUE" Then
  466.        I = Distance + 1
  467.        X = New_X
  468.        Y = New_Y
  469.     End If
  470. ' reset both points to full distance only if edges of frame not reached
  471. If X <> MaxNum And Y <> MaxNum Then
  472.    X = Min((X + (I * (1 / Slope))), MaxNum)
  473.    Y = Min((Y + I), MaxNum)
  474. End If
  475. Picture1.drawwidth = 4
  476. End Sub
  477. Sub DiagUpLeft ()
  478. Picture1.drawwidth = 3
  479. Old_X = X
  480. Old_Y = Y
  481. Slope = Val(SlopeBox.Text)
  482. Dim EndOfFrameReached As String
  483. ' ** lower left to upper middle (+x,-y)  **
  484. ' ** 2X slope - 1.0 / .5 **
  485.  For I = 0 To Distance Step .2
  486.     Picture1.PSet ((Max((X - (I * (1 / Slope))), MinNum)), (Max((Y - I), MinNum)))
  487.     'stop loop if end of picture frame is reached
  488.     'min X (far left of frame)
  489.     If Max((X - (I * (1 / Slope))), MinNum) = MinNum Then
  490.        New_Y = Y - I
  491.        New_X = MinNum
  492.        EndOfFrameReached = "TRUE"
  493.     End If
  494.     'min Y (top of frame)
  495.     If Max((Y - I), MinNum) = MinNum Then
  496.        New_X = X - (I * (1 / Slope))
  497.        New_Y = MinNum
  498.        EndOfFrameReached = "TRUE"
  499.     End If
  500.     ' Can't reset value of I until positions of x and y are
  501.     ' checked, otherwise setting I in first if statement
  502.     ' may cause second if statement to execute also
  503.     If EndOfFrameReached = "TRUE" Then
  504.        I = Distance + 1
  505.        X = New_X
  506.        Y = New_Y
  507.     End If
  508.  Next
  509. ' reset both points to full distance only if edges of frame not reached
  510. If X <> MinNum And Y <> MinNum Then
  511.    X = Max((X - (I * (1 / Slope))), MinNum)
  512.    Y = Max((Y - I), MinNum)
  513. End If
  514. Picture1.drawwidth = 4
  515. End Sub
  516. Sub DiagUpRight ()
  517. Picture1.drawwidth = 3
  518. Old_X = X
  519. Old_Y = Y
  520. Slope = Val(SlopeBox.Text)
  521. Dim EndOfFrameReached As String
  522. ' add slope to form and here slope 2 = 1/slope = .5
  523.  Rem ** lower left to upper middle (+x,-y)  **
  524.  Rem ** 2X slope - 1.0 / .5 **
  525.  For I = 0 To Distance Step .2
  526.     Picture1.PSet ((Min((X + (I * (1 / Slope))), MaxNum)), (Max((Y - I), MinNum)))
  527.     'stop loop if end of picture frame is reached
  528.     'max X (far right of frame)
  529.     If Min((X + (I * (1 / Slope))), MaxNum) = MaxNum Then
  530.        New_Y = Y - I
  531.        New_X = MaxNum
  532.        EndOfFrameReached = "TRUE"
  533.     End If
  534.     'min Y (top of frame)
  535.     If Max((Y - I), MinNum) = MinNum Then
  536.        New_X = X + (I * (1 / Slope))
  537.        New_Y = MinNum
  538.        EndOfFrameReached = "TRUE"
  539.     End If
  540.     ' Can't reset value of I until both expressions are
  541.     ' checked, otherwise setting I in first if statement
  542.     ' would cause second if statement to execute also
  543.     If EndOfFrameReached = "TRUE" Then
  544.        I = Distance + 1
  545.        X = New_X
  546.        Y = New_Y
  547.     End If
  548.  Next
  549. ' reset both points to full distance only if edges of frame not reached
  550. If X <> MaxNum And Y <> MinNum Then
  551.    X = Min((X + (I * (1 / Slope))), MaxNum)
  552.    Y = Max((Y - I), MinNum)
  553. End If
  554. Picture1.drawwidth = 4
  555. End Sub
  556. Sub Down ()
  557. Old_X = X
  558. Old_Y = Y
  559. Rem ** Move down **
  560. For I = 0 To Distance Step 1
  561.     Picture1.PSet (X, (Min((Y + I), MaxNum)))
  562.     Next
  563.  X = Old_X
  564.  Y = Min((Y + I), MaxNum)
  565. End Sub
  566. Sub Down_50_Click ()
  567. WriteToProgramBox ("D")
  568. End Sub
  569. Sub Draw_A_Star_Click ()
  570.     DrawStar
  571.     WriteToProgramBox ("S")
  572. End Sub
  573. Sub DrawStar ()
  574.     Slope = Val(SlopeBox.Text)
  575.     ' ** lower left to upper middle (+x,-y) 120,180 to 140,120  **
  576.     ' ** 3X slope - 1.5 / .5 **
  577.     For I = 0 To Distance Step .2
  578.     Picture1.PSet (X + (I * .5), Y - (1.5 * I))
  579.     Next
  580.     ' ** upper middle to lower right (+x,+y) 140,120 to 160,180  **
  581.     For I = 0 To Distance Step .2
  582.     Picture1.PSet ((X + (Distance * .5)) + (I * .5), (Y - (Distance * 1.5)) + (1.5 * I))
  583.     Next
  584.     ' ** lower right to upper left(-x,-y) 160,180 to 120,140  **
  585.     For I = 0 To Distance Step .2
  586.     Picture1.PSet ((X + Distance) - I, Y - I)
  587.     Next
  588.     ' ** straight across left to right(+x,=y) 120,140 to 160,140  **
  589.     For I = 0 To Distance Step .2
  590.     Picture1.PSet (X + I, (Y - Distance))
  591.     Next
  592.     ' ** upper left to lower right(-x,+y) 160,140 to 120,180  **
  593.     For I = 0 To Distance Step .2
  594.     Picture1.PSet ((X + Distance) - I, (Y - Distance) + I)
  595.     Next
  596. End Sub
  597. Sub Form_Load ()
  598. Picture1.Scale (100, 100)-(200, 200)
  599. Dim I As Integer
  600. Distance = 50
  601. LineColor$ = "Blue"
  602. BLUE.Value = True
  603. Form1.Picture1.ForeColor = RGB(0, 0, 255)
  604. Picture1.drawwidth = 4
  605. Old_X = DefaultX
  606. Old_Y = DefaultY
  607. Option5.Value = True
  608. Slope = 2
  609. SlopeBox.Text = "2"
  610. X = DefaultX
  611. Y = DefaultY
  612. ScribbleOn = False
  613. DrawNow = False
  614. Form1.WindowState = MAXIMIZED
  615. Color = "Blue"
  616. TextBoxLine = 0
  617. NL$ = Chr$(13) + Chr$(10)  ' Defines new line character
  618. End Sub
  619. Sub Form_Unload (Cancel As Integer)
  620. Unload Form1
  621. End Sub
  622. Sub Forward ()
  623. Old_X = X
  624. Old_Y = Y
  625. Rem ** Move to right **
  626. For I = 0 To Distance Step .5
  627.     Picture1.PSet ((Min((X + I), MaxNum)), Y)
  628.     Next
  629. X = Min((X + I), MaxNum)
  630. Y = Old_Y
  631. End Sub
  632. Sub Forward_50_Click ()
  633. Forward
  634. WriteToProgramBox ("F")
  635. End Sub
  636. Function GetLine$ (LineNumber As Long)
  637.   '* This function returns a line of text specified by LineNumber
  638.   '* from the edit control. The first line starts at zero.
  639.    Const MAX_CHAR_PER_LINE = 80
  640.    Const EM_GETLINE = &H400 + 20
  641.    ProgramBox.SetFocus
  642.    Buffer$ = Space$(MAX_CHAR_PER_LINE)
  643.    Pos% = SendMessage(GetFocus(), EM_GETLINE, LineNumber, Buffer$)
  644.    GetLine$ = Buffer$
  645. End Function
  646. Function GetLineCount ()
  647.    Const EM_GETLINECOUNT = &H400 + 10
  648.    ProgramBox.SetFocus
  649.    Pos% = SendMessage(GetFocus(), EM_GETLINECOUNT, 0&, 0&)
  650.    GetLineCount = Pos%
  651. End Function
  652. Function GetSel& ()
  653.   '* This function returns the starting/ending position of the
  654.   '* current selected text.  This is the current location of the
  655.   '* cursor if start is equal to ending.
  656.   '* LOWORD-start position of selected text
  657.   '* HIWORD-first no selected text
  658.    Const EM_GETSEL = &H400 + 0
  659.    ProgramBox.SetFocus
  660.    location& = SendMessage(GetFocus(), EM_GETSEL, 0&, 0&)
  661.    ending% = location& \ 2 ^ 16
  662.    starting% = location& Xor high%
  663. '   aGetSel.Caption = "Caret Location = " + Str$(starting%)
  664.    GetSel = location&
  665. End Function
  666. Sub Green_Click ()
  667. Form1.Picture1.ForeColor = RGB(0, 255, 0)
  668. Color$ = "Green"
  669. End Sub
  670. Sub HelpAbout_Click ()
  671.     HelpTopic$ = "Introduction"
  672.     Form2.Show
  673. End Sub
  674. Sub HelpCommands_Click ()
  675.     HelpTopic$ = "Command"
  676.     Form2.Show
  677. End Sub
  678. Sub HelpQuickTour_Click ()
  679.     HelpTopic$ = "Quick Tour"
  680.     Form2.Show
  681. End Sub
  682. Sub HelpRegistration_Click ()
  683. HelpTopic$ = "Registration"
  684. Form2.Show
  685. End Sub
  686. Function LineFromChar& (CharPos&)
  687.    '* This function will return the line number of the line that
  688.    '* contains the character whose location(index) specified in the
  689.    '* third argument of SendMessage.  If the third argument is -1,
  690.    '* then the number of the line that contains the first character
  691.    '* of the selected text is returned.  Line numbers start at zero.
  692.    Const EM_LINEFROMCHAR = &H400 + 25
  693.    ProgramBox.SetFocus
  694.    Pos% = SendMessage(GetFocus(), EM_LINEFROMCHAR, CharPos&, 0&)
  695. '   aLineFromChar.Caption = "Current Line = " + Str$(Pos%)
  696.    LineFromChar = Pos%
  697. End Function
  698. Function Max (FirstArg, SecondArg)
  699.  If FirstArg > SecondArg Then
  700.  Max = FirstArg
  701.  Else
  702.  Max = SecondArg
  703.  End If
  704. End Function
  705. Function Min (FirstArg, SecondArg)
  706.  If FirstArg < SecondArg Then
  707.  Min = FirstArg
  708.  Else
  709.  Min = SecondArg
  710.  End If
  711. End Function
  712. Sub OpenCloseRoutine (Mode%)
  713. 'Open Statement Example
  714.     Dim InputName$
  715.     InputName$ = InputBox$("Enter File Name:", "File Name", NametoUse)
  716.     If InputName$ = " " Then Exit Sub
  717.     NametoUse$ = InputName$
  718.     FileNum% = FreeFile        ' Determine next file number.
  719.     Screen.MousePointer = 11   ' change to hourglass
  720. Select Case Mode
  721.     Case WRITEFILE
  722.     On Error GoTo WriteError
  723.     Open NametoUse$ For Output As FileNum%
  724.     Print #FileNum%, ProgramBox.Text ' Write string to file.
  725.     Close                            ' Close all files.
  726.     MsgBox " File was successful saved - " + NametoUse$, 0
  727.     Case READFILE
  728.     On Error GoTo ReadError
  729.     Open NametoUse For Input As FileNum%
  730.     ProgramBox.Text = Input$(LOF(1), #FileNum%)
  731.     Close
  732.     Case Else
  733.     Exit Sub
  734. End Select
  735. Screen.MousePointer = 0
  736. Exit Sub
  737. WriteError:
  738.     On Error GoTo 0
  739.     MsgBox " Error Writing File " + NametoUse$, 48, "Save File"
  740.     Screen.MousePointer = 0
  741.     Exit Sub
  742. ReadError:
  743.     On Error GoTo 0
  744.     MsgBox " Error Reading File " + NametoUse$, 48, "File Open"
  745.     Screen.MousePointer = 0
  746.     Exit Sub
  747. End Sub
  748. Sub OpenCmdFile_Click ()
  749. OpenCloseRoutine (READFILE)
  750. End Sub
  751. Sub Option1_Click ()
  752. Distance = 10
  753. End Sub
  754. Sub Option2_Click ()
  755. Distance = 20
  756. End Sub
  757. Sub Option3_Click ()
  758. Distance = 30
  759. End Sub
  760. Sub Option4_Click ()
  761. Distance = 40
  762. End Sub
  763. Sub Option5_Click ()
  764. Distance = 50
  765. End Sub
  766. Sub ParseCommandLine (CommandLine As String)
  767. a = 0  ' current position
  768. j = 1  ' start of next word
  769. k = 1  ' position of last comma
  770. n = 0  ' current word in array
  771. ' Mid$ syntax (string, from pos, for length)
  772. Do While Len(CommandLine$) > a
  773.     a = a + 1
  774.     ' only parse if current position is a comma and last
  775.     ' position was not a space
  776.     If Mid$(CommandLine$, a, 1) = "," Then
  777.     CommandWord$(n) = Mid$(CommandLine$, j, (a - k))
  778.     CommandWord$(n) = LTrim$(RTrim$(UCase$(CommandWord$(n))))
  779.     j = a + 1
  780.     m = True
  781.     n = n + 1
  782.     End If
  783. ' write last command word when end of string is reached
  784.     If Len(CommandLine$) - 1 = a Then
  785.     CommandWord$(n) = Mid$(CommandLine$, j, (a - k))
  786.     CommandWord$(n) = LTrim$(RTrim$(UCase$(CommandWord$(n))))
  787.     End If
  788.     ' k = position of last comma
  789.     If Mid$(CommandLine$, a, 1) = "," Then k = a
  790. End Sub
  791. Sub Picture1_MouseDown (Button As Integer, Shift As Integer, MouseX As Single, MouseY As Single)
  792. If ScribbleOn Then DrawNow = True
  793. Picture1.PSet (MouseX, MouseY)
  794. X = MouseX
  795. Y = MouseY
  796. If ScribbleOn Then GoTo Finish
  797. If TextBoxLine = 0 Then
  798. ProgramBox.Text = "XY" + "," + Str$(MouseX \ 1) + "," + Str$(MouseY \ 1) + " "
  799. ProgramBox.Text = ProgramBox.Text + NL$ + "XY" + "," + Str$(MouseX \ 1) + "," + Str$(MouseY \ 1) + " "
  800. End If
  801. TextBoxLine = TextBoxLine + 1
  802. Finish:
  803. End Sub
  804. Sub Picture1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  805. 'Ideas - Change Mouse pointer to a paintbrush when scribbleon
  806. '         and positioned within picture box
  807. '        Limit drawing to within picture box - see ClipCursor
  808. '         API call in "Visual Basics #17"
  809. If X > 200 Then X = 199
  810. If X < 100 Then X = 101
  811. If Y > 200 Then Y = 199
  812. If Y < 100 Then Y = 101
  813. If DrawNow Then Picture1.Line -(X, Y)
  814. 'X = MouseX
  815. 'Y = MouseY
  816. End Sub
  817. Sub Picture1_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  818. DrawNow = False
  819. End Sub
  820. Sub Quit_Click ()
  821.     Unload Form1
  822. End Sub
  823. Sub Red_Click ()
  824. Form1.Picture1.ForeColor = RGB(255, 0, 0)
  825. Color$ = "Red"
  826. End Sub
  827. Sub Run_Program_Click ()
  828. ' The following code performs the following functions:
  829. '     1 - determines the number of lines in the program box
  830. '     2 - Loops through the code and enters a Case
  831. '         statement which sets the proper parameters
  832. '         (color and distance) and executes the proper
  833. '         Control
  834. 'This would provide input into the loop which would process
  835. ' "commands" in the text box. It returns the number of lines
  836. ' in the text2 box.
  837. LC% = GetLineCount() - 1
  838.             
  839. ' GetSel determines the starting and ending
  840. '  position of the selected text
  841. 'CharPos& = GetSel()
  842. 'LineFromChar uses the character postion returned by GetSel
  843. ' to return the line number in the text2 box
  844. 'LineNumber& = LineFromChar(CharPos&)
  845. For LineNumber& = 0 To LC%
  846.     ' GetLine returns the text on the line number specified by
  847.     ' the LineNumber variable.
  848.     CommandLine$ = GetLine(LineNumber&)
  849.     RunCommands (CommandLine$)
  850. End Sub
  851. Sub RunCommands (CommandLine As String)
  852. 'Parses Commands, right and left trims and converts to upper case
  853.     ParseCommandLine (CommandLine$)
  854.     If CommandWord$(2) = "BLUE" Then Blue_Click
  855.     If CommandWord$(2) = "BLACK" Then Black_Click
  856.     If CommandWord$(2) = "RED" Then Red_Click
  857.     If CommandWord$(2) = "GREEN" Then Green_Click
  858.     If CommandWord$(2) = "WHITE" Then White_Click
  859.     If UCase$(CommandWord$(0)) <> "XY" Then
  860.     Dis = Val(CommandWord$(1))
  861.     If Dis > 99 Then
  862.         MsgBox "Distance cannot be greater than 99. Please re-enter"
  863.         GoTo EndProc
  864.     End If
  865.     End If
  866.     If UCase$(CommandWord$(0)) <> "XY" Then
  867.     Distance = Dis
  868.     End If
  869.     If UCase$(CommandWord$(0)) = "F" Then Forward
  870.     If UCase$(CommandWord$(0)) = "B" Then Backward
  871.     If UCase$(CommandWord$(0)) = "U" Then Up
  872.     If UCase$(CommandWord$(0)) = "D" Then Down
  873.     If UCase$(CommandWord$(0)) = "S" Then DrawStar
  874.     If UCase$(CommandWord$(0)) = "DDR" Then DiagDownRight
  875.     If UCase$(CommandWord$(0)) = "DDL" Then DiagDownLeft
  876.     If UCase$(CommandWord$(0)) = "DUR" Then DiagUpRight
  877.     If UCase$(CommandWord$(0)) = "DUL" Then DiagUpLeft
  878.     If UCase$(CommandWord$(0)) = "XY" Then
  879.        X = Val(CommandWord$(1))
  880.        Y = Val(CommandWord$(2))
  881.        Picture1.PSet (X, Y)
  882.     End If
  883. EndProc:
  884. End Sub
  885. Sub SaveCmdFile_Click ()
  886. OpenCloseRoutine (WRITEFILE)
  887. End Sub
  888. Sub Scribble_Click ()
  889. If ScribbleOn Then
  890.    ScribbleOn = False
  891.    DrawNow = False
  892.    Scribble.Caption = "Scribble Off"
  893. ElseIf ScribbleOn = False Then
  894.    ScribbleOn = True
  895.    Scribble.Caption = "Scribble On"
  896. End If
  897. End Sub
  898. Function SelColor ()
  899. Select Case LineColor$
  900.    Case "Blue"
  901.       SelColor = RGB(0, 0, 255)
  902.    Case "Green"
  903.       SelColor = RGB(0, 255, 0)
  904.    Case "Red"
  905.       SelColor = RGB(255, 0, 0)
  906.    Case "Black"
  907.       SelColor = RGB(0, 0, 0)
  908.    Case "White"
  909.       SelColor = RGB(255, 255, 255)
  910. End Select
  911. End Function
  912. Sub SlopeBox_Change ()
  913.     If Val(SlopeBox.Text) > 99 Then
  914.        MsgBox "Slope cannot be greater than 99. Please re-enter"
  915.        SlopeBox.Text = "2"
  916.     End If
  917. End Sub
  918. Sub TestBox_KeyPress (KeyAscii As Integer)
  919. ' Execute Commands in test box when enter is pressed
  920. ' A space must be added to end of command line to prevent
  921. ' parsing problems
  922. If KeyAscii = 13 Then
  923.     CommandLine$ = TestBox.Text + " "
  924.     RunCommands (CommandLine$)
  925. ' Save text box commands to program box
  926.     If TextBoxLine = 0 Then
  927.     ProgramBox.Text = CommandLine$
  928.     Else
  929.     ProgramBox.Text = ProgramBox.Text + NL$ + CommandLine$
  930.     End If
  931.     TextBoxLine = TextBoxLine + 1
  932. End If
  933. End Sub
  934. Sub Up ()
  935. Old_X = X
  936. Old_Y = Y
  937. '** Move Up**
  938. For I = 0 To Distance Step 1
  939.     Picture1.PSet (X, (Max((Y - I), MinNum)))
  940.     Next
  941.  X = Old_X
  942.  Y = Max((Y - I), MinNum)
  943. End Sub
  944. Sub Up_50_Click ()
  945. WriteToProgramBox ("U")
  946. End Sub
  947. Sub White_Click ()
  948. Form1.Picture1.ForeColor = RGB(255, 255, 255)
  949. Color$ = "White"
  950. End Sub
  951. Sub WriteToProgramBox (Action As String)
  952. If TextBoxLine = 0 Then
  953. ProgramBox.Text = Action$ + "," + Str$(Distance) + "," + Color$
  954. ProgramBox.Text = ProgramBox.Text + NL$ + Action$ + "," + Str$(Distance) + "," + Color$
  955. End If
  956. TextBoxLine = TextBoxLine + 1
  957. End Sub
  958.