Description This command adds a new pickup entry to the end of the document pickup list.
Syntax pickIndex = AddPickup( tPick )
Parameters pickIndex (Long) Index into the document pickup list at which the new pickup was added.
tPick As T_PICKUP T_PICKUP data structure defining the pickup entry being added.
Example The following example consists of two separate scripts which together demonstrate how to write out pickups to a text file and read the same text file back into FRED to re-create the pickups. By using these scripts, pickups can be effectively saved out of a document and read back in at a later date if needed.
The first script, shown below, loops over existing document pickups and writes them to a designated text file using the ";" character as a delimiter. The subroutine "printScript" handles the proper output of scripted function type.
Sub Main
ClearOutputWindow
Dim outFile As String outFile = GetDocDir() & "\myPickups.txt"
'Re-direct output to file and output window SetTextFile outFile, False
Dim pCount As Long pCount = GetPickupCount()
Dim tPick As T_PICKUP Dim curPick As Long For curPick = 0 To GetPickupCount()-1 GetPickup( curPick, tPick ) Print "Pickup Description; " & tPick.Description Print "Active;" & tPick.active Print "Destination;" & tPick.dstentity Print "Destination Index;" & tPick.dstindex Print "Destination Sub-index;" & tPick.dstsubindex Print "Destination Type;" & tPick.dsttype Print "Source;" & tPick.srcentity Print "Source Index;" & tPick.srcindex Print "Source Sub-index;" & tPick.srcsubindex Print "Source Type;" & tPick.srctype Print "Function;" & tPick.Function Print "Operation;" & tPick.op Print "Parameter A;" & tPick.parma Print "Parameter B;" & tPick.parmb If tPick.Script <> "" Then printScript( tPick.Script ) Else Print "Script;" & "None" End If Print "" Next curPick
SetTextFileOff
End Sub
Sub printScript( ByVal pickScript As String )
Print "Script; "
Dim vals() As Double Dim strs() As String Dim numTokens As Long, curLine As Long numTokens = ParseString( pickScript, Chr(10), vals(), strs() ) For curLine = 0 To UBound( strs,1 ) Print strs( curLine ) Next curLine
End Sub
The second script, shown below, deletes all pickups, opens a text file produced by the first script above, reads the parameters into a T_PICKUP structure and then adds the pickups to the document.
Sub Main
ClearOutputWindow
'Delete all existing pickups Dim curPick As Long For curPick = GetPickupCount()-1 To 0 Step -1 DeletePickup( curPick ) Next curPick
'Open input file containing pickup definitions Dim inFile As String inFile = GetDocDir() & "\myPickups.txt" Open inFile For Input As #1
'Read text input file and re-create pickups Dim tPick As T_PICKUP Dim curLine As String, strs() As String Dim vals() As Double Dim numTokens As Long Dim lastTag As String Dim firstPickup As Boolean firstPickup = True While Not EOF(1) 'line feed and parse using ; delimiter Line Input #1, curLine numTokens = ParseString( curLine, ";", vals(), strs() ) 'Print strs(0) 'Print strs(1)
'Check for description member If strs(0) = "Pickup Description" Then 'Print out script member from last pass If lastTag = "Script" Then Print Chr(9) & "Script:" Print tPick.Script End If
'If this isn't the first pickup found, add pickup to document If Not firstPickup Then Print "Pickup added at: " & Chr(9) & AddPickup( tPick ) End If
Print "Pickup found: " & Chr(9) & strs(1) InitPickup( tPick ) tPick.Description = strs(1) lastTag = strs(0) firstPickup = False End If
'Check for script lines (location here in the script matters) If lastTag = "Script" Then tPick.Script = tPick.Script & Chr(13) & Chr(10) & curLine End If
'Check for Active status If strs(0) = "Active" Then If strs(1) = "True" Then tPick.active = True End If If strs(1) = "False" Then tPick.active = False End If Print Chr(9) & "Active:" & Chr(9) & tPick.active lastTag = strs(0) End If
'Check for destination variable If strs(0) = "Destination" Then tPick.dstentity = vals(1) Print Chr(9) & "Destination:" & Chr(9) & tPick.dstentity lastTag = strs(0) End If
'Check for destination index If strs(0) = "Destination Index" Then tPick.dstindex = vals(1) Print Chr(9) & "Destination Index:" & Chr(9) & tPick.dstindex lastTag = strs(0) End If
'Check for destination sub-index If strs(0) = "Destination Sub-index" Then tPick.dstsubindex = vals(1) Print Chr(9) & "Destination Sub-index:" & Chr(9) & tPick.dstsubindex lastTag = strs(0) End If
'Check for destination variable type If strs(0) = "Destination Type" Then tPick.dsttype = strs(1) Print Chr(9) & "Destination Type:" & Chr(9) & tPick.dsttype lastTag = strs(0) End If
'Check for source variable If strs(0) = "Source" Then tPick.srcentity = vals(1) Print Chr(9) & "Source:" & Chr(9) & tPick.srcentity lastTag = strs(0) End If
'Check for source variable index If strs(0) = "Source Index" Then tPick.srcindex = vals(1) Print Chr(9) & "Source Index:" & Chr(9) & tPick.srcindex lastTag = strs(0) End If
'Check for source variable sub-index If strs(0) = "Source Sub-index" Then tPick.srcsubindex = vals(1) Print Chr(9) & "Source Sub-index:" & Chr(9) & tPick.srcsubindex lastTag = strs(0) End If
'Check for source variable type If strs(0) = "Source Type" Then tPick.srctype = strs(1) Print Chr(9) & "Source Type:" & Chr(9) & tPick.srctype lastTag = strs(0) End If
'Check for pickup function If strs(0) = "Function" Then tPick.Function = strs(1) Print Chr(9) & "Function:" & Chr(9) & tPick.Function lastTag = strs(0) End If
'Check for pickup operation If strs(0) = "Operation" Then tPick.op = strs(1) Print Chr(9) & "Operation:" & Chr(9) & tPick.op lastTag = strs(0) End If
'Check for A parameter value If strs(0) = "Parameter A" Then tPick.parma = vals(1) Print Chr(9) & "Parameter A:" & Chr(9) & tPick.parma lastTag = strs(0) End If
'Check for B parameter value If strs(0) = "Parameter B" Then tPick.parmb = vals(1) Print Chr(9) & "Parameter B:" & Chr(9) & tPick.parmb lastTag = strs(0) End If
'Check for script If strs(0) = "Script" Then tPick.Script = "" lastTag = strs(0) End If Wend
'Write out script for last pickup found Print Chr(9) & "Script:" Print tPick.Script
'Add last pickup to the document Print "Pickup added at: " & Chr(9) & AddPickup( tPick )
Close #1
End Sub
See Also
|