|
Visual Basic (VB and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Please read the DISCLAIMER.
Here is an INDEX to all the procedures.
You will probably need one copy of my GLOBAL DECLARATIONS.
Public Function GetTodo(lngAr() As String, ByVal lngStoryStart As Long, lngStoryEnd As Long, lngToDo() As String)
' Procedure: GetTodo
' Description: Build an array of gaps in an array of ranges.
' By: Chris Greaves Inc.
' Inputs: Array of ranges, start and end of story, array to be loaed with missing ranges.
' Returns: LONG array of ranges To Be Processed ("To Do")
' Assumes: The incoming array is sorted ASCENDING sequence on the first column.
' Side Effects: None.
' Tested: By the calls shown below.
' Prepare the result array, two columns wide, one row.
ReDim lngToDo(1, 0)
' Prepare to loop through the array of ranges.
Dim lngI As Long
For lngI = 0 To UBound(lngAr, 2)
If lngAr(0, lngI) <= lngStoryStart Then ' this range starts before our story limit
' so maybe adjust the story start to the upper limit of this range.
lngStoryStart = lngMax(lngStoryStart, lngAr(1, lngI) + 1)
Else
If lngAr(0, lngI) > lngStoryStart Then ' this range starts AFTER our story start
' so maybe we have found a gap.
lngToDo(0, UBound(lngToDo, 2)) = lngStoryStart ' gap starts at our story start
lngToDo(1, UBound(lngToDo, 2)) = lngAr(0, lngI) - 1 ' gap ends before the next range start.
lngStoryStart = lngAr(1, lngI) + 1 ' Adjust the story start to just beyond the upper limit of this range.
ReDim Preserve lngToDo(1, UBound(lngToDo, 2) + 1) ' make space for the next result array entry.
Else
End If
End If
Next lngI
' We have looped through all the input ranges. What is left?
If lngStoryStart < lngStoryEnd Then ' We have one last chunk of text unaccounted for.
lngToDo(0, UBound(lngToDo, 2)) = lngStoryStart
lngToDo(1, UBound(lngToDo, 2)) = lngStoryEnd
Else ' We need to trim the next available entry from the result array.
ReDim Preserve lngToDo(1, UBound(lngToDo, 2) - 1)
End If
'Sub TESTGetTodo()
'Dim lngAr(2, 4) As String
'Dim lngToDo() As String
'Dim lngStoryStart As Long
'Dim lngStoryEnd As Long
'lngStoryEnd = 30
'lngAr(0, 0) = 0
'lngAr(1, 0) = 6
'lngAr(0, 1) = 10
'lngAr(1, 1) = 28
'lngAr(0, 2) = 10
'lngAr(1, 2) = 18
'lngAr(0, 3) = 25
'lngAr(1, 3) = 32
'lngAr(0, 4) = 30
'lngAr(1, 4) = 48
'Call GetTodo(lngAr, lngStoryStart, lngStoryEnd, lngToDo)
'End Sub
End Function
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Thursday, November 15, 2001 |