Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

New empty lines added to .frm file after import then export #22

Open
mattpalermo opened this issue Jan 21, 2017 · 12 comments
Open

New empty lines added to .frm file after import then export #22

mattpalermo opened this issue Jan 21, 2017 · 12 comments

Comments

@mattpalermo
Copy link
Collaborator

I am finding that a new line is added after the Attribute header each time I do a Import then Export cycle. I view the .frm file in a text editor and watch the file grow as I import then export over and over. Does anyone else suffer from this?

@spences10
Copy link
Owner

spences10 commented Jan 30, 2017

Ok, something I have never noticed before, may have had it happen but never noticed really. This can be problematic for this situation though, maybe we could use some of the CodeModule functions?

Like the example here, a straight copy pasta from the modImportExport.bas

Set modCodeCopy = comNewImport.CodeModule
Set modCodePaste = comExistingComp.CodeModule
modCodePaste.DeleteLines 1, modCodePaste.CountOfLines
If modCodeCopy.CountOfLines > 0 Then
  modCodePaste.AddFromString modCodeCopy.Lines(1, modCodeCopy.CountOfLines)
End If
Project.VBComponents.Remove comNewImport

No, that's not going to work very well as you'd need to go through all the files

🤔

I'll come back on this

@mattpalermo
Copy link
Collaborator Author

Argh, I must has glossed over that part at some point and left it out. Worth a try.

@mattpalermo
Copy link
Collaborator Author

Oh, actually I withdraw that comment. It is still there

Set modCodeCopy = comNewImport.CodeModule

@mattpalermo
Copy link
Collaborator Author

But yes, maybe there is a hack using CodeModule functions that we could conjure up to solve this problem.

@spences10
Copy link
Owner

Yeah, it's going to be some ugly loop through all modules, check for whitespace which will seem overkill but either that than have 15,000 empty lines at the start of your code I guess

I think the thing with this is that in the most part it's a straight import export with forms, why change it gah! Annoying!!

We have to do a whole new thing, to get around an annoying thing, thanks Microsoft

@mattpalermo
Copy link
Collaborator Author

Yes. In the mean time, it can be fixed using a text editor. I usually try to check the git diff before committing and touch up the whitespace with a text editor if needed. I do this as a routine to remove trailing whitespace as well.

@mattpalermo
Copy link
Collaborator Author

mattpalermo commented Feb 21, 2017

Thoughts about implementation:
The whitespace is added between the attributes and the rest of the code. The attributes "header" seems quite different from the rest of VBA syntax so it seems possible that we could identify the end of the attributes section automatically and simply remove whitelines before the first non-whiteline.

This could be part of a grander "formatting" code which also removes trailing whitespace (this would be quite useful).

Edit: May be useful to look at VBADeveloper's formatting code for inspiration.

@rubberduck203
Copy link

We hit this bug in the Rubberduck project a while back. You may want to browse our source to see how we handled it. If you have trouble finding it, let me know and I'll lend a hand.

@spences10
Copy link
Owner

Hi @rubberduck203 thanks for taking a look, @mattpalermo I'll let you take a look at this one if you know what needs doing??

@mattpalermo
Copy link
Collaborator Author

Thankyou @rubberduck203 for this. I'll definitely have a look.

@retailcoder
Copy link

Not sure if it's still relevant, but this is the relevant code in Rubberduck:

https://github.com/rubberduck-vba/Rubberduck/blob/2b341dd15605cbca037f3d5f7c50ef83fedc7c3b/Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBComponents.cs#L133-L150

Note that this creates another problem - member attributes get wiped out, since the module isn't really imported, but re-written. You'll need another mechanism in place to avoid losing the member attributes (we've fixed that as well in Rubberduck, but that's pretty involved).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants