VERSION 2.00
Begin Form Form1 
   AutoRedraw      =   -1  'True
   BackColor       =   &H00C0C0C0&
   Caption         =   "Donna Teaches Typing"
   ClientHeight    =   4485
   ClientLeft      =   1275
   ClientTop       =   1350
   ClientWidth     =   7350
   Height          =   4890
   Icon            =   DTT1.FRX:0000
   Left            =   1215
   LinkTopic       =   "Form1"
   ScaleHeight     =   4485
   ScaleWidth      =   7350
   Top             =   1005
   Width           =   7470
   Begin Timer Timer1 
      Enabled         =   0   'False
      Interval        =   100
      Left            =   7200
      Top             =   4320
   End
   Begin PictureBox Container 
      BackColor       =   &H00FFFFFF&
      BorderStyle     =   0  'None
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   1695
      Left            =   120
      ScaleHeight     =   1695
      ScaleWidth      =   7095
      TabIndex        =   10
      Top             =   720
      Width           =   7095
      Begin PictureBox pctFrom 
         AutoRedraw      =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         FontBold        =   0   'False
         FontItalic      =   0   'False
         FontName        =   "MS Sans Serif"
         FontSize        =   8.25
         FontStrikethru  =   0   'False
         FontUnderline   =   0   'False
         Height          =   1695
         Left            =   0
         ScaleHeight     =   1695
         ScaleWidth      =   6855
         TabIndex        =   11
         Top             =   0
         Width           =   6855
         Begin Shape FollowMe 
            BorderColor     =   &H00FFFFFF&
            BorderStyle     =   0  'Transparent
            DrawMode        =   7  'Xor Pen
            FillColor       =   &H00FFFFFF&
            FillStyle       =   0  'Solid
            Height          =   255
            Left            =   0
            Top             =   0
            Visible         =   0   'False
            Width           =   615
         End
      End
      Begin VScrollBar vsScroll 
         Height          =   1695
         LargeChange     =   10
         Left            =   6840
         Max             =   0
         TabIndex        =   12
         Top             =   0
         Width           =   255
      End
   End
   Begin CommandButton Command3 
      Caption         =   "Exit"
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   255
      Left            =   2070
      TabIndex        =   9
      Top             =   240
      Width           =   975
   End
   Begin CommandButton Command2 
      Caption         =   "Clear"
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   255
      Left            =   1095
      TabIndex        =   8
      Top             =   240
      Width           =   975
   End
   Begin CommandButton Command1 
      Caption         =   "Print"
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   255
      Left            =   120
      TabIndex        =   7
      Top             =   240
      Width           =   975
   End
   Begin TextBox Text1 
      BackColor       =   &H00FFFFFF&
      BorderStyle     =   0  'None
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   1695
      Left            =   120
      MultiLine       =   -1  'True
      TabIndex        =   0
      Top             =   2640
      Width           =   7095
   End
   Begin TextBox txtTime 
      BorderStyle     =   0  'None
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   195
      Left            =   4080
      TabIndex        =   15
      Text            =   "1:00"
      Top             =   15
      Visible         =   0   'False
      Width           =   855
   End
   Begin Label WPMCount 
      BackStyle       =   0  'Transparent
      Caption         =   "0"
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   255
      Left            =   5760
      TabIndex        =   14
      Top             =   0
      Width           =   1455
   End
   Begin Label lblUseless 
      BackStyle       =   0  'Transparent
      Caption         =   "WPM:"
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   255
      Index           =   3
      Left            =   5160
      TabIndex        =   13
      Top             =   0
      Width           =   495
   End
   Begin Line Line3 
      X1              =   -120
      X2              =   8040
      Y1              =   2520
      Y2              =   2520
   End
   Begin Label lblTElapsed 
      BackStyle       =   0  'Transparent
      Caption         =   "0:00:00"
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   255
      Left            =   4080
      TabIndex        =   6
      Top             =   240
      Width           =   1815
   End
   Begin Label lblUseless 
      BackStyle       =   0  'Transparent
      Caption         =   "Elapsed:"
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   255
      Index           =   2
      Left            =   3360
      TabIndex        =   5
      Top             =   240
      Width           =   615
   End
   Begin Line Line2 
      X1              =   3240
      X2              =   3240
      Y1              =   0
      Y2              =   600
   End
   Begin Label lblTime 
      BackStyle       =   0  'Transparent
      Caption         =   "0:00:00"
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   255
      Left            =   4080
      TabIndex        =   4
      Top             =   0
      Width           =   975
   End
   Begin Label lblUseless 
      BackStyle       =   0  'Transparent
      Caption         =   "Time:"
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   255
      Index           =   1
      Left            =   3360
      TabIndex        =   3
      Top             =   0
      Width           =   615
   End
   Begin Label lblName 
      BackStyle       =   0  'Transparent
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   255
      Left            =   720
      TabIndex        =   2
      Top             =   0
      Width           =   2415
   End
   Begin Label lblUseless 
      BackStyle       =   0  'Transparent
      Caption         =   "Name:"
      FontBold        =   0   'False
      FontItalic      =   0   'False
      FontName        =   "MS Sans Serif"
      FontSize        =   8.25
      FontStrikethru  =   0   'False
      FontUnderline   =   0   'False
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   1
      Top             =   0
      Width           =   615
   End
   Begin Line Line1 
      X1              =   -600
      X2              =   7800
      Y1              =   600
      Y2              =   600
   End
End
Dim TimeBegin, EndTime, Delta, CurWord As Single
Dim PassKey As String * 256
Dim LessonData(1 To 2) As Integer

Function CntNum (Text As String, substring$)
  For q = 1 To Len(Text$)
    q = InStr(q, Text$, substring$)
    If q = 0 Then Exit For
    Cnt = Cnt + 1
  Next q
  CntNum = Cnt
End Function

Function CntWords (Text$)
  For q = 1 To Len(Text$)
    If Mid$(Text$, q, 1) = " " And lastchr$ <> " " Then Cnt = Cnt + 1
    lastchr$ = Mid$(Text$, q, 1)
  Next q
  CntWords = Cnt + Switch(Right$(Text$, 1) = " ", 0, 1 = 1, 1)
End Function

Sub Command1_Click ()
Text1_KeyPress 32
On Error GoTo PrinterError
Printer.FontName = "Times New Roman"
Printer.FontBold = False
Printer.Print "Name: " + lblName.Caption
Printer.Print "Date: " + Date$
Printer.Print "Time: " + Time$
Printer.Print
Printer.Print "Time elapsed: " + lblTElapsed.Caption
Printer.Print "Words: " + Trim$(Str$(CntWords(Trim$(Text1.Text))))
Printer.Print "Lines: " + Trim$(Str$(CntNum(Trim$(Text1.Text), Chr$(13))))
Printer.Print "Words per minute: " + WPMCount.Caption
Printer.Print
For q = 1 To Len(Text1.Text)
  C$ = Mid$(Text1.Text, q, 1)
  If Printer.CurrentX + Printer.TextWidth(C$) > Printer.Width Then Printer.Print
  Printer.Print C$;
Next q
Printer.EndDoc
Exit Sub
PrinterError:
  MsgBox "An error occured writing to the printer.  Please check the computer's printer settings and try again.", 48, "Printer Error"
End Sub

Sub Command2_Click ()
  TimeBegin = 0
  Timer1.Enabled = False
  lblTElapsed = "0:00:00"
  Text1.Text = ""
  Text1.Enabled = True
  If LessonData(1) = 2 Then SetFrom Left$(pctFrom.Tag, InStr(pctFrom.Tag, " ") - 1)
  If LessonData(1) = 3 Then SetFrom Left$(pctFrom.Tag, 1)
  If LessonData(1) = 1 Then MakeFit
End Sub

Sub Command3_Click ()
  End
End Sub

Sub FixFonts (From As Control, Fnt1$, Fnt2$, Fnt3$)
  From.FontName = Fnt1$
  If UCase$(From.FontName) <> UCase$(Fnt1$) Then From.FontName = Fnt2$
  If UCase$(From.FontName) <> UCase$(Fnt2$) Then From.FontName = Fnt3$
  If UCase$(From.FontName) <> UCase$(Fnt3$) Then From.FontName = "Fixedsys"
End Sub

Sub Form_Activate ()
  Me.Caption = "Donna Teaches Typing - " + Me.Tag
End Sub

Sub Form_Load ()
  FixFonts pctFrom, "Courier New", "Times New Roman", "Arial"
  Text1.FontName = pctFrom.FontName
  Container.FontName = pctFrom.FontName
  Make3DControl Text1, 0
  Make3DControl Container, 0
  Make3DLine Line1
  Make3DLine Line2
  Make3DLine Line3
  ReDim PassKeyTmp(0) As String
  LoadRecord 1, PassKeyTmp(), "DTT"
  PassKey = PassKeyTmp(0)
  LoadLesson
  If Trim$(pctFrom.Tag) = "" Then LessonData(1) = 4
  If LessonData(1) = 1 Then MakeFit
  If LessonData(1) > 1 Then
    vsScroll.Visible = False
    Delta = Container.Height
    If LessonData(1) = 4 Then
      Line3.Visible = False
      Container.Visible = False
    Else
      Container.Height = Container.TextHeight("A")
      pctFrom.Height = Container.Height
      Delta = Delta - Container.Height
      Line3.Y1 = Line3.Y1 - Delta
      Line3.Y2 = Line3.Y2 - Delta
    End If
    Text1.Top = Text1.Top - Delta
  End If
End Sub

Sub Form_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  If WindowState = 2 And Button = 2 And Shift = 1 And lblName = "ROY KEENE" And Splash.Visible = False Then
    Splash.Show 1
  End If
End Sub

Sub Form_Resize ()
  On Error Resume Next
  Me.Cls
  Line1.X2 = Form1.Width + 300
  Line3.X2 = Form1.Width + 300
  Make3DLine Line1
  Make3DLine Line2
  If Line3.Visible Then Make3DLine Line3
  Text1.Move Text1.Left, Text1.Top, Form1.Width - (Screen.TwipsPerPixelX * 24), Form1.Height - (Screen.TwipsPerPixelY * 35) - Text1.Top
  Container.Width = Form1.Width - (Screen.TwipsPerPixelX * 24)
  vsScroll.Left = Container.Width - vsScroll.Width
  pctFrom.Width = Container.Width - vsScroll.Width
  Make3DControl Text1, 0
  If Container.Visible Then Make3DControl Container, 0
  If LessonData(1) < 2 Then SetFrom pctFrom.Tag
1001  If LessonData(1) = 1 Then GetWordXY (Len(Text1.Text) Mod Len(pctFrom.Tag)) + 1, Lft, Tp, Wdth: FollowMe.Move Lft, Tp, Wdth - pctFrom.TextWidth(" ")
End Sub

Sub Form_Unload (Cancel As Integer)
  End
End Sub

Sub GetNextXY (Pos, Lft, Tp, Wdth)
  SONW = InStr(Pos + 1, pctFrom.Tag, " ")
  SONSW = InStr(SONW + 1, pctFrom.Tag, " ")
  If SONSW = 0 Then SONSW = Len(pctFrom.Tag)
  NextWord$ = Mid$(pctFrom.Tag, SONW, SONSW - SONW)
  NWdth = pctFrom.TextWidth(NextWord$)
  If (Lft + NWdth + Wdth) > pctFrom.Width Then Lft = 0: Tp = Tp + pctFrom.TextHeight("A") Else Lft = Lft + Wdth
  Wdth = NWdth
End Sub

Sub GetWordXY (Posi, Lft, Tp, Wdth)
  CX = 0: CY = 0
  Endq = InStr(Posi, pctFrom.Tag, " ")
  Endq = Switch(Endq = 0, Len(pctFrom.Tag), -1, Endq)
  For q = 1 To Endq
    nextq = InStr(q, pctFrom.Tag, " ")
    If nextq = 0 Then nextq = Len(pctFrom.Tag)
    Wrd$ = Mid$(pctFrom.Tag, q, nextq - q + 1)
    WW = pctFrom.TextWidth(Wrd$)
    If CX + WW > pctFrom.Width Then CY = CY + pctFrom.TextHeight("A"): CX = WW Else CX = CX + WW
    q = nextq
  Next q
  Tp = CY
  Lft = CX - WW
  Wdth = WW
End Sub

Sub lblTime_Click ()
  If LessonData(2) = 0 Then Exit Sub
  Make3DControl txtTime, 0
  txtTime.Visible = True
  DoEvents
  txtTime.SetFocus
End Sub

Sub LoadLesson ()
  RecordNumber = Val(Startup.Tag)
  ReDim CurrentLesson(1 To 5) As String
  LoadRecord RecordNumber, CurrentLesson(), "DTT"
  txtTime.Text = CurrentLesson(3)
  Encrypted = Val(Mid$(CurrentLesson(4), 1, 1))
  LessonData(1) = Val(CurrentLesson(5))
  LessonData(2) = Val(Mid$(CurrentLesson(4), 2, 1))
  pctFrom.Tag = Switch(Encrypted = 0, CurrentLesson(2), 1 = 1, Decrypt(CurrentLesson(2), PassKey, 5))
  If LessonData(1) < 2 Then SetFrom pctFrom.Tag
  If LessonData(1) > 1 And LessonData(1) < 4 Then pctFrom.Tag = pctFrom.Tag + "  "
  If LessonData(1) = 2 Then SetFrom Left$(pctFrom.Tag, InStr(pctFrom.Tag, " ") - 1)
  If LessonData(1) = 3 Then SetFrom Left$(pctFrom.Tag, 1)
  txtTime_KeyPress 13
End Sub

Sub MakeFit ()
  'GetNextXY 0, 0, 0, Wdth
  FollowMe.Move 0, 0, pctFrom.TextWidth(Left$(pctFrom.Tag, InStr(pctFrom.Tag, " ") - 1))
  FollowMe.Visible = True
End Sub

Sub PrintIt (Dest As Form)
End Sub

Sub SetFrom (ByVal Text As String)
  pctFrom.Cls
  If LessonData(1) = 3 Then pctFrom.Print Text: Exit Sub
  For q = 1 To Len(Text)
    newq = InStr(q, Text, " ")
    If newq = 0 Then newq = Len(Text)
    Word$ = Mid$(Text, q, newq - q + 1)
    If pctFrom.CurrentX + pctFrom.TextWidth(Word$) > pctFrom.Width Then
      pctFrom.Print
      If (pctFrom.CurrentY + pctFrom.TextHeight("A")) > pctFrom.Height Then pctFrom.Height = pctFrom.Height + pctFrom.TextHeight("A")
    End If
    pctFrom.Print Word$;
    q = newq
  Next q
  If pctFrom.Top <> 0 Then pctFrom.Top = 0
1008  Lines = CInt((pctFrom.Height - Container.Height) / pctFrom.TextHeight("A"))
  vsScroll.Max = Lines
End Sub

Sub Text1_Click ()
  If Text1.SelStart <> Len(Text1.Text) Then Text1.SelLength = 0: Text1.SelStart = Len(Text1.Text)
End Sub

Sub Text1_DblClick ()
  Text1_Click
End Sub

Sub Text1_KeyDown (KeyCode As Integer, Shift As Integer)
  If KeyCode = 38 Then NSV = vsScroll.Value - 1: vsScroll.Value = Switch(NSV < 0, 0, -1, NSV)
  If KeyCode = 40 Then NSV = vsScroll.Value + 1: vsScroll.Value = Switch(NSV > vsScroll.Max, vsScroll.Max, -1, NSV)
  If KeyCode > 32 And KeyCode < 41 Then KeyCode = 0: Exit Sub
End Sub

Sub Text1_KeyPress (KeyAscii As Integer)
  On Error GoTo ErrorHandler
  
  If TimeBegin = 0 And Text1.Enabled Then TimeBegin = Timer: Timer1.Enabled = True
1002 If LessonData(1) <> 4 Then CurPos = ((Text1.SelStart) Mod (Len(pctFrom.Tag))) + 1
  If LessonData(1) > 0 And LessonData(1) < 4 Then
    If Mid$(pctFrom.Tag, CurPos, 1) <> Chr$(KeyAscii) Then KeyAscii = 0: Exit Sub
  End If
  Select Case LessonData(1)
    Case 1
      If CurPos = Len(pctFrom.Tag) Then MakeFit
      If KeyAscii = 32 Then
        CurWord = CurWord + 1
        Lft = FollowMe.Left: Tp = FollowMe.Top: Wdth = FollowMe.Width
        GetNextXY CurPos - 1, Lft, Tp, Wdth
        FollowMe.Visible = True
        If Tp + pctFrom.TextHeight("A") > Container.Height - pctFrom.Top Then vsScroll.Value = vsScroll.Value + 1
        FollowMe.Move Lft + pctFrom.TextWidth(" "), Tp, (Wdth - pctFrom.TextWidth(" "))
      End If
      If KeyAscii = 13 Then
        FollowMe.Move 0, pctFrom.TextHeight("A") + FollowMe.Top, pctFrom.TextWidth(Mid$(pctFrom.Tag, CurPos, InStr(CurPos, pctFrom.Tag, " ") - CurPos))
      End If
    Case 2
      If KeyAscii = 32 Then
        CurPos = Switch(CurPos = Len(pctFrom.Tag), 0, 1 = 1, CurPos)
        SetFrom Mid$(pctFrom.Tag, CurPos + 1, InStr(CurPos + 1, pctFrom.Tag, " ") - CurPos)
      End If
    Case 3
      If CurPos = Len(pctFrom.Tag) Then SetFrom Left$(pctFrom.Tag, 1) Else SetFrom Mid$(pctFrom.Tag, CurPos + 1, 1)
  End Select

1004  If (Len(Text1.Text) + 1) Mod 5 = 0 Then
1005    WordCount = (Len(Text1.Text) + 1) \ 5
    Tme = Val(lblTElapsed.Tag)
1009    WPM = WordCount / (Tme / 60)
    WPMCount.Caption = Trim$(Str$(WPM))
  End If
  Exit Sub
ErrorHandler:
  MsgBox "An error has occured." & Chr$(13) & Chr$(10) & Error$ & Str$(Erl)
  Resume Next
End Sub

Sub Timer1_Timer ()
  TimerNew = Timer
  Tme = (TimerNew - TimeBegin)
1010  Hours = Int(Tme / 3600): Tme = Tme - (Hours * 3600)
1011  mins = Int(Tme / 60): Tme = Tme - (mins * 60)
  Sec = Int(Tme)
  Fs = Int((Tme - Sec) * 10000)
  lblTElapsed.Caption = Trim$(Str$(Hours)) + ":" + MakeLength$(Trim$(Str$(mins)), 2, "0") + ":" + MakeLength$(Trim$(Str$(Sec)), 2, "0") + "." + Trim$(Str$(Fs))
  lblTElapsed.Tag = Str$(TimerNew - TimeBegin)
  If ClipBoard.GetFormat(1) Then ClipBoard.SetText ""
  If (TimerNew - TimeBegin) >= Val(lblTime.Tag) And Val(lblTime.Tag) <> 0 Then
    Text1.Enabled = False
    Timer1.Enabled = False
    MsgBox "Time has expired.", 64, "Time's up!"
  End If
End Sub

Sub txtTime_Change ()
  If Abs(Len(txtTime.Tag) - Len(txtTime.Text)) <> 1 Then
    'they pasted, check it
    If CntNum(Trim$(txtTime.Text), ":") > 2 Then
      tmp$ = txtTime.Text
      For q = 1 To Len(txtTime.Text)
        q = InStr(q, txtTime.Text, ":")
        If q = 0 Then Exit For
        Cnt = Cnt + 1
        If Cnt > 2 Then Mid$(tmp$, q, 1) = "0"
      Next q
      txtTime.Text = tmp$
    End If
  End If
  txtTime.Tag = txtTime.Text
End Sub

Sub txtTime_KeyPress (KeyAscii As Integer)
  If (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) And KeyAscii > 31 And KeyAscii <> Asc(":") Then KeyAscii = 0: Exit Sub
  If KeyAscii = Asc(":") Then
    If CntNum(Trim$(txtTime.Text), ":") > 1 Then KeyAscii = 0: Exit Sub
  End If
  If KeyAscii = 13 Then
    Command2_Click
    Form_Resize
    txtTime.Visible = False
    KeyAscii = 0
    ReDim TmpArray(-1 To 7) As Integer
    For q = 1 To Len(txtTime.Text)
      Endq = InStr(q, txtTime.Text, ":")
      If Endq = 0 Then s = Val(Mid$(txtTime.Text, q, Len(txtTime.Text) - Endq)): Exit For
      Cnt = Cnt + 1
      TmpArray(Cnt) = Int(Val(Mid$(txtTime.Text, q, Endq - q)))
      q = Endq
    Next q
1006    m = TmpArray(Cnt) + (s \ 60)
1007    h = TmpArray(Cnt - 1) + (m \ 60)
1000    m = m Mod 60: s = s Mod 60
    lblTime.Tag = Str$((h * 3600) + (m * 60) + s)
    lblTime.Caption = Trim$(Str$(h)) + ":" + MakeLength$(Trim$(Str$(m)), 2, "0") + ":" + MakeLength(Trim$(s), 2, "0")
    txtTime.Text = lblTime.Caption
  End If
End Sub

Sub vsScroll_Change ()
  pctFrom.Top = 0 - (vsScroll.Value * Container.TextHeight("A"))
End Sub

