home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / articles / vbpj / source / llist1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-01-29  |  10.8 KB  |  317 lines

  1. VERSION 4.00
  2. Begin VB.Form frmMain 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H80000005&
  5.    Caption         =   "Linked List Example Program"
  6.    ClientHeight    =   4095
  7.    ClientLeft      =   1095
  8.    ClientTop       =   1770
  9.    ClientWidth     =   9780
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   1
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   4785
  21.    Left            =   1035
  22.    LinkTopic       =   "Form1"
  23.    ScaleHeight     =   4095
  24.    ScaleWidth      =   9780
  25.    Top             =   1140
  26.    Width           =   9900
  27.    Begin VB.Frame Frame2 
  28.       Appearance      =   0  'Flat
  29.       BackColor       =   &H80000005&
  30.       Caption         =   "Display"
  31.       ForeColor       =   &H80000008&
  32.       Height          =   1215
  33.       Left            =   2880
  34.       TabIndex        =   5
  35.       Top             =   2760
  36.       Width           =   3555
  37.       Begin VB.TextBox txtPerson 
  38.          Appearance      =   0  'Flat
  39.          Height          =   315
  40.          Left            =   1980
  41.          TabIndex        =   8
  42.          Text            =   "1"
  43.          Top             =   780
  44.          Width           =   675
  45.       End
  46.       Begin VB.OptionButton optDisplay 
  47.          Appearance      =   0  'Flat
  48.          BackColor       =   &H80000005&
  49.          Caption         =   "For Person"
  50.          ForeColor       =   &H80000008&
  51.          Height          =   315
  52.          Index           =   1
  53.          Left            =   120
  54.          TabIndex        =   7
  55.          Top             =   720
  56.          Width           =   1275
  57.       End
  58.       Begin VB.OptionButton optDisplay 
  59.          Appearance      =   0  'Flat
  60.          BackColor       =   &H80000005&
  61.          Caption         =   "By Start Time"
  62.          ForeColor       =   &H80000008&
  63.          Height          =   315
  64.          Index           =   0
  65.          Left            =   120
  66.          TabIndex        =   6
  67.          Top             =   360
  68.          Value           =   -1  'True
  69.          Width           =   1575
  70.       End
  71.    End
  72.    Begin VB.Frame Frame1 
  73.       Appearance      =   0  'Flat
  74.       BackColor       =   &H80000005&
  75.       Caption         =   "Implementation"
  76.       ForeColor       =   &H80000008&
  77.       Height          =   1215
  78.       Left            =   120
  79.       TabIndex        =   2
  80.       Top             =   2760
  81.       Width           =   2655
  82.       Begin VB.OptionButton optImplementation 
  83.          Appearance      =   0  'Flat
  84.          BackColor       =   &H80000005&
  85.          Caption         =   "Array Based"
  86.          ForeColor       =   &H80000008&
  87.          Height          =   315
  88.          Index           =   1
  89.          Left            =   60
  90.          TabIndex        =   4
  91.          Top             =   720
  92.          Width           =   1995
  93.       End
  94.       Begin VB.OptionButton optImplementation 
  95.          Appearance      =   0  'Flat
  96.          BackColor       =   &H80000005&
  97.          Caption         =   "Linked List Based"
  98.          ForeColor       =   &H80000008&
  99.          Height          =   315
  100.          Index           =   0
  101.          Left            =   60
  102.          TabIndex        =   3
  103.          Top             =   360
  104.          Value           =   -1  'True
  105.          Width           =   1935
  106.       End
  107.    End
  108.    Begin VB.VScrollBar VScroll1 
  109.       Height          =   2655
  110.       Left            =   9240
  111.       Max             =   100
  112.       Min             =   1
  113.       TabIndex        =   1
  114.       Top             =   60
  115.       Value           =   1
  116.       Width           =   315
  117.    End
  118.    Begin VB.PictureBox picDisplay 
  119.       Appearance      =   0  'Flat
  120.       BackColor       =   &H80000005&
  121.       BeginProperty Font 
  122.          name            =   "Courier New"
  123.          charset         =   1
  124.          weight          =   400
  125.          size            =   8.25
  126.          underline       =   0   'False
  127.          italic          =   0   'False
  128.          strikethrough   =   0   'False
  129.       EndProperty
  130.       ForeColor       =   &H80000008&
  131.       Height          =   2655
  132.       Left            =   120
  133.       ScaleHeight     =   2625
  134.       ScaleWidth      =   8985
  135.       TabIndex        =   0
  136.       Top             =   60
  137.       Width           =   9015
  138.    End
  139.    Begin VB.Menu mnuTop1 
  140.       Caption         =   "Test"
  141.       Begin VB.Menu mnuTest 
  142.          Caption         =   "Test Random Insert/Delete"
  143.       End
  144.       Begin VB.Menu mnuTestDisplay 
  145.          Caption         =   "Test Display"
  146.       End
  147.    End
  148. Attribute VB_Name = "frmMain"
  149. Attribute VB_Creatable = False
  150. Attribute VB_Exposed = False
  151. Option Explicit
  152. ' Set up the global variables and arrays
  153. Private Sub Form_Load()
  154.     Dim namecntr%
  155.     ' Here we load the name array.  In this example, we
  156.     ' are using a fixed set of names.  In a real program
  157.     ' you would provide a mechanism to edit the name list.
  158.     Open App.Path & "\" & "llnames.txt" For Input As #1
  159.     For namecntr% = 1 To 20
  160.         Input #1, NameArray$(namecntr%)
  161.     Next namecntr%
  162.     Close #1
  163.     InitializeGlobals
  164. End Sub
  165. Private Sub mnuTest_Click()
  166.     Dim starttime
  167.     Dim counter%, idx%
  168.     Dim se As ScheduleEntry
  169.     Dim seLL As ScheduleEntryLL
  170.     InitializeGlobals
  171.     Screen.MousePointer = 11
  172.     starttime = GetCurrentTime()
  173.     ' First add 500 entries to get things started
  174.     For counter% = 1 To 500
  175.         If optImplementation(0).Value = 0 Then
  176.             ' It's the array implementation
  177.             GenerateRandom se.Start, se.Duration, se.Person
  178.             se.Description = "Description for " & NameArray(se.Person)
  179.             AddEntry se
  180.         Else
  181.             ' It's the linked list implementation
  182.             GenerateRandom seLL.Start, seLL.Duration, seLL.Person
  183.             seLL.Description = "Description for " & NameArray(seLL.Person)
  184.             AddEntryLL seLL
  185.         End If
  186.     Next counter%
  187.     ' Now another 500 miscellaneous insertions and deletions
  188.     For counter% = 1 To 1000
  189.         If optImplementation(0).Value = 0 Then
  190.             ' It's the array implementation
  191.             If Rnd < 0.5 Then
  192.                 GenerateRandom se.Start, se.Duration, se.Person
  193.                 se.Description = "Description for " & NameArray(se.Person)
  194.                 AddEntry se
  195.             Else
  196.                 idx% = Int(Rnd * UBound(ScheduleARY) + 1)
  197.                 If ScheduleARY(idx%).Start <> 0 Then
  198.                     DeleteEntry idx%
  199.                 End If
  200.             End If
  201.         Else
  202.             ' It's the linked list implementation
  203.             If Rnd < 0.5 Then
  204.                 ' It's the linked list implementation
  205.                 GenerateRandom seLL.Start, seLL.Duration, seLL.Person
  206.                 seLL.Description = "Description for " & NameArray(seLL.Person)
  207.                 AddEntryLL seLL
  208.             Else
  209.                 idx% = Int(Rnd * UBound(ScheduleARY) + 1)
  210.                 If ScheduleLL(idx%).Start <> 0 Then
  211.                     DeleteEntryLL idx%
  212.                 End If
  213.             End If
  214.         End If
  215.     Next counter%
  216.     Screen.MousePointer = 0
  217.     MsgBox "Elapsed Time: " & GetCurrentTime() - starttime
  218.     picDisplay.Refresh
  219. End Sub
  220. Private Sub mnuTestDisplay_Click()
  221.     Dim starttime
  222.     Dim counter%, idx%
  223.     Screen.MousePointer = 11
  224.     starttime = GetCurrentTime()
  225.     ' Try displaying 100 times
  226.     For counter% = 1 To 100
  227.         picDisplay.Refresh
  228.     Next counter%
  229.     Screen.MousePointer = 0
  230.     MsgBox "Elapsed Time: " & GetCurrentTime() - starttime
  231.     picDisplay.Refresh
  232. End Sub
  233. Private Sub optDisplay_Click(Index As Integer)
  234.     picDisplay.Refresh
  235. End Sub
  236. '   Display the array contents based on the requests
  237. Private Sub picDisplay_Paint()
  238.     Dim idx%, targetidx%, count%
  239.     Dim personlmt%
  240.     targetidx% = VScroll1.Value
  241.     picDisplay.Cls  ' Clear the display
  242.     If optImplementation(0).Value = 0 Then
  243.         ' It's the ScheduleARY array
  244.         If optDisplay(0).Value <> 0 Then
  245.             VScroll1.Max = UBound(ScheduleARY)  ' Approximation
  246.             ' Display by start time
  247.             idx% = targetidx%
  248.             Do While idx% < UBound(ScheduleARY)
  249.                 If ScheduleARY(idx%).Start = 0 Then Exit Do
  250.                 picDisplay.Print GetEntryDesc(idx%)
  251.                 If picDisplay.CurrentY > picDisplay.ScaleHeight Then Exit Do
  252.                 idx% = idx% + 1
  253.             Loop
  254.         Else
  255.             ' Display by name
  256.             personlmt% = Val(txtPerson.Text)
  257.             VScroll1.Max = GetCount(personlmt%)
  258.             idx% = 1
  259.             count% = 0
  260.             Do While idx% < UBound(ScheduleARY)
  261.                 If ScheduleARY(idx%).Start = 0 Then Exit Do
  262.                 If ScheduleARY(idx%).Person = personlmt% Then
  263.                     count% = count% + 1 ' How many found?
  264.                     If count% >= targetidx% Then
  265.                         picDisplay.Print GetEntryDesc(idx%)
  266.                         If picDisplay.CurrentY > picDisplay.ScaleHeight Then Exit Do
  267.                         End If
  268.                     End If
  269.                 idx% = idx% + 1
  270.             Loop
  271.         End If
  272.     Else
  273.         ' It's the ScheduleLL array (linked list)
  274.         If optDisplay(0).Value <> 0 Then
  275.             VScroll1.Max = UBound(ScheduleLL) ' Approximation
  276.             ' Display by start time
  277.             idx% = FirstTask
  278.             count% = 0
  279.             Do While idx% > 0
  280.                 count% = count% + 1
  281.                 If count% > targetidx% Then
  282.                     picDisplay.Print GetEntryDescLL(idx%)
  283.                     If picDisplay.CurrentY > picDisplay.ScaleHeight Then Exit Do
  284.                 End If
  285.                 idx% = ScheduleLL(idx%).StartLink.Forward
  286.             Loop
  287.         Else
  288.             ' Display by name
  289.             personlmt% = Val(txtPerson.Text)
  290.             VScroll1.Max = GetCountLL(personlmt%)
  291.             idx% = FirstPerson(personlmt%)
  292.             count% = 0 ' Tracks how many to skip
  293.             Do While idx% > 0
  294.                 count% = count% + 1 ' How many found?
  295.                 If count% >= targetidx% Then
  296.                     picDisplay.Print GetEntryDescLL(idx%)
  297.                     If picDisplay.CurrentY > picDisplay.ScaleHeight Then Exit Do
  298.                 End If
  299.                 idx% = ScheduleLL(idx%).PersonLink.Forward
  300.             Loop
  301.         End If
  302.         
  303.         
  304.         ' It's the linked list array
  305.     End If
  306.         
  307. End Sub
  308. Private Sub txtPerson_Change()
  309.     picDisplay.Refresh
  310. End Sub
  311. Private Sub VScroll1_Change()
  312.     picDisplay.Refresh
  313. End Sub
  314. Private Sub VScroll1_Scroll()
  315.     picDisplay.Refresh
  316. End Sub
  317.