home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form frmMain
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "Linked List Example Program"
- ClientHeight = 4095
- ClientLeft = 1095
- ClientTop = 1770
- ClientWidth = 9780
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 1
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 4785
- Left = 1035
- LinkTopic = "Form1"
- ScaleHeight = 4095
- ScaleWidth = 9780
- Top = 1140
- Width = 9900
- Begin VB.Frame Frame2
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "Display"
- ForeColor = &H80000008&
- Height = 1215
- Left = 2880
- TabIndex = 5
- Top = 2760
- Width = 3555
- Begin VB.TextBox txtPerson
- Appearance = 0 'Flat
- Height = 315
- Left = 1980
- TabIndex = 8
- Text = "1"
- Top = 780
- Width = 675
- End
- Begin VB.OptionButton optDisplay
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "For Person"
- ForeColor = &H80000008&
- Height = 315
- Index = 1
- Left = 120
- TabIndex = 7
- Top = 720
- Width = 1275
- End
- Begin VB.OptionButton optDisplay
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "By Start Time"
- ForeColor = &H80000008&
- Height = 315
- Index = 0
- Left = 120
- TabIndex = 6
- Top = 360
- Value = -1 'True
- Width = 1575
- End
- End
- Begin VB.Frame Frame1
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "Implementation"
- ForeColor = &H80000008&
- Height = 1215
- Left = 120
- TabIndex = 2
- Top = 2760
- Width = 2655
- Begin VB.OptionButton optImplementation
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "Array Based"
- ForeColor = &H80000008&
- Height = 315
- Index = 1
- Left = 60
- TabIndex = 4
- Top = 720
- Width = 1995
- End
- Begin VB.OptionButton optImplementation
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "Linked List Based"
- ForeColor = &H80000008&
- Height = 315
- Index = 0
- Left = 60
- TabIndex = 3
- Top = 360
- Value = -1 'True
- Width = 1935
- End
- End
- Begin VB.VScrollBar VScroll1
- Height = 2655
- Left = 9240
- Max = 100
- Min = 1
- TabIndex = 1
- Top = 60
- Value = 1
- Width = 315
- End
- Begin VB.PictureBox picDisplay
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BeginProperty Font
- name = "Courier New"
- charset = 1
- weight = 400
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 2655
- Left = 120
- ScaleHeight = 2625
- ScaleWidth = 8985
- TabIndex = 0
- Top = 60
- Width = 9015
- End
- Begin VB.Menu mnuTop1
- Caption = "Test"
- Begin VB.Menu mnuTest
- Caption = "Test Random Insert/Delete"
- End
- Begin VB.Menu mnuTestDisplay
- Caption = "Test Display"
- End
- End
- Attribute VB_Name = "frmMain"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- ' Set up the global variables and arrays
- Private Sub Form_Load()
- Dim namecntr%
- ' Here we load the name array. In this example, we
- ' are using a fixed set of names. In a real program
- ' you would provide a mechanism to edit the name list.
- Open App.Path & "\" & "llnames.txt" For Input As #1
- For namecntr% = 1 To 20
- Input #1, NameArray$(namecntr%)
- Next namecntr%
- Close #1
- InitializeGlobals
- End Sub
- Private Sub mnuTest_Click()
- Dim starttime
- Dim counter%, idx%
- Dim se As ScheduleEntry
- Dim seLL As ScheduleEntryLL
- InitializeGlobals
- Screen.MousePointer = 11
- starttime = GetCurrentTime()
- ' First add 500 entries to get things started
- For counter% = 1 To 500
- If optImplementation(0).Value = 0 Then
- ' It's the array implementation
- GenerateRandom se.Start, se.Duration, se.Person
- se.Description = "Description for " & NameArray(se.Person)
- AddEntry se
- Else
- ' It's the linked list implementation
- GenerateRandom seLL.Start, seLL.Duration, seLL.Person
- seLL.Description = "Description for " & NameArray(seLL.Person)
- AddEntryLL seLL
- End If
- Next counter%
- ' Now another 500 miscellaneous insertions and deletions
- For counter% = 1 To 1000
- If optImplementation(0).Value = 0 Then
- ' It's the array implementation
- If Rnd < 0.5 Then
- GenerateRandom se.Start, se.Duration, se.Person
- se.Description = "Description for " & NameArray(se.Person)
- AddEntry se
- Else
- idx% = Int(Rnd * UBound(ScheduleARY) + 1)
- If ScheduleARY(idx%).Start <> 0 Then
- DeleteEntry idx%
- End If
- End If
- Else
- ' It's the linked list implementation
- If Rnd < 0.5 Then
- ' It's the linked list implementation
- GenerateRandom seLL.Start, seLL.Duration, seLL.Person
- seLL.Description = "Description for " & NameArray(seLL.Person)
- AddEntryLL seLL
- Else
- idx% = Int(Rnd * UBound(ScheduleARY) + 1)
- If ScheduleLL(idx%).Start <> 0 Then
- DeleteEntryLL idx%
- End If
- End If
- End If
- Next counter%
- Screen.MousePointer = 0
- MsgBox "Elapsed Time: " & GetCurrentTime() - starttime
- picDisplay.Refresh
- End Sub
- Private Sub mnuTestDisplay_Click()
- Dim starttime
- Dim counter%, idx%
- Screen.MousePointer = 11
- starttime = GetCurrentTime()
- ' Try displaying 100 times
- For counter% = 1 To 100
- picDisplay.Refresh
- Next counter%
- Screen.MousePointer = 0
- MsgBox "Elapsed Time: " & GetCurrentTime() - starttime
- picDisplay.Refresh
- End Sub
- Private Sub optDisplay_Click(Index As Integer)
- picDisplay.Refresh
- End Sub
- ' Display the array contents based on the requests
- Private Sub picDisplay_Paint()
- Dim idx%, targetidx%, count%
- Dim personlmt%
- targetidx% = VScroll1.Value
- picDisplay.Cls ' Clear the display
- If optImplementation(0).Value = 0 Then
- ' It's the ScheduleARY array
- If optDisplay(0).Value <> 0 Then
- VScroll1.Max = UBound(ScheduleARY) ' Approximation
- ' Display by start time
- idx% = targetidx%
- Do While idx% < UBound(ScheduleARY)
- If ScheduleARY(idx%).Start = 0 Then Exit Do
- picDisplay.Print GetEntryDesc(idx%)
- If picDisplay.CurrentY > picDisplay.ScaleHeight Then Exit Do
- idx% = idx% + 1
- Loop
- Else
- ' Display by name
- personlmt% = Val(txtPerson.Text)
- VScroll1.Max = GetCount(personlmt%)
- idx% = 1
- count% = 0
- Do While idx% < UBound(ScheduleARY)
- If ScheduleARY(idx%).Start = 0 Then Exit Do
- If ScheduleARY(idx%).Person = personlmt% Then
- count% = count% + 1 ' How many found?
- If count% >= targetidx% Then
- picDisplay.Print GetEntryDesc(idx%)
- If picDisplay.CurrentY > picDisplay.ScaleHeight Then Exit Do
- End If
- End If
- idx% = idx% + 1
- Loop
- End If
- Else
- ' It's the ScheduleLL array (linked list)
- If optDisplay(0).Value <> 0 Then
- VScroll1.Max = UBound(ScheduleLL) ' Approximation
- ' Display by start time
- idx% = FirstTask
- count% = 0
- Do While idx% > 0
- count% = count% + 1
- If count% > targetidx% Then
- picDisplay.Print GetEntryDescLL(idx%)
- If picDisplay.CurrentY > picDisplay.ScaleHeight Then Exit Do
- End If
- idx% = ScheduleLL(idx%).StartLink.Forward
- Loop
- Else
- ' Display by name
- personlmt% = Val(txtPerson.Text)
- VScroll1.Max = GetCountLL(personlmt%)
- idx% = FirstPerson(personlmt%)
- count% = 0 ' Tracks how many to skip
- Do While idx% > 0
- count% = count% + 1 ' How many found?
- If count% >= targetidx% Then
- picDisplay.Print GetEntryDescLL(idx%)
- If picDisplay.CurrentY > picDisplay.ScaleHeight Then Exit Do
- End If
- idx% = ScheduleLL(idx%).PersonLink.Forward
- Loop
- End If
-
-
- ' It's the linked list array
- End If
-
- End Sub
- Private Sub txtPerson_Change()
- picDisplay.Refresh
- End Sub
- Private Sub VScroll1_Change()
- picDisplay.Refresh
- End Sub
- Private Sub VScroll1_Scroll()
- picDisplay.Refresh
- End Sub
-