FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log inLog in 


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

Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog Tips & Samples
View previous topic :: View next topic  
Author Message
Ferenc Nagy



Hungary
Joined: 24 Apr 2007
Posts: 378

PostPosted: 24 Apr 2016 8:07    Post subject: VB Macro for Excel for handling output of file::save procedure Reply with quote

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.


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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog Tips & Samples All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum