Importing and viewing Visual Basic files in a Scrivener project

Is there a way to view the contents of a Visual Basic file that has been formatted, after it has been imported into a Scrivener project? If the file is imported with a .txt extension then the file contents can be seen and edited but I was hoping to retain the .bas extension.

What is your ultimate goal?

Scrivener’s native format is RTF, and that’s the only format it knows how to edit. So no, there’s no way to retain the extension for an editable file.

OTOH, if you export the file back out again, you can give the output document any extension you want.

1 Like

If you only want to view the content of a .bas file and not edit it, shouldn’t a QuickLook extension like PreviewCode do the trick?

The goal was (as always!) a little complicated. I have a Scrivener project that contains.a collection of creative writing, prose, poems, scripts - and the scripts are laid out using the conventions for screenplays, stage plays etc - using Scrivener’s script writing elements. The whole project is really a ‘collected works’ omnibus. To print it as a physical book, I need to send PDF of the project to a print on demand service like Lulu. However, I want to print in both A4 and A5 physical sizes. The `Scrivener scriptwriting elements get compiled into Word styles that don’t fit well on an A5 page (as they have fixed indents, set from the left hand margin that are setup for A4 pages). The fix, was to write a bit of visual basic, and then compile in Scrivener into Word .docx and then run the VB on that Word doc, to modify the Word styles that Scrivener had generated for the scriptwriting elements so that the modified Word styles then had the appropriate indents and margins. Then Word can generate an A5 sized PDF that looks pretty good. All of which works okay.

So I then thought, how do I document/preserve this VB code i have just written. It seems appropriate to put it into the same Scrivener project. And that’s fine, it can be imported and exported as a .bas file in the ‘Research’ area of the project. I can then put a note in the ‘Research’ area of the project which reminds me how to use this VB code in the compile-to-pdf process.

But I mildly disappointed I could not see the contents of the VB file in Scrivener.

I can of course, rename the VB file and give it a .txt extension, then import it into Scrivern and the contents is visible (and indeed editable, though that’s not really needed or even a good idea).
But then when I export it I have to remember to make it a .bas file again. It’s just an extra step.
Given that when the .bas file is stored in Scrivener it is a simple readable format (ie there is no complicated metadata or non printing stuff in a VB .bas file, I wasn’t sure why Scrivener did not want to show the contents of what in way could be seen to be a file in plain text RTF like format, just with a .bas extension.

Here’s Scrivener looking at the SetScript

Fonts file with either a .bas or a .txt extension - but the same contents.

On macOS, you can go into the Sharing: Import settings tab, and in the Plain-Text section you will find a control to add custom extensions that Scrivener should recognise as plain-text, rather than importing as “unrecognised” or Quick Look preview-only. The downside is that it will import as regular text instead of the original file, so export will be oblivious as to its original file extension.

Otherwise, for something that is read-only, the best route is to find a Quick Look plug-in that will display it, that way you at least get something better than an empty icon.

1 Like