Results 1 to 7 of 7

Thread: (VB6) source code of Add-In to delete *.vbw files on project load

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    (VB6) source code of Add-In to delete *.vbw files on project load

    This Add-In deletes *vbw files when the IDE opens a project and also when closing.

    Download from GitHub.

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: (VB6) source code of Add-In to delete *.vbw files on project load

    Quote Originally Posted by Eduardo- View Post
    New version: it deletes the *.vbw files also when closing a project.
    Now that is nifty!

    cheers,
    </wqw>

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: (VB6) source code of Add-In to delete *.vbw files on project load

    Eduardo, I thought of a way to keep the vbw file and prevent code execution. If you want to modify your add-in, great.

    1. Determine if the vbw file exists using simple on-error statements
    2. Enumerate the components looking for non-GUI types; the others will be GUI
    3. If any found, cache names of GUIs to a collection
    4. After enumeration, if collection count <> 0 then
    -- open vbw file, get contents
    -- for each collection item, see if it is in the vbw file
    -- if it's there, test the final character and if not C, replace with a C (or simply delete the line)
    -- if any changes are made, rewrite the vbw file
    Code:
         Dim v As VBComponent, cNames As Collection
    ...
    If Exists(vbwFile) = True Then  ' psuedocode
        Set cNames = New Collection
        For Each v In VBProject.VBComponents
            Select Case v.Type
                Case vbext_ct_StdModule, vbext_ct_ClassModule, vbext_ct_RelatedDocument, vbext_ct_ResFile
                Case Else: cNames.Add v.Name
            End Select
        Next
        If cNames.Count <> 0 Then
             -- open vbw, get contents, locate collection names, tweak final character, rewrite if needed
        End If
    End If
    I tried it and it works.

    Edited: I've updated one of my personal (unpublished) add-ins to include your idea but keeping the vbw file & modifying it as needed. If you don't want to make the changes, anyone visiting this page should be able to follow the steps I outlined above to do it themselves. If you do make the changes, you might even want to offer up choices: delete vbw or keep/tweak vbw

    Thanks for the add-in.
    Last edited by LaVolpe; Sep 7th, 2020 at 06:54 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: (VB6) source code of Add-In to delete *.vbw files on project load

    Quote Originally Posted by LaVolpe View Post
    Eduardo, I thought of a way to keep the vbw file and prevent code execution. If you want to modify your add-in, great.

    1. Determine if the vbw file exists using simple on-error statements
    2. Enumerate the components looking for non-GUI types; the others will be GUI
    3. If any found, cache names of GUIs to a collection
    4. After enumeration, if collection count <> 0 then
    -- open vbw file, get contents
    -- for each collection item, see if it is in the vbw file
    -- if it's there, test the final character and if not C, replace with a C (or simply delete the line)
    -- if any changes are made, rewrite the vbw file
    Code:
         Dim v As VBComponent, cNames As Collection
    ...
    If Exists(vbwFile) = True Then  ' psuedocode
        Set cNames = New Collection
        For Each v In VBProject.VBComponents
            Select Case v.Type
                Case vbext_ct_StdModule, vbext_ct_ClassModule, vbext_ct_RelatedDocument, vbext_ct_ResFile
                Case Else: cNames.Add v.Name
            End Select
        Next
        If cNames.Count <> 0 Then
             -- open vbw, get contents, locate collection names, tweak final character, rewrite if needed
        End If
    End If
    I tried it and it works.

    Edited: I've updated one of my personal (unpublished) add-ins to include your idea but keeping the vbw file & modifying it as needed. If you don't want to make the changes, anyone visiting this page should be able to follow the steps I outlined above to do it themselves. If you do make the changes, you might even want to offer up choices: delete vbw or keep/tweak vbw

    Thanks for the add-in.
    Yes, I was reading your other thread and was about to suggest what you say here: to check the vbw file and look for the trailing C, and edit/update the vbw file if needed.

    Still, I see then that the Add-In then will need an options window, to be able to select whether to delete the vbw file when closing the project or not.

    The other thing I was thinking is what you also mention here: that this add-in should be merged with the other IDE fix about the color palette.

    About the third issue that you mention there:

    Quote Originally Posted by LaVolpe View Post
    ...possibly restore drag/drop from non-elevated Explorer to elevated IDE (manifested or not).
    I'm not aware of that problem, what is that?

    So, yes, I agree that all these IDE fixes should go together.
    If you want to make it LaVolpe please go ahead.
    If you prefer me to do it, I can do it, I'll have to learn your add-in code.

    Another "IDE fix" desirable (at least for me), could be the ability to remove items from the MRU project list. But that's not important, at least in the first version.

    In another add-in where a I have an options form, in the Connect object I have code like this:

    Code:
    Private mFormDisplayed As Boolean
    Private mmfrmOptions As frmOptions
    Private mVBInstance As VBIDE.VBE
    Private mcbMenuCommandBar As Office.CommandBarControl
    
    Public Sub HideOptionsWindow()
        On Error Resume Next
        
        mFormDisplayed = False
        mfrmOptions.Hide
    End Sub
    
    Sub ShowOptionsWindow()
        On Error Resume Next
        
        If mfrmOptions Is Nothing Then
            Set mfrmOptions = New frmOptions
        End If
        
        Set mfrmOptions.VBInstance = mVBInstance
        Set mfrmOptions.Connect = Me
        mFormDisplayed = True
        mfrmOptions.Show
    End Sub
    
    Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
        On Error GoTo error_handler
        
        Set mVBInstance = Application
        
        If ConnectMode = ext_cm_External Then
            ShowOptionsWindow
        Else
            Set mcbMenuCommandBar = AddToAddInCommandBar("Add-In Name here")
            Set mMenuHandler = mVBInstance.Events.CommandBarEvents(mcbMenuCommandBar)
        End If
      
        If ConnectMode = ext_cm_AfterStartup Then
            If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
                ShowOptionsWindow
            End If
        End If
        Exit Sub
        
    error_handler:
        MsgBox Err.Description
    End Sub
    
    Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
        On Error Resume Next
        
        mcbMenuCommandBar.Delete
        
        If mFormDisplayed Then
            SaveSetting App.Title, "Settings", "DisplayOnConnect", "1"
            mFormDisplayed = False
        Else
            SaveSetting App.Title, "Settings", "DisplayOnConnect", "0"
        End If
        
        Unload mfrmOptions
        Set mfrmOptions = Nothing
    End Sub
    
    Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
        If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
            ShowOptionsWindow
        End If
    End Sub
    
    Private Sub mMenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
        ShowOptionsWindow
    End Sub
    
    Function AddToAddInCommandBar(sCaption As String) As Office.CommandBarControl
        Dim cbMenuCommandBar As Office.CommandBarControl  'objeto de barra de comandos
        Dim cbMenu As Object
      
        On Error GoTo AddToAddInCommandBarErr
        
        Set cbMenu = mVBInstance.CommandBars("Add-Ins")
        If cbMenu Is Nothing Then
            Exit Function
        End If
        
        Set cbMenuCommandBar = cbMenu.Controls.Add(1)
        cbMenuCommandBar.Caption = sCaption
        Set AddToAddInCommandBar = cbMenuCommandBar
        Exit Function
        
    AddToAddInCommandBarErr:
    End Function

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: (VB6) source code of Add-In to delete *.vbw files on project load

    ...possibly restore drag/drop from non-elevated Explorer to elevated IDE (manifested or not).
    Since Win8.1 (I think), you cannot drag/drop from Explorer to the IDE project tree when the IDE is elevated. Try it. Then run IDE un-elevated and try it.

    The other thing I was thinking is what you also mention here: that this add-in should be merged with the other IDE fix about the color palette.
    I wasn't intending to do that -- it's your code; you came up with the solution. For my personal copy of my add-in, I added the fix you came up with -- just modified your fix to keep vbw files, since most of the time, they won't need to be edited/deleted.

    As for options to delete or keep the vbw? Yep, VB doesn't offer a lot of alternatives & even their template/wizard suggests saving setting to the registry.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: (VB6) source code of Add-In to delete *.vbw files on project load

    Still, I think that it is a good idea to have all the IDE fixes in one single Add-In.

  7. #7
    Fanatic Member
    Join Date
    Jan 2015
    Posts
    596

    Re: (VB6) source code of Add-In to delete *.vbw files on project load

    Tested and works perfectly.
    I had in my mind to do the same, juste delete vbw files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width