VB Macro for Excel for handling output of file::save procedure

Share Tips, Code Samples, etc. with the Visual Prolog community.
Post Reply
User avatar
Ferenc Nagy
VIP Member
Posts: 343
Joined: 24 Apr 2007 12:26

VB Macro for Excel for handling output of file::save procedure

Post by Ferenc Nagy » 24 Apr 2016 8:07

Hi,
I adore the save, consult and reconsult statements.
They can write out and read in complicated fact sections very simply.
However, the saved files are unfriendly for non-expert human inspection and tabulation.
Everybody has, however, Excel.

I publish here a macro for Preparation of Prolog terms for Excel".

The format of the files saved by Turbo->PDC->Visual Prolog resemble to the format of the CSV that is comma separated value files. Their fields are separated by commas, the strings are enclosed between double quotes. They are ready to import and split into columns.
Some unnecessary words and characters should be deleted like the "clauses" in the first line and the term and list opening and parentheses and brackets.

Code: Select all

Attribute VB_Name = "Module1" Sub Term() Attribute Term.VB_Description = "Preparation of Prolog terms for Excel" Attribute Term.VB_ProcData.VB_Invoke_Func = "T\n14" ' Author: ' Ferenc Nagy, Budapest, Hungary 2016. ' ' Term Macro ' ' This macro prepares the output files of the Visual Prolog file::save procedures for Excel. ' 1) splits the lines of comma and parenthesis separated saved prolog terms into columns ; ' 2) and deletes the unncessary '    final periods, '    closing parentheses, '    opening and closing brackets. ' ' Warning: ' Decimal points of real numbers, periods, ' closing parentheses and brackets within string will be deleted in Step#2, too. ' Hot key: Ctrl+Shift+T '     Columns("A:A").Select     Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _         TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _         Semicolon:=False, Comma:=True, Space:=False, Other:=True, OtherChar:= _         "(", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _         TrailingMinusNumbers:=True     Cells.Select     Selection.Replace What:=".", Replacement:="", LookAt:=xlPart, _         SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _         ReplaceFormat:=False     Selection.Replace What:=")", Replacement:="", LookAt:=xlPart, _         SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _         ReplaceFormat:=False     Selection.Replace What:="[", Replacement:="", LookAt:=xlPart, _         SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _         ReplaceFormat:=False     Selection.Replace What:="]", Replacement:="", LookAt:=xlPart, _         SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _         ReplaceFormat:=False     Rows("1:1").Select     Selection.Delete Shift:=xlUp End Sub
TIA, Regards,
Frank Nagy

Post Reply